首页 > 解决方案 > xy.coords(x, y) 中的错误:“x”和“y”长度不同的图表。PerformanceSummary R XTS

问题描述

运行以下代码:

charts.PerformanceSummary( xts(c(.05,.01,-0.1),as.POSIXct(c('2018-02-28','2018-03-29','2018-04-24'))))

我得到错误:

Error in xy.coords(x, y) : 'x' and 'y' lengths differ

以下是 sessionInfo() 的结果:

    R version 3.4.4 (2018-03-15)
    Platform: x86_64-w64-mingw32/x64 (64-bit)
    Running under: Windows >= 8 x64 (build 9200)

    Matrix products: default

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

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

    other attached packages:
     [1] googlesheets_0.2.2         PerformanceAnalytics_1.5.2 doParallel_1.0.11          iterators_1.0.9            foreach_1.4.4             
     [6] TTR_0.23-3                 xts_0.10-2                 zoo_1.8-1                  RMySQL_0.10.14             DBI_0.8                   

    loaded via a namespace (and not attached):
     [1] Rcpp_0.12.16     bindr_0.1.1      magrittr_1.5     lattice_0.20-35  R6_2.2.2         rlang_0.2.0      quadprog_1.5-5   dplyr_0.7.4     
     [9] tools_3.4.4      grid_3.4.4       assertthat_0.2.0 tibble_1.4.2     bindrcpp_0.2     purrr_0.2.4      codetools_0.2-15 curl_3.1        
    [17] glue_1.2.0       pillar_1.2.1     cellranger_1.1.0 pkgconfig_2.0.1 

我使用的是 XTS 0.10-2 版和 PerformanceAnalytics 1.5.2 版。

标签: rxtsperformanceanalytics

解决方案


你的问题在这里得到解决Github PerfomanceAnalytics

第一的:

charts.PerformanceSummary(xts(c(.05,.01,-0.1), as.POSIXct(c('2018-02-28','2018-03-29','2018-04-24'), tz = "UTC")))

第二:

charts.PerformanceSummary(xts(c(.05,.01,-0.1), as.Date(c('2018-02-28','2018-03-29','2018-04-24'))))

推荐阅读