PerformanceAnalytics icon indicating copy to clipboard operation
PerformanceAnalytics copied to clipboard

Return.portfolio problem with partial weight param?

Open casras111 opened this issue 7 years ago • 2 comments

Is Return.portfolio working correctly when the weight parameter has no value for first period? Why are the returns of the first period discarded and the second period returns appear as first? When the default weights are used (equal weights in the absence of a parameter) the results seem correct.

> d <- as.Date("2018-02-17")
> (w <- xts(order.by=(d-11),1))
           [,1]
2018-02-06    1
> (ptest <- xts(order.by=(d-10:11),c(0.1,-0.5)))
           [,1]
2018-02-06 -0.5
2018-02-07  0.1
> Return.portfolio(ptest,weights = w)
           portfolio.returns
2018-02-06               0.1
2018-02-07               0.0
> Return.portfolio(ptest)
           portfolio.returns
2018-02-06              -0.5
2018-02-07               0.1

casras111 avatar Feb 17 '18 20:02 casras111

This is actually not a bug but a feature. The weights applied to Return.portfolio come into effect at closing of the day (e.g. weight on Feb 6,2018 are effective on Feb 7, 2018). This is relevant for portfolio analysis because when you are back-testing your system you don't want your forecasted weights to be ahead of the returns they are applied to. You get bogus backtesting results otherwise. To see this do the following test:

> (ptest <- xts(order.by=(d-10:11),c(0.1,-0.5)))
           [,1]
2018-02-06 -0.5
2018-02-07  0.1
> (w2 <- xts(order.by=(d-10:11),c(1,NA)))
           [,1]
2018-02-06   NA
2018-02-07    1
> (Return.portfolio(ptest,weights = w2))
           portfolio.returns
2018-02-07                NA

As you see the NA on the 6th is applied to the portfolio return on the 7th as it should be.

Hope this helps.

goodnewz avatar Nov 01 '18 04:11 goodnewz

@goodnewz is correct. Return.portfolio rebalances on the observation after the rebalance timestamp, effectively before the next timestamp, to avoid entering biases.

If you send in a time series of weights that start before your observations, I believe that they will be applied on the first observation in your return data.

braverock avatar Nov 01 '18 15:11 braverock