Free Friday 10 – Properly Funding a Strategy with Monte Carlo

In this week’s Free Friday strategy (#10) I want to talk about one method of using Monte Carlo analysis to properly size a trading system – again, this is just one method!

The strategy itself is one created for the Semiconductor ETF or $SMH. All you Dow theorists – if any remain – can rejoice!

The strategy uses 4 rules for entry:

  1. 20 Period ATR[0] <= ATR[2]
  2. High[1] <= Close[7]
  3. High[5] > Low[8]
  4. Low[4] <= High[8]

**Remember [0] means current bar and [2] means 2 bars ago**

The exits used are a 7 day maximum hold or exit after 3 profitable closes. The stop will be a rolling 5 day minimum low. That is, stop out at the lowest low of the previous 5 days.

Couple quick notes. The chart on the left is from TradeStation and the chart on the right is from Build Alpha.

Notice TradeStation x-axis is trade number and Build Alpha x-axis is by date (both can display either way).

The grey line is buy and hold for SMH. You can see since early 2012 (the beginning of our out of sample period) we have much superior risk-adjusted return.

Also, please note that the test was done using only 100 shares per trade. This is essentially nothing, and does not account for underlying price changes over time, but this post is for demonstration purposes only.

Sizing with Monte Carlo Analysis

A quick recap of what a simple Monte Carlo test can be… we will reshuffle the order of the trades 1,000 times. Each time we will re-create an equity curve by adding the newly shuffled trades up one by one. Each time we will calculate a max drawdown as if the trades had actually happened in this shuffled order.

For the first test, I assumed an account size of $2,500.00. I ran the Monte Carlo test using Build Alpha which created 1,000 new drawdowns and the picture below. For example, the first Monte Carlo run (1 of 1000) might have calculated a $275.00 drawdown on the reshuffled trades or an 11% drawdown (275/2500). The second Monte Carlo run (2 of 1000) would reshuffle the trades and might recalculate the drawdown to be $450.00 on this random ordering of the trades; that would be an 18% drawdown (450/2500). After 1000 reshuffles we are left with the image below – all done instantly.

The green bars are just a frequency distribution of the [percentage] drawdowns. The blue, more important, line is a cumulative distribution which adds the green bars up as you move left to right.

The red “X” shows that 95% (y-axis) of all the drawdowns were less than or equal to 30% (x-axis). So we can say “we are 95% confident our drawdown should not exceed 30% of the our $2,500.00 account”. In other words, we have a 5% chance of experiencing a 30% or more drawdown trading this system.

Furthermore, the drawdown from the original backtest was 15.6% (391/2500) based on this $2,500.00 account. However, according to our Monte Carlo Drawdown analysis we have over a ~38% chance of realizing a drawdown equal to or greater than our max drawdown from the backtest of 15.6%! That’s too high and already Monte Carlo has helped make us more aware traders of the risk we are assuming. I calculated 38% by locating the blue line’s y-value where the x-axis was equal to our 15.6% drawdown. The blue line’s value was approximately 62. So 62% of our Monte Carlo drawdowns were less than or equal to our max drawdown from the backtest. In other words, a 38% chance to see a greater drawdown like I previously mentioned.

That is too high for me; a 30% drawdown can be unbearable and 30+% chance of exceeding our backtest drawdown is too high. Let’s increase our account size to $4,000 and re-run the Build Alpha Monte Carlo Drawdown analysis. Pictured below:

Now you can see that 95% of our drawdowns (red “X”) were 18% or less. In other words, there is only a 5% chance we will experience a drawdown of 20% or more using a $4,000 account. That is comfortable levels and chances of drawdown to most.

Now the question becomes… is setting aside $4,000 to COMFORTABLY trade this system worth the return this system can generate? That is a more personal question, but a question we will dive into in later posts.

Cheers and enjoy the 3-day weekend,

Dave

Old Posts:

New Posts:

Thanks for reading,
Dave

Free Friday 9 – Intermarket Signals

What is Intermarket Analysis?

Intermarket analysis is a method of analyzing one market based on another market or their intermarket relationship. Common intermarket analysis techniques include correlation, cointegration, and relative value. However, in its simplest form, one can also trade one market based on what another market is doing on its own. 

Intermarket Analysis Trading Strategy Example

In this week’s Free Friday strategy (#9) I display a strategy built using inter-market signals. Inter-market signals/analysis is the ability to generate trading signals and filters for a primary market based on what another market may be doing.

For example, you may only want to buy the stock market when gold is trading lower or when bonds are below their 200 simple moving average.

Build Alpha now let’s you test these exact sort of scenarios and build strategies taking into account up to 3 markets (plus Vix). This specific strategy was built for SPY (S&P500 ETF) but takes into account Gold (GLD ETF) and holds for a maximum of 2 days.

There are no other exit rules or sophisticated risk management; all trades assume only a 100 share position for testing purposes.

The Entry

1. $SPY’s 2-period RSI <= 90
2. Gold’s 50 period simple moving average is greater than Gold’s 200 period simple moving average
3. Gold closed below both its 10 period simple moving average and its 50 period simple moving average

The Exit

Exit after holding for 2 days

Intermarket Analysis with Build Alpha

For a better explanation of inter-market signals and how to configure Build Alpha to generate strategies based on them please watch this short video I made: https://www.youtube.com/watch?v=CaFRO_gvR-8

There might even be TradeStation/MultiCharts code in the video?!?

Step 1 – Select Symbols

In the upper left, select the primary symbol in the Symbol dropdown. This is the primary market that the automated trading strategy will execute trades on. Next, select a symbol for market 2. This is the secondary market we can use to generate intermarket technical analysis signals.

Step 2 – Select Signals

Scroll down in the built-in signal library and notice signals prefixed with “market 2”. These signals are calculated on market 2 and can be used to generate signals to trade the primary symbols. If you have selected a symbol for market 3 you may also notice signals prefixed with “market 3”. 

Step 3 – Run Simulation

After selecting your symbols and signals, hit simulation. Build Alpha will begin building the best automated trading strategies based on your inputs. If the strategy results do not use any market 2 (or market 3) signals that is because these signals did not improve or enhance performance. 

Thanks and enjoy the weekend,

-Dave

Thanks for reading,
Dave

Read more:

Free Friday January 2017 Update

Happy Friday!

For this Free Friday edition I will just share an update of the first 7 Free Friday strategies. One month is not indicative of anything and these are just meant for educational purposes (strategies may or may not have gone through the entire rigor of the robustness/validation techniques described on this site).

I post the strategies on twitter and you can follow me here: @dburgh.

Free Friday #1: eMini S&P500 +$625.00
Free Friday #2: Gold Futures +1,630.00
Free Friday #3: Oil Futures -$310.00, +$2,940.00, +$470.00
Free Friday #4: US Bond Market No Trades
Free Friday #5: Nasdaq Futures No Trades
Free Friday #6: Russell Futures -$790.00,-$490.00,-$765.00,+$310.00,+$985.00,-$315.00
Free Friday #7: SPY ETF No Trades

January Total: +$4,290.00

All in all, not a bad month. A few things to consider… 1. One month(11 trades) is by no means telling, but it is sure nice to see profits. 2. Not all these strategies went through the full spectrum of validation techniques. 3. Strategy #6 only has 1 rule so it is much more common for its entry condition to be satisfied; hence the larger number of trades. 4. All of these results based on 1 contract traded

If you missed Free Friday#8 where I broke down one of the new validation techniques, Randomized Monte Carlo testing, then please take a look here: Free Friday 8 – Randomized Monte Carlo

Enjoy the weekend,
Dave

Thanks for reading,
Dave

Free Friday 8 – Randomized Monte Carlo

Randomized Monte Carlo Strategy Analysis

In this Free Friday, I want to introduce a new feature to Build Alpha: The Randomized Monte Carlo Test. The purpose of this test is to give us another robustness test or tool to identify potentially unreliable trading strategies or lying backtests. 

As system traders, all we can do is improve the probabilities that the strategies we take live will succeed. Identifying lying backtests or misleading results can both save the trader money and headaches. 

The strategy below shorts the EURUSD futures contract and has shown nice results on both in-sample and out-of-sample testing from 2002 to 2017 with a fairly large sample size of over 600 trades. Should we greenlight this strategy and trade it live?

All performance metrics and even the simple reshuffle monte carlo method (pictured below) seems to give favorable insights to trading this strategy live. This strategy shows almost all Monte Carlo paths are profitable after 150 trades. Should we go live?

Let’s introduce one more test, the Randomized Monte Carlo test. This test can help us determine if this strategy’s backtest is lying to us and can potentially harm our account.

What is the Randomized Monte Carlo Test?

The Randomized Monte Carlo test re-trades the entry signal while modifying each trade’s exit at random (and within reason). The Randomized Monte Carlo test will not introduce new exit logic or remove any exit logic. That is, if the original strategy does not use a stop-loss then the Randomized Monte Carlo test will not introduce one. This is vital as altering the strategy’s logic can alter the underlying strategy to the point where the results do not tell us anything informative about the original strategy.

This particular strategy uses three unique exit strategies:

  • Maximum 3-day hold  ||  First profitable close  ||  Stop at rolling 5-day high

In the Randomized Monte Carlo test, trade one will enter as expected but we may exit with a two-day max hold, first profitable close, or stop at the rolling four-day high.

The second trade will enter as expected but we may exit with a three-day max hold, second profitable close, or a stop at the rolling five day high.

Trade three will enter as expected but we may exit with a three-day max hold, first profitable close, or stop at the rolling seven day high.

This process will repeat for ALL the trades randomizing the exit each time. The first three hypothetical trades of the first run, that are stated above, are summarized below for simplicity and comparison’s sake. Again, this is random so you can imagine the variations possible.

  1. Maximum 2-day hold  ||  First profitable close       ||  Stop at rolling 5-day high
  2. Maximum 3-day hold  ||  Second profitable close  ||   Stop at rolling 5-day high
  3. Maximum 3-day hold  ||   First profitable close      || Stop at rolling 7-day high

We then repeat this test and re-trade the strategy 1,000 or more times to make sure we have a reliable sample and remove any lucky “randomizations”. The results of this test on this Free Friday strategy are below. Yikes. 

What does the Randomized Monte Carlo Test tell us?

In this particular example, this test and new feature in Build Alpha was able to identify a lying backtest and save us from implementing a false positive or “too good to be true” trading strategy. 

The test is intended to validate we have not overfit our exit strategies/signals. If the Randomized Monte Carlo results are all positive, then it can tell us that our strategy’s entry has enough edge worth harvesting and could maintain profitability even with random exits. However, seeing struggling results like the graph above indicate a lying backtest and potentially overfit exits. This is just another tool in our trading toolbox to help prevent or reduce the risk of curve fitting.

For instance, strategies showing nice equity curves but poor edge ratios are always suspicious. The Randomized Monte Carlo test is a good candidate here and can identify overfit exits that are squeezing out profits when the edge ratio indicates there should not be much! Anyways, more to come in Build Alpha on strategy robustness and reliability.

Thanks for reading,
Dave

Read the Full Monte Carlo Simulation Guide (free equity curve simulator).