我似乎无法使用来自XTS的period.apply()的TTR指示符函数direclty。请帮我弄清楚我做错了什么。
> require(TTR)
> require(quantmod)
> require(xts)
> data(sample_matrix)
> period.apply(sample_matrix, endpoints(sample_matrix,"weeks"), RSI)
Error in EMA(c(NA, 0.190714286249097, 0.190459011271606, 0, 0, 0, NA, :
Invalid 'n'
我首先尝试as.xts(sample_matrix)
,但没有帮助。
答案 0 :(得分:1)
根据您对问题的评论,我认为您需要这样的内容:
> RSI(Cl(to.period(sample_matrix, "weeks", 2)),4)
[,1]
2007-01-07 NA
2007-01-21 NA
2007-02-04 NA
2007-02-18 NA
2007-03-04 58.42659
2007-03-18 40.25955
2007-04-01 27.12793
2007-04-15 50.26745
2007-04-29 38.97652
2007-05-13 22.03943
2007-05-27 28.75952
2007-06-10 22.21261
2007-06-24 21.58207
2007-06-30 41.69338