XTS 기간을 사용하는 방법. TTR 표시기 기능을 사용하여 () 함수를 사용 하시겠습니까?

StackOverflow https://stackoverflow.com/questions/5489675

  •  14-11-2019
  •  | 
  •  

문제

TTR 표시기 기능을 사용하는 것으로 보이는 것 같습니다. xts에서 afply ()를 사용하십시오.내가 뭘 잘못하고 있는지 알아낼 수 있도록 도와주세요.

> 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)를 먼저 시도했지만 도움이되지 않습니다.

도움이 되었습니까?

해결책

Based on the comments to your question, I think you want something like this:

> 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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top