Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 计算返回时发生Xts错误_R_Xts_Quantmod - Fatal编程技术网

R 计算返回时发生Xts错误

R 计算返回时发生Xts错误,r,xts,quantmod,R,Xts,Quantmod,调用periodReturns函数时,我从Xts包中得到以下错误。我已经从github升级了Quantmod和Xts包,但错误仍然存在。 有人能建议如何解决这个问题吗 谢谢 getSymbols('AAPL', src = 'yahoo', from = '2016-01-01', auto.assign = T) > periodReturn(AAPL,by=years,from='2003-01-01') Error in lag.xts(x1, K.) : INTEGER() c

调用periodReturns函数时,我从Xts包中得到以下错误。我已经从github升级了Quantmod和Xts包,但错误仍然存在。 有人能建议如何解决这个问题吗

谢谢

getSymbols('AAPL', src = 'yahoo', from = '2016-01-01', auto.assign = T)

> periodReturn(AAPL,by=years,from='2003-01-01')
Error in lag.xts(x1, K.) : 
INTEGER() can only be applied to a 'integer', not a 'double'

> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252    LC_MONETARY=English_Australia.1252
[4] LC_NUMERIC=C                       LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] PerformanceAnalytics_1.5.1 quantmod_0.4-9             TTR_0.23-1                 xts_0.10-0                
[5] zoo_1.8-0                 

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.10              lattice_0.20-35           codetools_0.2-15          IKTrading_1.0            
 [5] foreach_1.4.4             grid_3.4.0                curl_2.6                  boot_1.3-19              
 [9] blotter_0.11.3            iterators_1.0.8           FinancialInstrument_1.2.0 compiler_3.4.0           
[13] quantstrat_0.10.0        

我无法重现你的错误。虽然您正在从='2016-01-01'下载数据,并从='2003-01-01'计算回报,但您的代码仍然适用于我。也许你可以试着解决这个问题看看

> getSymbols('AAPL', src = 'yahoo', from = '2016-01-01', auto.assign = T)
[1] "AAPL"
> class(AAPL)
[1] "xts" "zoo"
> periodReturn(AAPL, by = years, from = '2003-01-01')
           monthly.returns
2016-01-29   -5.135956e-02
2016-02-29   -6.677563e-03
2016-03-31    1.272106e-01
2016-04-29   -1.399211e-01
2016-05-31    6.528700e-02
2016-06-30   -4.265975e-02
2016-07-29    9.006277e-02
2016-08-31    1.813645e-02
2016-09-30    6.550429e-02
2016-10-31    4.334348e-03
2016-11-30   -2.659859e-02
2016-12-30    4.795515e-02
2017-01-31    4.774649e-02
2017-02-28    1.288835e-01
2017-03-31    4.868968e-02
2017-04-28   -6.967841e-05
2017-05-31    6.341804e-02
2017-06-08    1.459813e-02

这看起来与中讨论的内容非常相似。尝试从GitHub重新安装xts和/或重新启动RStudio。还请注意,
by
不是
periodReturn
的参数,因此被忽略。。。这很好,因为
by=years
可能会返回错误,否则(您可能是指
by=“years”
)。