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

Bos, Roger roger.bos at rothschild.com
Tue Nov 4 18:50:56 CET 2014


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.")
    }

Thanks,

Roger



***************************************************************
This message and any attachments are for the named person's use only.
This message may contain confidential, proprietary or legally privileged
information. No right to confidential or privileged treatment
of this message is waived or lost by an error in transmission.
If you have received this message in error, please immediately
notify the sender by e-mail, delete the message, any attachments and all
copies from your system and destroy any hard copies. You must
not, directly or indirectly, use, disclose, distribute,
print or copy any part of this message or any attachments if you are not
the intended recipient.




More information about the R-SIG-Finance mailing list