Monte Carlo Simulation for Trading System in AmiBroker

16
Monte Carlo Simulation AMIBROKER QUANT COURSE 1

Transcript of Monte Carlo Simulation for Trading System in AmiBroker

Page 1: Monte Carlo Simulation for Trading System in AmiBroker

1

Monte Carlo Simulation

AMIBROKER QUANT COURSE

Page 2: Monte Carlo Simulation for Trading System in AmiBroker

2

Why perform Monte Carlo Simulation?

•Probability of Risk & Reward•Worst Scenarios of Risk & Reward•Strategy Robustness

Page 3: Monte Carlo Simulation for Trading System in AmiBroker

3

What is Monte Carlo Simulation?

Random SamplingCalculate Statistics

Page 4: Monte Carlo Simulation for Trading System in AmiBroker

4

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 system

Page 5: Monte Carlo Simulation for Trading System in AmiBroker

5

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

<= 10% chance that CAR < 27% <= 90% chance that MDD < 9%<= 10% chance that MDD > 9%

Random Sampling: Trades

Page 6: Monte Carlo Simulation for Trading System in AmiBroker

6

MC Simulation in Trading System1. Model a system (trading strategy) in order to get results such as

CAR and MDD2. Backtest system/strategy consisting of several processes (buy,

sell, cut loss,… )3. Repeatedly random sampling from the processes to get

various resultsRandom 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 CAR6. Construct cumulative distribute function, CDF

Page 7: Monte Carlo Simulation for Trading System in AmiBroker

7

Trade Shuffling (AmiBroker’s feature)Trade Simulating (User’s code)

2 TYPES OF MC SIMULATION

Page 8: Monte Carlo Simulation for Trading System in AmiBroker

8

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, …

Page 9: Monte Carlo Simulation for Trading System in AmiBroker

9

Recap: 2 Types of MC Simulation in Trading

Trade ShufflingUse AmiBroker’s Built-in MC Feature

1 Backtest -> 1 Trade List -> Shuffle trades for 1,000 times -> 1,000 Equity Curves

Trade SimulatingUse user’s code and optimize function

1,000 Backtests -> 1,000 Trade Lists -> 1,000 Equity Curves

Page 10: Monte Carlo Simulation for Trading System in AmiBroker

10

Trade Shuffling MCSAdvantages• 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 MCSAdvantages•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

Page 11: Monte Carlo Simulation for Trading System in AmiBroker

11

Trade Shuffling Example

AMIBROKER QUANT COURSE

Page 12: Monte Carlo Simulation for Trading System in AmiBroker

12

Trade Shuffling Example

Page 13: Monte Carlo Simulation for Trading System in AmiBroker

13

Testing from start2011 – end2014

Page 14: Monte Carlo Simulation for Trading System in AmiBroker

14

Trade Shuffling MC Results

Page 15: Monte Carlo Simulation for Trading System in AmiBroker

15

Monte Carlo Simulation Template“Trade Simulating”

AMIBROKER QUANT COURSE

Page 16: Monte Carlo Simulation for Trading System in AmiBroker

16

Code for Trade Simulating Simulation•Slippage•Missing Trades•Partially Filled Orders•Additional Noise