[R-SIG-Finance] Return.rebalancing and rebalancing on consecutive days
Paul Ramer
paul.ramer at gmail.com
Sun Mar 3 02:18:32 CET 2013
When I rebalance my portfolio on consecutive days, I get an error:
Error in `[.xts`(result, 2:length(result)) : subscript out of bounds.
So, I wonder what I am doing wrong.
Below is a code snippet both with and without the error. The first is
rebalanced on consecutive days whereas the second one has at least a
day between all rebalancing. I ran debug on Return.rebalancing. With
consecutive rebalancing days, the only thing I could find was the
'from' and 'to' variables had the same date when the 'R' variable was
subset.
data(edhec)
data(weights)
days <- c("2000-05-01 18:00:00 MDT", "2000-05-02 18:00:00 MDT",
"2000-05-03 18:00:00 MDT", "2000-05-04 18:00:00 MDT",
"2000-05-07 18:00:00 MDT", "2000-05-08 18:00:00 MDT",
"2000-05-09 18:00:00 MDT", "2000-05-10 18:00:00 MDT",
"2000-05-11 18:00:00 MDT", "2000-05-14 18:00:00 MDT",
"2000-05-15 18:00:00 MDT", "2000-05-16 18:00:00 MDT",
"2000-05-17 18:00:00 MDT", "2000-05-18 18:00:00 MDT",
"2000-05-21 18:00:00 MDT", "2000-05-22 18:00:00 MDT",
"2000-05-23 18:00:00 MDT", "2000-05-24 18:00:00 MDT",
"2000-05-25 18:00:00 MDT", "2000-05-29 18:00:00 MDT",
"2000-05-30 18:00:00 MDT", "2000-05-31 18:00:00 MDT")
may.reb <- c("2000-05-09 18:00:00 MDT", "2000-05-10 18:00:00 MDT",
"2000-05-15 18:00:00 MDT")
may.reb.2 <- c("2000-05-09 18:00:00 MDT", "2000-05-11 18:00:00 MDT",
"2000-05-15 18:00:00 MDT")
e1 <- edhec[1:length(days), ]
index(e1) <- as.Date(days)
w1 <- weights[1:3, ]
index(w1) <- as.Date(may.reb)
Return.rebalancing(e1, w1)
w2 <- weights[1:3, ]
index(w2) <- as.Date(may.reb.2)
Return.rebalancing(e1, w2)
Session Info:
R version 2.15.2 (2012-10-26)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] splines stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] reshape_0.8.4 plyr_1.8
[3] latticeExtra_0.6-24 RColorBrewer_1.0-5
[5] Hmisc_3.10-1 survival_2.36-14
[7] PerformanceAnalytics_1.1.0 quantmod_0.4-0
[9] Defaults_1.1-1 TTR_0.21-1
[11] xts_0.9-3.2 zoo_1.7-10
[13] lattice_0.20-13
loaded via a namespace (and not attached):
[1] cluster_1.14.3 compiler_2.15.2 grid_2.15.2 tools_2.15.2
Any guidance is appreciated.
Thank you,
----
Paul Ramer, CAIA, CFA
paul.ramer at gmail.com
(303) 359-4192
More information about the R-SIG-Finance
mailing list