Archive

Archive for the ‘Educational Articles’ Category

Countertrend / Trend Following SP Trading System

August 4th, 2010 No comments

This article features a trading system for the ES/SP futures that opens trading positions counter to the short term trend when the long term trend is also counter to the short term trend. Long positions are closed when the price exceeds a shorter term simple moving average and vice versa.

The trading system was built using BioComp Dakota to enable walk-forward adaptation of the system parameter values. The system was run using daily reverse adjusted SP futures data, provided by Pinnacle Data Corp., from Jan 1994. No trading signals were generated until Jan 1995 because the performance engine requires approximately one year of data before outputting trading signals.

The screen images that follow show the Dakota system settings that were used.

Dakota Bots and Swarm Settings

Dakota Bots and Swarm Settings

A description for each of the key trading system parameters follows:

  • The Min Values Above/Below Last ranges from 4 to 9 trading days. For a long signal to be generated the n prior closes for the SP contract must be above the last close and vice versa. i.e. the market must be at a short term new low to go long or a short term new high to go short.
  • The MA Trend Period ranges from 100 to 300 trading days and the Trend Threshold ranges from 0% to 5%. For a long position to be generated, the last close of the SP contract is required to be above the SMA or the last close is required to be within the threshold percentage of the SMA and vice versa. i.e. If the last close is within +-x% of the SMA then both long and short positions can potentially be output.
  • The MA Exit Period ranges from 2 to 12 trading days. If the trading system is long and the last close exceeds the SMA then the position is closed and vice versa.
Dakota Equity Management Settings

Dakota Equity Management Settings

The Proportion of Perfect while In Position (PPIP) Equity Engine is selected and a 250 trading day Performance Lookback period has been set. The Trading Delay is set to 1 trading day. i.e. The system trades on the close of the trading day that follows the trading day that has just been processed. No commission or slippage was used. i.e. Results are frictionless.

The screen images that follow show the hypothetical trading results of running the system.

Dakota Price, Signal and Equity Charts

Dakota Price, Signal and Equity Charts

There are some prolonged flat periods in the equity curve and the system didn’t manage to capture some of the very significant declines. These criticisms aside, overall the equity curve is quite consistent and sure beats buy and hold.

Dakota Trades Report

Dakota Trades Report

The average trade period is 3.4 trading days, percent time in position is 31.4%, percent winning trades is 63% and the average winner is about equal to the average loser. If this trading signal was actually traded, versus contributing to a meta-system, then slippage and commission would have to be minimized. Given that the system signal is applied on the close of the next trading day, minimizing slippage is not difficult. Hopefully this article has given others some ideas to work with.

Regards,

James

Categories: Educational Articles Tags:

Adaptive CPredictor Trading System

July 31st, 2010 No comments

Introduction

This article presents an example trading system constructed by running the CPredictor in BioComp Dakota. Dakota enables the creation of adaptive trading systems with 100% walk-forward out-of-sample performance evaluation. The CPredictor algorithm is basically a pattern matching algorithm. For more information on the CPredictor please read a High Level Description of the CPredictor3D Algorithm. The purpose of the CPredictor is to predict the short term trend of a given time series. An example, would be predicting the trend of an indicator such as the stochastic oscillator. The cool thing about running a CPredictor system in Dakota is that the key parameters of the CPredictor algorithm are adapted walking-forward bar by bar. The simulated trading system performance is, therefore, more likely to resemble performance after the system construction date.

For this example, the target series to be predicted is the short term trend of a seven  period CooksP oscillator applied to the SP reverse adjusted daily data series and smoothed with a three period EMA. An educated guess was used to determine these parameters. No optimization was done. Ideally, analysis would be completed to develop or find a target series with a  short term trend that has served as an effective target for the entire history of the traded series. An alternative is to adapt the parameters of the target series in addition to the parameters of the CPredictor algorithm. However, this is asking a lot more of the swarm adaptation algorithm that is responsible for determining all adapted parameter values walking-forward bar by bar.

Trading System Details

The BioComp Dakota system settings are presented in a series of screen images with descriptions.

Dakota System Settings

Dakota System Settings

Reverse adjusted data for the SP contract supplied by Pinnacle Data Corp is selected as the traded series. Data from January 1st 1987 is loaded. By default, the two thousand bars prior to the bar that is being processed are required by the CPredictor to produce the trend prediction. Therefore, no trading signal will be output until January 1995. This system trades on the close of the day session. The trading signals actually apply to the trading day following that being processed. This allows for ample time to update the data and system.

Dakota Bots and Swarm Settings

Dakota Bots and Swarm Settings

The CooksP-Ema-CPredictor3D scriptbot has been selected on the Dakota Bots and Swarm Settings tab. The CooksP Period is set to 7 and the EMA Period is set to 3. This defines the target series. The ranges for the three dimensions of the CPredictor3D algorithm are 1 to 10, 5 to 15 and 10 to 25 respectively. The Depth parameter is not visible in the screen image. The Depth is another adapted CPredictor parameter that can vary between 3 to 9 bars. These are the default ranges for the CPredictor3D parameters that are adapted walking-forward.

A total of one hundred and fifty trade bots make up the swarm. Seventy five of these trade bots are assigned to the ghost swarm. Ghost trade bots do not produce trading signals. Ghost trade bots are fixed in place within the adapted parameter / performance space and provide performance statistics for the flocking swarms that do produce trading signals. Please read the High Level Description of the ATS Swarm Adaptation Library 3.00 for more information.

Dakota Equity Management Settings

Dakota Equity Management Settings

The selected Equity (performance) Engine calculates the proportion of perfect trading while in position over the Performance Lookback period of 250 trading days. ‘Perfect trading’ is the profit that would have been made if the system had traded perfectly from close to close. The Value per Point is set to 1. This could have been set to $250 for the SP contract or $50 for the ES contract. No commissions or slippage were used. i.e. This is a frictionless trading simulation.

The signal that is generated today applies to the close of the market on the next trading day. The system trades both long and short and the trading signal is calculated by averaging the signals generated by the trade bots in the swarm.

Trading Simulation Results

The screen images that follow show the results of the trading simulation.

Dakota Price, Trading Signal and Equity Charts

Dakota Price, Trading Signal and Equity Charts

The resulting equity curve is not very smooth. However, it is definitely biased toward the upside and tends to make new highs on a regular basis. This particular CPredictor system does not represent the best that can be produced, nor is it the worst!

Dakota Trades Report

Dakota Trades Report

The system performed at 6.7% of perfect while in position. It is worth remembering that these statistics were produced by a system that’s key parameters were determined on a walk-forward basis. For a ‘trading system’, that trades as frequently as this one, to make the cut and be included in an ensemble of trading systems that combine to generate a production trading signal I would require approximately 8% of perfect or greater. It’s not far off the mark.

Regards,

James

Categories: Educational Articles Tags:

High Level Description of the CPredictor3D Algorithm

July 27th, 2010 No comments

This article describes the CPredictor3D algorithm. The CPredictor is designed to predict the short term trend of a given time series. The time series to predict can be market price data or transformed price data (oscillators etc.). The CPredictor functions best when predicting oscillating time series because the complexity of the data series is significantly less than the complexity of a ‘raw’ market price series. The longer and sometimes very persistent trends in market price data can cause unwanted bias. It is advisable to detrend the market price data so that it is, at a minimum, weakly stationary.

The CPredictor is based on the k-nearest neighbor algorithm. You can think of the CPredictor as a pattern matching algorithm. The CPredictor3D is an implementation of the CPredictor that constructs the state space using three dimensions. Each of the three dimensions is calculated by subtracting the value of the given time series N periods ago from the most recent value. N will usually be a different time period for each dimension.

For example,

  • Given the time series TS {-0.91,-0.80,-0.82,-0.75,-0.77,-0.54,-0.22,0.10,0.05,0.07,0.44,0.58,0.33}, where 0.33 is the most recent value and Dimension 1 (D1) period = 2, D2 Period = 5 and the D3 period = 9.
  • Value at Dimension 1 = TS(t) – TS(t-2) = 0.33 – 0.44 = -0.11
  • Value at Dimension 2 = TS(t) – TS(t-5) = 0.33 – 0.10 = 0.23
  • Value at Dimension 3 = TS(t) – TS(t-9) = 0.33 – -0.75 = 1.08

Imagine the three values associated with each dimension plotted on a xyz graph. When a new value is added to the time series the values associated with each dimension are recalculated and plotted. The xyz graph is a representation of the phase space or state space. The ‘state’ at any time period (bar number) is defined by the coordinates of the corresponding point within the state space.

The path through the state space is obtained by moving from point to point in the same order as the values in the time series i.e. chronological order. If you google state space or phase space you will find plenty of example diagrams. To determine when the ‘system’ was in a similar state to any selected point, find other points that are in relatively close proximity.

Points that are in close proximity are called nearest neighbors. Each point in the state space maps to a time period or bar number in the time series. The last point in the path is always the point of interest because the prediction will be built from this point forward. We are not interested in points that immediately preceded the last point in a chronological sense, because these points will not be useful for the prediction.

For example,

  • Three points have been identified that are in close proximity to the last point within the state space.
  • The nearest neighbors occur at (t-155), (t-329) and (t-523) i.e. 155, 329 and 523 time periods back from the last point.
  • The corresponding time periods are identified in the time series. i.e. TS(t-155), TS(t-329) and TS(t-523).

The pattern matching exercise is now complete. The next step is to generate the prediction of the direction of the trend for the time series. To predict the direction of the trend from the last time period (t)  to  (t+n) calculate the equivalent deltas for each nearest neighbor in the time series and average them.

For example,

  • Calculate the deltas for the nearest neighbors. Delta 1 = TS(t-153) – TS(t-155), Delta 2 = TS(t -327) – TS(t-329), Delta 3 = TS(t-521) – TS(t-523).
  • Average the deltas. Average delta = (Delta 1 + Delta 2 + Delta 3) / 3.
  • If the average delta is positive then the trend from TS(t) to TS(t+1) is predicted to be advancing and vice versa.

Averaging the deltas in the time series that occur after the nearest neighbors isn’t the only approach to predicting the direction of the trend. A majority vote would be an example of another approach. Averaging the deltas is appropriate when the time series is stationary.

Regards,

James

Categories: Educational Articles Tags: