Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

Monte Carlo Analysis using Amibroker

1 min read

Monte Carlo Analysis is a process of validating the robustness of the Trading Strategy. With Monte Carlo Analysis we can simulate set of Equity curves using random numbers from the backtest data. These large sets of simulations are then used to find the likely probability distribution of an unseen risk in trading the strategy.

Monte Carlo Simulation performs trial runs using combination of positions from your trading system (backtested data) and collects statistics. You can use the statistics to analyze the characteristics of your trading systems.

AmiBroker in its recent version 5.94 beta onwards released a built-in Monte Carlo simulator which is high speed (30+ million trades per second) simulator. It uses high-quality Mersene Twister random number generator. Probably one can expect to access Monte Carlo Simulator in its upcoming major release upgrade (Amibroker Version 6.0 onwards).

Monte Carlo Settings in Amibroker
Monte Carlo Settings
[wp_ad_camp_5]

 
Following are the Input Parameters in Monte Carlo Settings available under backtester settings section in New Analysis

“Enable Monte Carlo Simulation” – turns on/off MC simulator

“Number of runs” – defines how many MC simulation runs is done (default value is 1000)

“Position sizing” – defines position sizing used by Monte Carlo simulator.

“Enable MC Equity Curves” – Enable MC (Min/Max/Avg) Equity Curves CDF Charts statistics

In Amibroker Monte Carlo Analysis is readily available in the backtest report once the backtest is done. The output statistics is set of CDF Charts (Cumulative Distribution Function Charts). MC Min/Max Equity, MC Final Equity, MC CAR, MC Max Drawdown $ and %, Lowest Equity are the output statistics from Monte Carlo Analysis. And one can access these reports from the Backtesting report from Amibroker v5.96 beta onwards.

MC Final Equity CDF Charts
MC Final Equity

Above chart shows the terminal equity level percentile. You can find out for a specific equity level, the percentile of trials that are above/below the level. Terminal equity level is the final equity value after a trial is run.

Above MC Final Equity is the cumulative result of 1000 simulated runs with a sample strategy. From the CDF charts 30% of the trial runs generated equity retuns between 7,50,000 and 12,50,000 returns. And rest of the 70% of the trail runs are able to generate more than 12,50,000 profits with a Initial Capital of 2,00,000. Every time you do backtest you will get different output statistics due to random generation of Equity Curve.

Sample Backtest Report with Monte Carlo Analysis

Monte Carlo Report

To enable Monte Carlo simulation in each backtest of optimization process and each individual backtest at code level one can
SetOption( “MCEnable”, 2 ); // value == 2 forces MC to be enabled everywhere (in every mode including optimization).

the old option:
SetOption(“MCEnable”, 1 ); // value == 1 enables MC only in portfolio backtests (default)

Monte Carlo will help you in understand the robustness of the trading system and idenifty the problem with the trading strategy but Monte Carlo analysis will not solve the problem in your trading system. To put it in simple words it is just a validation process. To create a better trading system the trader should adapt better trading design principles to improve his/her trading system performance.

If you are using lower version of Amibroker still one can perform Monte Carlo analysis using Amibroker alongwith Ms Excel which we will be discussing in the upcoming articles.

Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

[Live Coding Webinar] Build Your First Trading Bridge for…

In this course, you will be learning to build your own trading bridge using Python. This 60-minute session is perfect for traders, Python enthusiasts,...
Rajandran R
1 min read

[Webinar] Understanding and Mitigating Curve Fitting in System Trading

"Understanding and Mitigating Curve Fitting in System Trading"! This dynamic session aims to equip novice to intermediate traders, quantitative analysts, and financial engineers with...
Rajandran R
1 min read

P-Signal Strategy Long Only Strategy – Amibroker AFL Code

This tutorial provides an overview of the P-Signal reversal strategy, a quantitative trading strategy that utilizes statistical parameters and error functions to generate probabilistic...
Rajandran R
2 min read

5 Replies to “Monte Carlo Analysis using Amibroker”

  1. I want to learn Market Profile. I am based in Kolkata, West Bengal. Please revert back at the earliest. My no. is 9831921712

  2. Hi Rajandran, I am trying to learn AFL. I want to do the following:

    if ADX(14) is greater than 70{
    Paint Chart candle Red}
    else if ADX (14) is less than 25 {
    Paint Chart candle Green}
    else {
    Paint Chart Candle Gray}

    can you help

  3. Interesting article but would you care to elaborate what are the expected parameters of a robust system and what kind of systems should be avoided on the basis of the results of the simulation.

    I understand that it differs from trader to trader but I am looking for a ball park estimate.

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More