[R-SIG-Finance] Return.portfolio() behaves differently in PerformanceAnalytics 1.0.5.2 vs 1.0.4.4?

Michael Weylandt michael.weylandt at gmail.com
Fri Feb 15 08:46:50 CET 2013


Moved to r-sig-fin. 

On Feb 15, 2013, at 6:43 AM, Aleksi Mattila <aleksi at ideaario.net> wrote:

> Dear R experts,
> 
> After updating PerformanceAnalytics from 1.0.4.4. to 1.0.5.2 I have encountered a following issue (reproducible example below). I am not quite sure whether this is due to my sloppy coding (any hints on how to get around this would be greatly appreciated), or an actual bug. I think that the code causing the error is in function Return.portfolio(), and occurs when the parameter "geometric" is set to TRUE. I inspected the code from both versions of PerformanceAnalytics, and there were some large changes in the above mentioned function. Unfortunately my coding skills are not good enough to be able to produce a proposal for a workaround.
> 
> The following code works in PA 1.0.4.4
> 
> # create sample data and dates
> library(PerformanceAnalytics)
> cols <- 4
> rows <- 50
> sample.dates <- Sys.Date()-1:rows
> sample.data <- xts(matrix(rep(rnorm(cols*rows)), ncol=cols, nrow=rows), order.by=sample.dates)
> colnames(sample.data) <- c("one", "two", "three", "four")
> sample.rebal.weights <- xts(matrix(rep(1/cols, cols), ncol=cols, nrow=rows), order.by=sample.dates)
> 
> # works in 1.0.4.4
> Return.rebalancing(sample.data, sample.rebal.weights)
> 
> #, but in PerformanceAnalytics 1.0.5.2 the same code results in an error.
> Return.rebalancing(sample.data, sample.rebal.weights)
>> Error in `[.xts`(result, 2:length(result)) : subscript out of bounds
> 
> I also tried to use endpoints(), where periodicity "days" is fine, if parameter k is greater or equal to 3. Coarser periodicities work fine with k=1 (weeks,...)
> 
> # this works
> sample.endpoints <- endpoints(sample.dates, on="days", k=3)
> Return.rebalancing(sample.data, sample.rebal.weights[sample.endpoints])
> 
> # this does not
> sample.endpoints <- endpoints(sample.dates, on="days", k=1)
> Return.rebalancing(sample.data, sample.rebal.weights[sample.endpoints])
>> Error in `[.xts`(result, 2:length(result)) : subscript out of bounds
> 
> I am stuck with this one, and can't figure out how to go around this problem.
> 
> Any pointers/hints on this would be greatly appreciated. SessionInfo() from both machines is attached below.
> 
> With best regards,
> Aleksi Mattila
> 
> 
>> sessionInfo() # sample code run on this machine works fine
> R version 2.15.2 (2012-10-26)
> Platform: x86_64-pc-linux-gnu (64-bit)
> 
> locale:
> [1] LC_CTYPE=fi_FI.UTF-8       LC_NUMERIC=C              
> [3] LC_TIME=fi_FI.UTF-8        LC_COLLATE=fi_FI.UTF-8    
> [5] LC_MONETARY=fi_FI.UTF-8    LC_MESSAGES=fi_FI.UTF-8   
> [7] LC_PAPER=C                 LC_NAME=C                 
> [9] LC_ADDRESS=C               LC_TELEPHONE=C            
> [11] LC_MEASUREMENT=fi_FI.UTF-8 LC_IDENTIFICATION=C       
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base     
> 
> other attached packages:
> [1] PerformanceAnalytics_1.0.4.4 xts_0.9-1                   
> [3] zoo_1.7-9                   
> 
> loaded via a namespace (and not attached):
> [1] grid_2.15.2     lattice_0.20-13 tools_2.15.2   
> 
> 
>> sessionInfo() # sample code run on this machine gives an error
> R version 2.15.1 (2012-06-22)
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
> 
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base     
> 
> other attached packages:
> [1] PerformanceAnalytics_1.0.5.2 xts_0.9-3.2                  zoo_1.7-9                   
> 
> loaded via a namespace (and not attached):
> [1] grid_2.15.1     lattice_0.20-13 tools_2.15.1   
> 
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.



More information about the R-SIG-Finance mailing list