Search code examples
rquantmodperiod

Calculating highest high price during specific period using quantmod in R


I am trying to calculate the highest high price and lowest low price during the last 144 days for one stock.

I have been thinking for a while and finally I came up with the following two means, but these are still not exactly what I want.

This is because the highest(high_price, 144) and lowest(low_price, 144) is a series that would probably change over time.

data <- getSymbols("300343.SZ",auto.assign=FALSE)

#highest price so far
seriesHi(data)

# find the maximum highest price each week
max_price_weekly <- period.apply(data,endpoints(data,on='weeks'), FUN=function(x) { max(Hi(x)) } ) 

candleChart(data,subset='2012::2013')

Someone can give some help?


Solution

  • If you just want the highest or lowest price over the previous 144 days, you can do this

    runMax(Hi(data), 144)
    runMin(Lo(data), 144)