Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Of course its possible - I think what you're actually asking is has someone already built a package/function for you. – jeff m Apr 28 '13 at 20:24

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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