Premium Market Analysis, Trader Education, Software, and Trading Strategies. Thirty Years Of Skin In The Game

DLPAL software

Dealing with Long/Short Data Bias When Developing Trading Algos

A fundamental principle of trading system development, whether automatic or manual, is that the data sample used to test hypotheses must include a wide variety of market conditions. Systems developed on data samples that are biased in a single direction are usually non-robust and their performance breaks down when the bias changes sign.

The stock market is an example where a strong upward bias can persist for extended periods of time.  During the late 1990s and due to cheaper processing power, retail backtesting software availability and an exploding equity market, stock trading system development became very popular. Many retail traders started developing systems using data before 2000. However, and primarily due to the strong positive bias in the data used, most systems were curve-fitting artifacts that broke down in the bear market that followed, generating large trading losses.

In the mid 2000s, motivated by quite unjustifiable claims that more recent data is more significant than older data, some trader system developers became again victims of the strong upward bias in data from 2003 to 2006 and developed systems that generated substantial losses in the plunge during 2008. Since, many understood that when developing trading systems it is important to consider a wide variety of market conditions. Practically speaking, the data used to develop trading systems should include uptrends, downtrends and sideways market activity. In essence, the diverse conditions in the data act as filters of weak correlations established during biased markets due to fitting the noise and prevent them for being manifested in the final system. Therefore:

  • Price series with a bias in a single direction are not suitable for development
  • Uptrends help filter out weak short signals
  • Downtrends help filter out weak long signals
  • Sideways activity helps filter out both long and short weak signals
  • Trading systems can only be developed for mature markets but
  • Mature markets are harder to trade because of diminishing returns and thus
  • One must look for new ways of discovering opportunities (forget about classical TA)

If a system must be developed for a new market for which there is no sufficient history that covers a wide variety of market conditions, then one could use a system developed for other markets that is also profitable in the market considered on available data.

An example

Next, I apply synthesis of trading systems for SPY using Price Action Lab and for two different cases. The first case considers only an uptrend and the second an uptrend plus a downtrend. This is just an example to illustrate the impact of different market conditions and not the usual procedure followed when developing systems. 

SPY_20140404

Both systems are developed based on the same performance criteria but using data from different periods, the first with data enclosed in the blue rectangle and the second with data enclosed in the red rectangle. The blue rectangle reflects a strong uptrend and the red one includes in addition a downtrend. Both systems will be tested on data from 2011, a year that included a downtrend a slightly negative performance for the underline index before dividends.

 1. Data from 04/01/2003 to 09/28/2007

Price Action Lab search workspace used:

2003to007WKS

Results

2003to2007

Each line in the above results corresponds to a price pattern that satisfies the performance parameters specified by the user.  Index and Index Date are used internally to classify patterns. Trade on is the entry point, in this case the Open of next bar. P is the success rate of the pattern, PF is the profit factor, Trades is the number of historical trades, CL is the maximum number of consecutive losers, Type is LONG for long patterns and SHORT for short patterns , Target is the profit target,  Stop is the stop-loss and C indicates % or point exits. Last Date and First Date are the last and first date in the historical data file.

Price Action Lab found 60 patterns in the above data sample, all long. This was to be expected. No software can find something in the data that does not exist. It is thus quite illogical and also unreasonable to expect software to discover something in the data that does not exist, i.e. short patterns that meet the performance criteria specified on the search workspace above, simply because there is none.

Below is the performance of this system of 60 patterns for single positions in the 2011 out-of-sample:

2011

The system return is -13.79% because patterns found on a strong uptrend tried to deal with a sideways/downtrending market. This should be expected. Many of the patterns were unsuitable for these new conditions. Some can try to put on the blame on the patterns but actually there are no good or bad patterns, just appropriate or inappropriate ones for given market conditions. It is unreasonable to expect a system developed on data from a strong uptrend to perform well under any conditions.

2. Data from 04/01/2003 to 02/27/2009

Price Action Lab search workspace used:

2003to2009WKS

Results

2003to2009

In this case Price Action Lab found only 14 patterns, 46 less than in the first case. In effect, the downtrend period acted as a filter of non-robust long patterns during a down market. This was expected. The patterns removed were either fitted to the uptrend noise or not suitable for use in a downtrend.

Below is the performance of this system of 14 patterns for single positions in the 2011 out-of-sample:

2011_2

In this case the return during 2011 is only -0.45%, slightly better than the unadjusted buy and hold return of -1.22%. The difference from case 1 is large and illustrates the impact of including different market conditions in the data series used for developing a system.

As markets mature, the swings filter out more patterns, rendering essentially a large number of them useless. However, Price Action lab results show that new patterns keep emerging that maybe reflect changing market conditions. Therefore, it is important to rebalance systems at least once at the end of each year using all available data and then test them on several different other comparable markets for robustness, like it was done in this post.  

Protection filters

Protection filters attempt to protect the equity of a system developed for uptrends or downtrends by adding additional logic to exclude signals during adverse conditions. For example, if a system was developed using data from an uptrend, a trend indicator could be added to prevent the system from issuing signals during a downtrend. However, this may also removes completely contrarian signals that are often very profitable. Recall that markets do not usually go straight up or down but often the are wide swings during which contrarian signals can be quite profitable. Therefore, the application of additional filters, something that must be done after the system is developed to avoid curve-fitting, may not always be the best way of handling long/short bias in the data.

You can subscribe here to notifications of new posts by email.

Disclosure: no relevant positions.
Charting program: Amibroker
Disclaimer