0
$\begingroup$

I am running the chart.SnailTrail function from the PerformanceAnalytics package in r. I get the following subscript out of bounds error.

Error in chart.SnailTrail(z, Rf = 0.009261, main = "", : Error in rval[i, j, drop = drop., ...] : subscript out of bounds"

I am not understanding the relevance of the rval[i, j, drop = drop., ...] message nor the reason the subscript is out of bounds.

Here's the reprex:

library(data.table)

if (requireNamespace("xts", quietly = TRUE)) {
    z <- data.table(
                 date = as.Date(c("2012-06-30", "2012-09-30", "2012-12-31",
                           "2013-03-31", "2013-06-30", "2013-09-30",
                           "2013-12-31", "2014-03-31", "2014-06-30", "2014-09-30",
                           "2014-12-31", "2015-03-31", "2015-06-30", "2015-09-30",
                           "2015-12-31", "2016-03-31", "2016-06-30", "2016-09-30",
                           "2016-12-31", "2017-03-31", "2017-06-30", "2017-09-30",
                           "2017-12-31", "2018-03-31", "2018-06-30", "2018-09-30",
                           "2018-12-31", "2019-03-31", "2019-06-30")),
       Advisors = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, -0.018, 0.0316,
                           0.023, -0.0041, -0.069, 0.0588, 0, -0.0131, 0.0443,
                           0.0802, 0.0568, 0.037, 0.0377, 0.058, 0.0054, 0.0252,
                           0.0715, -0.1642, 0.1317, 0.0317),
   Composite.Portfolio = c(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, -0.018,
                           0.0316, 0.023, -0.0041, -0.00451066775572065,
                           0.0138801428787179, 0.0167544082714075, 0.0086808059159329,
                           0.0128885691937194, 0.00447602245053359,
                           0.0245970869103885, 0.0206885949732613, 0.0169456093554593,
                           0.0142686600431308, -0.00498093053050016,
                           0.00946423708285855, 0.022061151018737, -0.0307014361379985,
                           0.0584823655637847, 0.0222879820629305)
)

    # print data.table
    print(z)
    # print head of xts
    print(head(as.xts.data.table(z))) # xts might not be attached on search path
    # convert to xts
    z<-as.xts.data.table(z)
}

chart.SnailTrail(z,Rf=0.009261,main="",add.names ="none",width=Period.Qtr,stepsize=1,legend.loc="topleft", cex.axis = 1.5, cex.lab = 1.5)

Session Info

Created on 2019-07-18 by the reprex package (v0.3.0)

devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.6.1 (2019-07-05)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  ctype    English_United States.1252  
#>  tz       America/New_York            
#>  date     2019-07-18                  
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version    date       lib source                         
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.0)                 
#>  backports     1.1.4      2019-04-10 [1] CRAN (R 3.6.0)                 
#>  callr         3.3.0      2019-07-04 [1] CRAN (R 3.6.1)                 
#>  cli           1.1.0      2019-03-19 [1] CRAN (R 3.6.0)                 
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.0)                 
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.6.0)                 
#>  devtools      2.1.0      2019-07-06 [1] CRAN (R 3.6.1)                 
#>  digest        0.6.20     2019-07-04 [1] CRAN (R 3.6.1)                 
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 3.6.0)                 
#>  fs            1.3.1      2019-05-06 [1] CRAN (R 3.6.0)                 
#>  glue          1.3.1.9000 2019-07-08 [1] Github (tidyverse/glue@423b7e5)
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.6.0)                 
#>  htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.6.0)                 
#>  knitr         1.23       2019-05-18 [1] CRAN (R 3.6.0)                 
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.0)                 
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.6.0)                 
#>  pkgbuild      1.0.3      2019-03-20 [1] CRAN (R 3.6.0)                 
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.6.0)                 
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.6.0)                 
#>  processx      3.4.0      2019-07-03 [1] CRAN (R 3.6.1)                 
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.6.0)                 
#>  R6            2.4.0      2019-02-14 [1] CRAN (R 3.6.0)                 
#>  Rcpp          1.0.1      2019-03-17 [1] CRAN (R 3.6.0)                 
#>  remotes       2.1.0      2019-06-24 [1] CRAN (R 3.6.0)                 
#>  rlang         0.4.0      2019-06-25 [1] CRAN (R 3.6.0)                 
#>  rmarkdown     1.14       2019-07-12 [1] CRAN (R 3.6.0)                 
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.6.0)                 
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                 
#>  stringi       1.4.3      2019-03-12 [1] CRAN (R 3.6.0)                 
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.6.0)                 
#>  testthat      2.1.1      2019-04-23 [1] CRAN (R 3.6.0)                 
#>  usethis       1.5.1      2019-07-04 [1] CRAN (R 3.6.1)                 
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.6.0)                 
#>  xfun          0.8        2019-06-25 [1] CRAN (R 3.6.0)                 
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.6.0)                 
#> 
#> [1] C:/Users/utexas80/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-3.6.1/library  

Also, if I exclude the last row in the vector by changing the vector reference to:

head(performance[,one.year],-1)

i.e.,

charts.SnailTrail(head(performance[,one.year],-1),width=4,Rf=risk.free.rate,legend.loc="left",main="", 
                              cex.axis = 1.5, cex.lab = 1)

I am able to create the SnailTrail chart.

Any assistance or direction on resolving this error is greatly appreciated

Thank you.

$\endgroup$
  • $\begingroup$ Without having used SnailTrail, I'm guessing this is an indexing issue (eg, 0- v. 1-indexed, sending a vector/matrix when it's expecting a matrix/vector, etc.). Try running the example included in the SnailTrail documentation and compare inputs/outputs to yours. It could be as simple as taking the transpose of a vector to get it in the right form. $\endgroup$ – Chris Jul 18 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.