[R-SIG-Finance] quantstrat::Return.rebalancing

Brian G. Peterson brian at braverock.com
Tue Nov 4 19:47:51 CET 2014


On 11/04/2014 11:50 AM, Bos, Roger wrote:
> I was trying to run some code and got an error on Return.rebalancing, so I tried running the example from the help page and that didn't work either.  I am using windows.
>
> Question 1: what origin must I supply?
>> data(edhec)
>> data(weights)
>> round(Return.rebalancing(edhec,weights),4)
> Error in as.Date.numeric(index(last(R))) : 'origin' must be supplied
>
> Once I figure out how to get that example working, what I really want to run is this:
>
> Question 2: Should this code work on windows (from http://quantstrattrader.wordpress.com/category/asset-allocation/)?
> library(quantstrat)
>
> #long TMF 60% (leveraged 3x t-bond bull), long XIV 40%
> getSymbols("XIV", from="1990-01-01")
> getSymbols("TMF", from="1990-01-01")
> tmfRets <- Return.calculate(Cl(TMF))
> xivRets <- Return.calculate(Ad(XIV))
> both <- merge(xivRets, tmfRets, join='inner')
> colnames(both) <- c("xiv", "tmf")
> portfRets <- Return.rebalancing(both, weights=c(.4, .6),
>                                 rebalance_on="weeks", geometric=FALSE)
>
> The last line gives this error:
>
>> portfRets <- Return.rebalancing(both, weights=c(.4, .6),
> +                                rebalance_on="weeks", geometric=FALSE)
> Error in Return.rebalancing(both, weights = c(0.4, 0.6), rebalance_on = "weeks",  :
>    Use Return.portfolio for single weighting vector.  This function is for building portfolios over rebalancing periods.
>
> Question 3: Does the weights parameter have to be a matrix, or could it be a vector?
>
> A vector would make sense in this case where we want to rebalance to 40%/60% on a weekly basis, but the first thing the code does is make sure weights is not a vector:
>      if (is.vector(weights)) {
>          stop("Use Return.portfolio for single weighting vector.  This function is for building portfolios over rebalancing periods.")
>      }
>

It looks like you're using old versions of the packages.

You did not attach your sessionInfo as described in the posting guide
http://www.r-project.org/posting-guide.html

Both your examples work for me with current code.

In the current CRAN version of PerformanceAnalytics,  Return.rebalancing 
and Return.portfolio are aliases for the same function. (those functions 
are in PerformanceAnalytics, not quantstrat)

Regards,

Brian



-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list