Optimization with periodic rebalancing
Running the optimization with periodic rebalancing and analyzing the out-of-sample results of the backtest is an important step to better understand and potentially refine the constraints and objectives. optimize.portfolio.rebalancing()
supports optimization with periodic rebalancing (backtesting) to examine out of sample performance. In addition to the arguments for optimize.portfolio()
, a periodic rebalancing frequency must be specified with rebalance_on
, training_period
to specify the number of periods to use as the training data for the initial optimization, and rolling_window
to specify the number of periods for the window width of the optimization. If rolling_window
is set to NULL
each optimization will use all data available at the given period the optimization is run.
To reduce computation time for this exercise, the set of random portfolios, rp
, is generated using 50 permutations, and search_size
, how many portfolios to test, is set to 1000. If you are actually optimizing portfolios yourself, you'll probably want to test more portfolios (the default value for search_size
is 20,000)!
This exercise is part of the course
Intermediate Portfolio Analysis in R
Exercise instructions
- Run the optimization with quarterly rebalancing. Set the training period and rolling window to 60 periods. The dataset is monthly data so we are using 5 years of historical data. Assign the optimization output to a variable named
opt_rebal
. - Print the results of the optimization.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Run the optimization backtest with quarterly rebalancing
opt_rebal <- optimize.portfolio.rebalancing(R = ___, portfolio = ___, optimize_method = ___, rp = rp, trace = TRUE, search_size = 1000, rebalance_on = ___, training_period = ___, rolling_window = ___)
# Print the output of the optimization backtest