我想在滞后价格上使用SMI,所以一开始我写了这么简单的代码:
SPY$SMI3MA <- SMI(SPY[,c("SPY.High","SPY.Low","SPY.Close")], maType=list(list(SMA), list(EMA, wilder=TRUE), list(SMA)) )
然后我使用此行将此列转换为已编译的列:
SPY$SMI3MA_T <- Lag(SPY$SMI3MA , k = 1 )
但我只得到MA结果,而不是SMI,如下面的输出中所示。
如何修复此代码,以便在滞后价格上获得SMI结果?
这是代码:
spy<-getSymbols(("SPY") , src = 'yahoo', from = '2007-01-01', auto.assign = T)
spy<-cbind(SPY)
SPY$SMI3MA <- SMI(SPY[,c("SPY.High","SPY.Low","SPY.Close")], maType=list(list(SMA), list(EMA, wilder=TRUE), list(SMA)) )
SPY$SMI3MA_T <- Lag(SPY$SMI3MA , k = 1 )
tail(SPY)
SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted SMI SMI3MA SMI3MA_T
2016-02-11 182.34 184.10 181.09 182.86 210592800 182.86 -16.107562 -14.38172 -15.34089
2016-02-12 184.96 186.65 183.96 186.63 124459300 186.63 -17.289562 -14.03284 -14.38172
2016-02-16 188.77 189.81 187.63 189.78 112124300 189.78 -16.383093 -13.93242 -14.03284
2016-02-17 191.16 193.32 191.01 192.88 131884500 192.88 -13.668168 -13.79414 -13.93242
2016-02-18 193.20 193.27 191.72 192.09 98872300 192.09 -10.379016 -13.59036 -13.79414
2016-02-19 191.17 192.18 190.45 192.00 111764300 192.00 -7.307641 -13.22583 -13.59036