Monte Carlo Simulation
AMIBROKER QUANT COURSE
1
Whyperform Monte Carlo Simulation?
•Probability of Risk & Reward
•Worst Scenarios of Risk & Reward
•Strategy Robustness
2
Whatis Monte Carlo Simulation?
Random Sampling
Calculate Statistics
3
What is Monte Carlo Simulation?
A method uses random sampling to calculate statistics of a process.
Examples of Random Sampling:
• Instead of buying stocks A-B-C in this order, the order could be B-C-A or C-A-B
• Instead of setting slippage to a constant 10%, it could be set to a random number 5% to 15%
Examples of Calculate Statistics:
• Instead of average CAR 40%, 10% chance that CAR will be less than 27%
• Instead of average MDD 15%, 10% chance that MDD will be greater than 9%
Please read: AmiBroker User’s Guide: Monte Carlo Simulation of your trading system4
MC Simulation in Trading System
•Model and backtest a trading strategy/system
•Random sampling repeatedly: trades or numbers
•Calculate statistics to summarize results
•Construct cumulative distribution function (CDF) of those results
5
<= 10% chance that CAR < 27% <= 90% chance that MDD < 9%
<= 10% chance that MDD > 9%
Random Sampling: Trades
MC Simulation in Trading System
1. Model a system (trading strategy) in order to get results such as CAR and MDD
2. Backtest system/strategy consisting of several processes (buy, sell, cut loss,… )
3. Repeatedly random sampling from the processes to get various results
Random sampling for trading system could be
1. Trades such as buy and sell stocks. “Trade Shuffling”
2. Random numbers added into parameters such as slippage. “Trade Simulating”
4. After random sampling for 1000 times, 1000 results of CAR are obtained.
5. Then calculate statistics to summarize the results such as an average of CAR
6. Construct cumulative distribute function, CDF
6
Trade Shuffling (AmiBroker’s feature)
Trade Simulating (User’s code)
2 TYPES OF MC SIMULATION
7
2 Types of Monte Carlo Simulation
• Trade Shuffling
• Set parameters in AmiBroker’s built-in Monte Carlo Simulation
• Backtest 1 time and get 1 trade list, consisting of many Trades with %profit/loss
• Shuffle orders of the Trades 1,000 times to get 1,000 results and equity curves
• Summarize the results: average CAR, minimum CAR, CDF of CAR, …
• Trade Simulating
• Code random numbers into various parameters such as slippage and missing trades
• Backtest 1,000 times to get 1,000 trade lists in optimization table results
• Copy results into Excel and use Excel table to summarize the results
• Summarize the results: average CAR, minimum CAR, CDF of CAR, …
8
Recap: 2 Types of MC Simulation in Trading
Trade Shuffling
Use AmiBroker’s Built-in MC Feature
1 Backtest -> 1 Trade List -> Shuffle trades for 1,000 times -> 1,000 Equity Curves
Trade Simulating
Use user’s code and optimize function
1,000 Backtests -> 1,000 Trade Lists -> 1,000 Equity Curves
9
Trade Shuffling MCS
Advantages
• AmiBroker’s built-in feature (ready to use)
• Provide necessary basic statistical parameters
• Fast. Require short computational time
• Suitable for new traders in testing and designing
Disadvantages
• Assumption of independent trades
• Results derived from the same trade list
• Limit position sizing methods
• Missing various important statistical parameters
Trade Simulating MCS
Advantages
• User controls all aspects of simulation model
• Perform Sensitivity Analysis
• True simulation trading model
• Use the assumptions to monitor actual trading
Disadvantages
• User’s assumptions: slippage, missing trades, …
• Not readily to use
• Slow. Take times to run many backtests
• Manually calculate all statistics by user
10
Trade Shuffling Example
AMIBROKER QUANT COURSE
11
Trade Shuffling Example
12
Testing from start2011 – end2014
13
Trade Shuffling MC Results
14
Monte Carlo Simulation Template
“Trade Simulating”
AMIBROKER QUANT COURSE
15
Code for Trade Simulating Simulation
•Slippage
•Missing Trades
•Partially Filled Orders
•Additional Noise
16

Monte Carlo Simulation for Trading System in AmiBroker

  • 1.
  • 2.
    Whyperform Monte CarloSimulation? •Probability of Risk & Reward •Worst Scenarios of Risk & Reward •Strategy Robustness 2
  • 3.
    Whatis Monte CarloSimulation? Random Sampling Calculate Statistics 3
  • 4.
    What is MonteCarlo Simulation? A method uses random sampling to calculate statistics of a process. Examples of Random Sampling: • Instead of buying stocks A-B-C in this order, the order could be B-C-A or C-A-B • Instead of setting slippage to a constant 10%, it could be set to a random number 5% to 15% Examples of Calculate Statistics: • Instead of average CAR 40%, 10% chance that CAR will be less than 27% • Instead of average MDD 15%, 10% chance that MDD will be greater than 9% Please read: AmiBroker User’s Guide: Monte Carlo Simulation of your trading system4
  • 5.
    MC Simulation inTrading System •Model and backtest a trading strategy/system •Random sampling repeatedly: trades or numbers •Calculate statistics to summarize results •Construct cumulative distribution function (CDF) of those results 5 <= 10% chance that CAR < 27% <= 90% chance that MDD < 9% <= 10% chance that MDD > 9% Random Sampling: Trades
  • 6.
    MC Simulation inTrading System 1. Model a system (trading strategy) in order to get results such as CAR and MDD 2. Backtest system/strategy consisting of several processes (buy, sell, cut loss,… ) 3. Repeatedly random sampling from the processes to get various results Random sampling for trading system could be 1. Trades such as buy and sell stocks. “Trade Shuffling” 2. Random numbers added into parameters such as slippage. “Trade Simulating” 4. After random sampling for 1000 times, 1000 results of CAR are obtained. 5. Then calculate statistics to summarize the results such as an average of CAR 6. Construct cumulative distribute function, CDF 6
  • 7.
    Trade Shuffling (AmiBroker’sfeature) Trade Simulating (User’s code) 2 TYPES OF MC SIMULATION 7
  • 8.
    2 Types ofMonte Carlo Simulation • Trade Shuffling • Set parameters in AmiBroker’s built-in Monte Carlo Simulation • Backtest 1 time and get 1 trade list, consisting of many Trades with %profit/loss • Shuffle orders of the Trades 1,000 times to get 1,000 results and equity curves • Summarize the results: average CAR, minimum CAR, CDF of CAR, … • Trade Simulating • Code random numbers into various parameters such as slippage and missing trades • Backtest 1,000 times to get 1,000 trade lists in optimization table results • Copy results into Excel and use Excel table to summarize the results • Summarize the results: average CAR, minimum CAR, CDF of CAR, … 8
  • 9.
    Recap: 2 Typesof MC Simulation in Trading Trade Shuffling Use AmiBroker’s Built-in MC Feature 1 Backtest -> 1 Trade List -> Shuffle trades for 1,000 times -> 1,000 Equity Curves Trade Simulating Use user’s code and optimize function 1,000 Backtests -> 1,000 Trade Lists -> 1,000 Equity Curves 9
  • 10.
    Trade Shuffling MCS Advantages •AmiBroker’s built-in feature (ready to use) • Provide necessary basic statistical parameters • Fast. Require short computational time • Suitable for new traders in testing and designing Disadvantages • Assumption of independent trades • Results derived from the same trade list • Limit position sizing methods • Missing various important statistical parameters Trade Simulating MCS Advantages • User controls all aspects of simulation model • Perform Sensitivity Analysis • True simulation trading model • Use the assumptions to monitor actual trading Disadvantages • User’s assumptions: slippage, missing trades, … • Not readily to use • Slow. Take times to run many backtests • Manually calculate all statistics by user 10
  • 11.
  • 12.
  • 13.
    Testing from start2011– end2014 13
  • 14.
  • 15.
    Monte Carlo SimulationTemplate “Trade Simulating” AMIBROKER QUANT COURSE 15
  • 16.
    Code for TradeSimulating Simulation •Slippage •Missing Trades •Partially Filled Orders •Additional Noise 16