简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM