Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
library(quantmod) getSymbols("SPY", from="2013-01-01", to=Sys.Date()) chartSeries(SPY, TA="addSMA(20)")
有没有办法将移动平均线左右移动?
lag是这里的关键
lag
s <- get(getSymbols('SPY')) sma <- SMA(Cl(s),20) chart_Series(s ,subset="2013::") add_TA(sma , on = 1) add_TA(lag(sma,10) , on = 1 , col ='red') add_TA(lag(sma,-10) , on = 1 , col = 'blue')
结果