Trading System Development

This is the first in a series of postings describing techniques for developing reliable trading systems.  Additional posts follow in a sequence as they might be in a book. 

The Goal

There is a goal common to all traders:

To have confidence that the signals generated by the trading system precede trades that provide rewards adequate to compensate for the risk.

  • The key word is confidence.
  • The primary limitation is risk.

The Process

The process we will use closely follows the scientific method.

The scientific method consists of techniques for investigating phenomena, acquiring new knowledge, or correcting and integrating previous knowledge. It is based on measurable evidence validated by independent testing, as this flowchart, courtesy of a Wikipedia article illustrates. 

This flowchart shows the scientific method as a flowchart in a form similar to the computer programs we write.

In developing trading systems, we analyze historical price data (and possibly data from other activities).  Then create models to process that data -- make transformations and compute indicators, postulate rules, adjust parameters, generate signals, and record the resulting trades.  The process continues in cycles of adjusting, fitting, and testing the model using the in-sample training data until we are satisfied with the resulting trades.  A separate set of out-of-sample data is tested to validate that the model has learned to recognize genuine signals, and is not merely fit to the noise.

Thinking ahead, if we are successful in developing a system that has low risk and high profit potential, we plan to actually trade it.  For this, we need a separate and distinct model -- one that monitors trades, evaluates risk, adjusts position size, and estimates profit.  It tells us whether the system is working or is broken.  

Managing the trading of the system also follows the scientific method.   The data used by this model is the set of recent trades.  The output of the model is a set of two metrics. 

  •           safe-f is the maximum safe position size for the next trade. 
  •           CAR25 is the estimate of profit.

As trades are accurate and profitable, safe-f remains high and it is safe to use a large portion of the trading account.  As trades are less profitable, safe-f declines.  This indicates that the system has become riskier and position size should be reduced.

CAR25 can be used to compare alternative uses of funds.  When several systems have been developed and are being tracked, the one with the highest CAR25 is the one that should be actively traded.

The trading system that generates signals and the management system that indicates the health of the system are two distinct systems.  This flowchart combines the two shown above and shows their relationship.  

The common element between the two systems is the best estimate set of trades.  The validation phase of the development process produces a set of trades that are the best estimate of future performance of the system.  These result from applying the model (that has been fit during the iterative process of model adjustment and backtesting) to the never-used-before out-of-sample validation data.  A commonly used and excellent validation technique is the walk forward process.  We will discuss validation, including walk forward, in a future post.  The trades that are produced in each of the walk forward steps are gathered together into the best estimate set of trades.  safe-f and CAR25 are computed using these trades and are used to decide whether the system should be moved from development to trading.

When the activity moves from development to trading, the trading system model is frozen, and no further changes are made to it.  The input data for the trading system changes from historical data to real-time data, signals are identified, and trades generated.  Conservative traders will wait for the system to generate several trades before beginning to trade with real money.  These trades are called shadow trades.  They are added to the best estimate set and used to monitor system performance.  Throughout the life of a trading system, all of its trades -- whether taken with real money or as shadow trades -- are added to the best estimate set of trades and are used to compute safe-f and CAR25.  As the flowchart shows, when performance deteriorates, the trading system is taken offline and perhaps sent back to development.    

During the development process, we want a sound model that analyzes data and produces signals.  Described broadly, success of the trading system depends on the quality of the model and its fit to the data.  Quality has several aspects that affect its usefulness, including:

  • Accuracy
  • Profitability
  • Risk
  • Reliability
  • Practicality

Our next posting will discuss trade quality.

Why use AmiBroker?

No matter which platform I chose, some people would be disappointed.  Some would prefer an English language description.  Some an artificial pseudo-langauge.  Some the language of only their favorite platform.  Some several of the most widely used languages.

One of the reasons I am publishing is to give system developers an alternative to imprecise trading advice, unrealistic promises, financial astrology, and smoke and mirrors.  The examples must be coded in the language of one of the popular trading system development platforms.  Readers must be able to replicate my results and use the examples as templates for further development and testing on their own.  I chose AmiBroker because:

  1. It is capable of performing everything I wanted to do (I do not know of another reasonably priced platform that can).
  2. It is free to try and inexpensive to buy.  The trial version can do everything I describe in the free Introduction to AmiBroker book.
  3. It has a very clear and concise language that should be easily understood by anyone who is reasonably comfortable programming in a modern computer language or for a different trading system platform.

You can get an idea of AmiBroker’s language:

  • From the sample chapters of my books (see the Books page of this website).
  • Every month, the trader’s journal Technical Analysis of Stocks and Commodities publishes the code corresponding to one of their articles for a dozen of the most popular trading system development platforms.  The AmiBroker code is usually the shortest, clearest, and easiest to understand.

For those people who are not already familiar with AmiBroker and who want to test the techniques I describe:

  1. Download the free trial version of AmiBroker from the AmiBroker website.
  2. Download and read the free Introduction to AmiBroker from that book’s website. It has complete instructions for installation, setting up databases, and using the platform in both charting mode and analysis mode.
  3. Paste in some of the AmiBroker code I provide and try it out.  For example, try this mean reversion system based on RSI.  It is reasonably stationary over a long period of time and works on many broad market and sector ETFs.  (It is for demonstration only, and is Not trading advice


// System settings
OptimizerSetEngine( "cmae" );
SetOption( "Initialequity", 100000 );
MaxPos = 1;
SetOption( "MaxOpenPositions", MaxPos );
SetPositionSize( 10000, spsValue );
SetOption( "CommissionMode", 3 ); // $ per share
SetOption( "CommissionAmount", 0.005 );
SetOption( "ExtraColumnsLocation", 1 );
SetTradeDelays( 0, 0, 0, 0 );
BuyPrice = Close;
SellPrice = Close;

// Parameters
// Good values have been: 2, 37, 5
RSILookback = Optimize( "RSILookback", 2, 2, 10, 1 );
EntryLevel = Optimize( "EntryLevel", 37, 1, 99, 1 );
ExitIncrement = Optimize( "ExitIncrement", 5, 1, 99, 1 );

// Indicator
RSIValue = RSIa( C, RSILookback );

// Rules

// Buy when RSI falls through a critical level
Buy = Cross( EntryLevel, RSIValue );

// Sell when RSI rises
ExitLevel = EntryLevel + ExitIncrement;
Sell = Cross( RSIValue, ExitLevel );

// end //

AmiBroker is used extensively in the Quantitative Trading Systems book and the Mean Reversion book. The code for both those books is available for download, copy, and paste. Whichever platform you decide to use, please use sound modeling and simulation techniques to give realistic estimates of future performance of your system. Use the risk-normalization procedures fully explained in Modeling Trading System Performance to compare alternative uses of your funds.


Blue Owl Press website is being revised

We are in the process of renovating our website. 

The pages for Postings will have a series of entries outlining trading system development using the scientific method.  Several entries have been posted, and more will be added.  The trading system development postings are at the beginning of the list and are in order by recommended reading sequence. 

The pages for Videos are complete.

The pages for Books, including the downloadable material, are complete.  

The pages for Papers has a few entries, and more will be added.

The pages for Resources are very new.  The entries that will appear on these pages will include extensive reference material -- books, videos, courses, articles.