在R中,以下代码:
apply.yearly(XTS_object, sum)
返回从非包容性的第一年的Jan到下一年的Jan的总和。
我怎样才能在十二月到十二月之间赚钱?
答案 0 :(得分:0)
提取endpoints
并与period.apply
一起使用:
getSymbols("SPY", from = "2013-12-01")
# Use your own data. Assuming Data already starts from December, otherwise extract all months and get Decembers only:
december <- endpoints(SPY, k = 12)
[1] 0 251 503
SPY[251 + 1]
SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
2014-12-01 206.399994 206.539993 205.380005 205.759995 103968400 199.464546
period.apply(Ad(SPY), december + 1, sum)