Testing Random-Start Portfolio Performance with Periodic Rebalancing
Summary
The document describes a proposed way to evaluate a multi-asset portfolio using weekly returns and a time-varying matrix of portfolio weights. The intended test samples start dates, measures performance over a one-year period, rebalances at regular intervals, accounts for transaction fees at rebalancing, and averages results across sampled windows. The example code creates synthetic weekly returns and weights, then selects start dates that leave enough data for the full test period.
A response recommends the fPortfolioBacktest package and points to its documentation, with a plotting function suggested for visualizing results. The exchange does not provide a complete implementation of the requested test, explain how to apply fees, or define performance measures. Its sample data are randomly generated, so they do not offer evidence about a real strategy. A practical backtest would need careful treatment of weight timing, return alignment, overlapping windows, and transaction costs.
Key ideas
- The proposed evaluation samples start dates for fixed-length portfolio test windows.
- The portfolio uses weekly asset returns and weights that may change through time.
- The test is intended to rebalance periodically and account for fees at each rebalance.
- The example filters start dates to ensure each selected window has sufficient data.
- The response points to fPortfolioBacktest but does not provide a complete fee-aware implementation.
Tags
Full text
# analyze strategy performance with given matrix of weights/time and weekly returns in R
# analyze strategy performance with given matrix of weights/time and weekly returns in R
I have a matrix of 259 weekly returns, 50 assets and a portfolio composition for each of the 259 weeks. I would like to test the performance of the portfolio during 52 weeks, rebalancing every 12 weeks also taking into account fees for each rebalancing, etc. I would choose 50 dates randomly, perform the test each date, store results and finally average them. Is there any way of doing this in R?
```
n=50
d=52*5-1 #multiple of 7
w=16
ns=50
returns=xts(matrix(rnorm(n*d,0,0.01),d,n),Sys.Date()-seq(d*7,1,by=-7))
A=c(rep(1/w,w),rep(0,n-w))
weights=xts(t(replicate(d,sample(A,n))),Sys.Date()-seq(d*7,1,by=-7))
dates.v=as.Date(replicate(ns,sample(index(returns),1)))
for (i in 1:ns) {
while (dates.v[i]+52*7>max(index(returns))) {dates.v[i]=sample(index(returns),1)} #this is to ensure that we always use one entire year
}
```
I already had a look to the fPortfolio, backtest and PortfolioSim packages but haven't found a similar example so don't know whether is possible or not.
## Answer by RndmSymbl (score 3)
https://quant.stackexchange.com/a/10176
Have a look at fPortfolioBacktest. An example can be found here: https://r-forge.r-project.org/scm/viewvc.php/pkg/fPortfolioBacktest/man/portfolioBacktesting.Rd?view=markup&revision=4086&root=rmetrics
Edit: you may want to try backtestPlot(smoothedPortfolios) to visualise the strategy performance.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.