Tuesday, March 27, 2012

What Your 8th Grade Science Teacher Can Teach You About Trading Systems: A Simple Format for Testing Trading Systems

Summary
1.  Trading logs give you current statistics on a real or simulated account.
2.  Trading reports are a way to develop, organize and refine an objective trading system.
3.  The 8-step scientific method is a great way to start putting together a trading report.
4.  But, the trading report doesn’t quantify how it FEELS to trade a system – for example, how will you feel during your peak to peak draw downs and can you accept that you don’t know when any of the outputs will occur.

Like any good “scientist,” keeping organized trading logs and trading reports are important when building your own trading system.

For our purposes let’s define what a trading log and a trading report are. 

Trading Log

A trading log tracks your performance either in real time or historically for an account you currently trade with real money or in simulated (“SIM”) mode.  Generally, it tracks such items as:

For each trade:
-           Date
-           Broker
-           Instrument (Stock/Future) Symbol
-           Trade Position (Long/Short)
-           Quantity
-           Entry
            -           Price
            -           Time
            -           Quantity
-           Exit
            -           Price
            -           Time
            -           Quantity
-           Initial Stop (Also called “R” – this would be your stop loss amount)
-           Commission Paid
-           Win/Loss – whether the trade was profitable or a loser
-           Profit/Loss Amount
-           R Multiple (P&L on trade divided by Initial Risk)
-           % Gain/Loss
-           Strategy Used (your name for the strategy)
-           Comments – what you saw to enter (if discretionary)

For all trades (you could break this up on a daily/weekly/monthly basis):
-           Gross Profit/Loss
-           Net Profit/Loss – Gross profit/loss net of commissions
-           Win Rate - % of Trades Profitable
-           Number of Trades
-           Expectancy
-           Total P&L
-           Total % Gain/Loss
-           Total R
-           Average R
-           Maximum Drawdown
-           Average Drawdown

For an off the shelf trading log, check out TradingSpreadsheets.com.

Trading Reports

While keeping a trading log is very important, for our purposes we need to focus on creating and designing trading reports when building a system. 

A trading report encompasses the design, testing, optimization and results of a trading system. 

This is necessary for a couple of reasons:

1.  We want to be extremely clear about what we want to test when designing our trading system.  Clarity about what we are testing is important because it imposes limits on what we are measuring and what those measurements mean.  We want objective signals that can be objectively evaluated using the statistical techniques that we have talked about earlier and will discuss in depth later.

In the book, Evidence Based Technical Analysis, the author David Aronson distinguishes between objective and subjective signals in a trading system: 

The acid test for distinguishing an objective from a subjective method is the programmability criterion: A method is objective if and only if it can be implemented as a computer program that produces unambiguous market positions (long, short, or neutral).

Aronson goes on to discuss the binary methods he employs when evaluating a trading signal.  In sum, it’s a 3 step process:

1.         Evaluate the input from the market - raw price data such as open, high, low, close, volume data, or any of the various technical indicators available.

2.         Apply an objective rule to it like a mathematical operator (plus, minus,  multiplication etc.) or a logical operator (if, then statements etc.)

3.         The output is either a +1 for long position, 0 for neutral or -1 for short

2.  We want to have a concrete record of what we tested so we:

            1.         Don’t test the same thing more than once (and waste time);
            2.         Can look back at the testing to either re-inforce our rules (so we don’t                               break them in the future) or become complacent; and
            3.         Have a platform to build new trading ideas in the future.

A Simple Format for Testing from Junior High

Think back for a second to junior high when you where taught the steps for the scientific method.  They are uniquely designed to be implemented into a trading report.  They are:

1.  Ask a question.

“What indicators accurately predict the direction of the S&P E-mini?”

2.  Do background research on the question.

This may include reading blogs, books and other sources on both indicators and the instrument in question.

3.  Construct a hypothesis.

After the research, you may believe that you can predict, with a high degree of probability, the direction of the S&P E-mini by using simple moving average crossovers. 

It is important at this stage to accurately and objectively state your hypothesis.

“Using a daily bar, when the close of the S&P E-Mini is greater than the 20-day simple moving average the output is long (+1) and when the close of the S&P E-Mini is less than the 20-day simple moving average, the output is short (-1).”

Really, there can be no ambiguity about this statement.  You go long if the close of the daily bar is greater than the 20-day simple moving average and go short if it is the opposite.

4.  Test with an experiment.

The next step is to code the hypothesis (trade signal) into some type of software (Multicharts, Tradestation, Excel etc.) and backtest the data.  Some important factors come into play here, namely:

-           In-Sample Testing - How far back to test the hypothesis
-           Out-of-Sample Testing - Keeping a set of sample data to use for “Out of Sample”Analysis to make sure that we weren’t “curve fitting” the signal to the available  data.
-           Rollover - For futures data, we also want to make sure that we aren’t running into problems with the “rollover” of the contract

We will get into each of these problems but a simple “experiment” of our 20-day moving average crossover could be used by looking back at the last 500 days, using 300 days for the “In-Sample” Testing and 200 days for the “Out-of-Sample” Testing.

In Multicharts, the long entry of the moving average crossover system is coded as “MovAvg Cross LE” and the short entry is “MovAvg Cross SE”.  These are automatically built in with the system – just change the Length of the simple moving average to 20.

5.  Analyze the results.

After testing the hypothesis on the in-sample and out-of-sample data, we then want to do three things:

1.  Check out the statistics output of the system you are using and by using our own trading statistics calculator;

2.  Use the optimization function to maximize the signal; and

3.  Compare the optimized or original signal against a benchmark either a buy and hold strategy or some other relevant benchmark.

Here is the performance summary for the 20 day moving average over the last 500 days from Multicharts:


Here is the trading stats calculator:

Inputs


Winning Percentage
31.11%
Average Win
1661.61
Average Loss
1141.53
Account Size
10,000
Sample Size
45
Standard Dev (All Trades)
1000
Largest Losing Trade
2887.5

Outputs

$
%
Expectancy Per Trade
-269.47
-269.47%
Edge
-
-2.69%
Fractional Gain (FG)
1661.61
16.62%
Fractional Loss (FL)
1142
11.42%
Initial Risk Per Trade (Unit Size)
1141.53
11.42%
Win/Loss Ratio (Profit Ratio)
-
1.46
Capital Units Available
-
8.76
Minimum Win % Required to Be Profitable1
-
41.00%
Maximum Average Loss to Be Profitable3
750.37
7.50%
Minimum Avg Win to Be Profitable2
2,527.80
25.28%
Risk of Ruin
-
160.36%
t-Test
-
11.15
Optimal F
-
-0.162175929
Maximum Leverage
-17804.73842
-

 Ouch – this was a pretty big net loser by any measure.

When you go to optimize, I did an “exhaustive” calculation of the 20-day MA and tested for both the long entry and short entry lengths from 10 to 50 using a 1 step.  Multicharts goes back and tests all of the signals but changes the hypothesis for us.  For the first test, it used a 10-day moving average on the long side and a 10-day moving average on the short side.  Then it did a 11-day/10-day and on and on. 

Interestingly, the most “optimized” results came from using a 37-day simple MA for the long entry and a 15-day simple MA for the short entry.  This resulted in a net profit of 14,412.50 but had a maximum drawdown of 21k.  Coming in a close second was a 44/15 length MA that had a similar net profit of 14,062.5 but a drawdown that was closer to 16k.

Here is the optimization report for the basic system:


Here is the optimization report for the basic system:

Net Profit
Gross Profit
Gross Loss
Total Trades
% Profitable
Winning Trades
Losing Trades
Max Intraday Drawdown
Length (MovAvg Cross LE)
Length (MovAvg Cross SE)
14412.5
25462.5
-11050
22
45.45455
10
12
-20962.5
37
15
14062.5
23625
-9562.5
22
40.90909
9
13
-16287.5
44
15
14062.5
23625
-9562.5
22
40.90909
9
13
-16287.5
45
15
13900
28987.5
-15087.5
29
37.93103
11
18
-16662.5
16
31
13887.5
24862.5
-10975
24
45.83333
11
13
-20437.5
33
15
13875
25987.5
-12112.5
22
50
11
11
-21775
37
16
13400
27150
-13750
25
36
9
16
-16162.5
16
32
13387.5
25537.5
-12150
24
37.5
9
15
-19937.5
38
15
13350
25387.5
-12037.5
24
50
12
12
-21250
33
16
13137.5
25300
-12162.5
26
50
13
13
-20762.5
33
17
13125
29862.5
-16737.5
31
35.48387
11
20
-16700
16
29

Here is the trading stats calculator for the optimized result using a 37-day simple MA for the long entry and a 15-day simple MA for the short entry:

Inputs




Winning Percentage
45.45%

Average Win
2546.25

Average Loss
920.83

Account Size
10,000

Sample Size
22

Standard Dev (All Trades)
1000

Largest Losing Trade
3550

Outputs

$
%
Expectancy Per Trade
654.96
654.96%
Edge
-
6.55%
Fractional Gain (FG)
2546.25
25.46%
Fractional Loss (FL)
921
9.21%
Initial Risk Per Trade (Unit Size)
920.83
9.21%
Win/Loss Ratio (Profit Ratio)
-
2.77
Capital Units Available
-
10.86
Minimum Win % Required to Be Profitable1
-
27.00%
Maximum Average Loss to Be Profitable3
2,121.49
21.21%
Minimum Avg Win to Be Profitable2
1,105.20
11.05%
Risk of Ruin
-
24.06%
t-Test
-
11.94
Optimal F
-
0.257224491
Maximum Leverage
13801.17417
-


6.  Draw a conclusion:  (1) don’t reject the hypothesis, (2) reject the hypothesis or (3) don’t reject part of the hypothesis/reject part of the hypothesis.

As they say, you can never be too sure.  Statisticians like to say that we can never really say anything is true, we can only say that based on the information we have, we can’t outright reject our hypothesis.  Or we can reject the hypothesis based on the sample that we have.  Or we can do both – reject part and not reject part.

For the above system, based on the information that we have, we could safely reject the 20-day MA crossover system.  It is clearly a net loser.  But you could not reject the 37/15 system with a corollary that more data needs to be analyzed and more hypotheses should be created to make the system more robust.

7.  Report the Results.

We could create one of those tri-fold cardboard stands to present our data, but for us having a good ol’ Excel spreadsheet with all of our tests neatly outlined will suffice.  This will be the subject of the next blog post so stay tuned.

8.  If the hypothesis is rejected or partially true, construct another hypothesis and repeat steps 1 - 8.

This is really the great part about the scientific method.  We have a slightly promising 37/15 signal but it doesn’t have enough data to support it and it is not that robust – based on the trading stats it is not likely to have the same performance when we “de-curve” fit it.  What worked for the last 500 days may not work over the next 500 days?  But it does create more questions and helps point us in the right direction.  Could we add another indicator?  Could we use a smaller bar size?  Could we risk less equity when certain conditions exist?  What are those conditions?  Etc. Etc.  More questions than answers but that is the joy of building trading systems.

What the Trading Report Doesn’t Tell Us:  The Psychological Aspects of the System

Trading is a unique mixture of emotions and technical expertise.  What we need to quantify and measure about any system can broken down and will be explored in later posts:

-           What does it feel like to take the maximum drawdown?  Can we ride it out?
-           What does it feel like to have the max string of losing trades?
-           What does it feel like to compound the growth on the upside and downside?
-           What does the profit and losses feel like on a day to day basis?
-           How would you feel if you took your biggest loss or your biggest win?
-           Can you accept that you don’t know when any of this will happen?

No comments:

Post a Comment