I can’t seem to use TTR indicator functions direclty with period.apply() from XTS. Please help me figure out what I’m doing wrong.
> 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'
I also tried to as.xts(sample_matrix) first but it doesn’t help.
Based on the comments to your question, I think you want something like this: