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?

d=52*5-1 #multiple of 7
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.

  • 1
    $\begingroup$ Of course its possible - I think what you're actually asking is has someone already built a package/function for you. $\endgroup$
    – jeff m
    Apr 28, 2013 at 20:24

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.