Portfolio Level Monte Carlo Analysis

Following up on the prior Strategy Stress Testing post: with the release of AmiBroker version 6.10.0 a new Monte Carlo mode has come available for simulating portfolio equity changes. Instead of randomizing the trade list, the new mode uses bar-per-bar percent equity changes at the portfolio level to generate permutations. Consequently cross-sectional correlations are preserved. According to AmiBroker’s developer, the new method is perfectly fine for multiple overlapped positions, provided the number of bar-per-bar equity changes is sufficiently large (> 100).


The portfolio level Monte Carlo simulation is controlled by a couple of new SetOption fields which allow for AFL implementation right into the strategy code:
The Monte Carlo Portfolio Analysis code is suitable for copy/paste inside a rotational model like the familair Simple GMR code attached to the prior Monte Carlo post. However, my preferred method is to save the code as a separate file for inclusion in strategy models by calling the #include command:
The update code for Simple GMR with the #include call implemented is available on the Google drive folder connected to this post. There you will also find the Monte Carlo Portfolio Analysis code. Be sure to save the latter code in AmiBroker's dedicated Include folder otherwise the #include call will not function: AmiBroker > Formulas > Include

The Monte Carlo analysis is turned on/off by toggling the "Enable Monte Carlo Simulation?" switch through the Parameter window (equalizer icon). With the switch at "Yes" the backtest will take a little longer to finish, since your AMD/Intel cpu has to run the 1,000,000 simulations as declared in the code (see above). The Monte Carlo CDF charts are then available through the Report icon.

Point to note: the #include code will override the appropriate settings made on the Monte Carlo tab of the Backtester settings (wrench icon).

Enjoy!