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

Bos, Roger roger.bos at rothschild.com
Tue Nov 4 20:52:38 CET 2014


Yes, it was an old version of PerformanceAnalytics.  It is working fine now.  Thanks for pointing that ouit.


#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)



***************************************************************
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.



-----Original Message-----
From: r-sig-finance-bounces at r-project.org [mailto:r-sig-finance-bounces at r-project.org] On Behalf Of Brian G. Peterson
Sent: Tuesday, November 04, 2014 1:48 PM
To: r-sig-finance at r-project.org
Subject: Re: [R-SIG-Finance] quantstrat::Return.rebalancing

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

_______________________________________________
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