1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Portfolio Analysis in R

Exercise

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)!

Instructions

100 XP
  • 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.