TASC 2017-08 | Artificial Intelligence For System Development (D’Errico & Trombetta)

Modified on 2017/07/01 06:23 by Eugene — Categorized as: TASC Traders Tips

Traders' Tip text

Since a framework that screens for all possible pattern combinations between several prices would be quite complex and lengthy for the purposes of article, we decided to confine ourselves to creating a simple system that implements just the "AI Pattern". Each elementary price rule comes with a set of numeric variables that can be optimized. Our objective is to provide a more realistic simulation of what could have been achieved with an optimized Strategy compared to the backtest results of an exhaustive optimization.


Figure 1. The entry pattern is made up of three rules and an eight-day exit. Here’s how it worked on Deutsche Bank (DBK.DE) stock from September 2016 to March 2017.

To reproduce the method described by authors Domenico D’Errico & Giovanni Trombetta, Wealth-Lab users should install or update the "Genetic Optimizer" extension and employ it with the built-in Walk-Forward Optimization tool (WFO). In broad sense, the WFO in Wealth-Lab lets traders plug in any supported optimization method, such as Monte Carlo, Genetic Algorithm and more. The common parameters of genetic algorithm (selection, crossover and mutation methods, population and generation count, and the metric to optimize for) are configurable. This way, a Walk-Forward Optimization powered by genetic algorithm find a set of optimum lookback parameters for the elementary price rules by testing an In-Sample data interval and applies them to an Out-of-sample section of data.


Figure 2. Results of an optimization of the system on DBK.DE stock data using genetic algorithm. The columns represent the optimizable parameters (entry lookback periods for the elementary price levels) as well as certain performance metrics.

Get the companion Strategy's C# code by downloading it right from Wealth-Lab's "Open Strategy" dialog.

Note: If you manaually copy/paste the code into the program, click on “References...” in the Editor and check “System.Core”.

using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using System.Linq;

namespace WealthLab.Strategies { public class TASC201708 : WealthScript { private StrategyParameter paramLookback1; private StrategyParameter paramLookback2; private StrategyParameter paramLookback21; private StrategyParameter paramLookback3; private StrategyParameter paramLookback31; private StrategyParameter paramLookback32; private StrategyParameter paramExitAfter; private StrategyParameter paramGap; public TASC201708() { paramLookback1 = CreateParameter("AP bars",1,0,4,1); paramLookback2 = CreateParameter("MP1 bars",3,0,4,1); paramLookback3 = CreateParameter("MBP1 bars",0,0,4,1); paramLookback21 = CreateParameter("MP2 bars",2,0,4,1); paramLookback31 = CreateParameter("MBP2 bars",1,0,4,1); paramLookback32 = CreateParameter("MBP3 bars",2,0,4,1); paramExitAfter = CreateParameter("Exit after",8,1,20,1); paramGap = CreateParameter("Entry gap",0.08,0.01,1.0,0.01); } protected override void Execute() { var averagePrice = (Open+Close+High+Low)/4; var medPrice = AveragePrice.Series(Bars); var medBodyPrice = (Open+Close)/2; var barsAvgPrice = paramLookback1.ValueInt; var barsMedPrice = paramLookback2.ValueInt; var barsMedPrice2 = paramLookback2.ValueInt; var barsMedBodyPrice = paramLookback3.ValueInt; var barsMedBodyPrice2 = paramLookback31.ValueInt; var barsMedBodyPrice3 = paramLookback32.ValueInt; var bars2Exit = paramExitAfter.ValueInt; int">"> lookback = new int[{barsAvgPrice,barsMedPrice,barsMedPrice2, barsMedBodyPrice,barsMedBodyPrice2,barsMedBodyPrice3}; int startBar = lookback.Max() + 1; var sfasatura = -paramGap.Value; for(int bar = GetTradingLoopStartBar(startBar); bar < Bars.Count; bar++) { if (IsLastPositionActive) { /* Exit after N days */ Position p = LastPosition; if ( bar+1 - p.EntryBar >= bars2Exit ) SellAtMarket( bar+1, p, "Timed" ); } else { /* AI Pattern Generator */ if( (averagePricebar - barsAvgPrice < medPricebar - barsMedPrice) && (medBodyPricebar - barsMedBodyPrice < medPricebar - barsMedPrice2) && (medBodyPricebar - barsMedBodyPrice2 < medBodyPricebar - barsMedBodyPrice3) ) { var entryLabel = string.Format("AP{0},MP1{1},MP2{2},MBP1{3},MBP2{4},MBP3{5}", barsAvgPrice, barsMedPrice, barsMedPrice2, barsMedBodyPrice, barsMedBodyPrice2, barsMedBodyPrice3 ); BuyAtLimit(bar+1, Lowbar + sfasatura, entryLabel); } } } } } }

Eugene (Gene Geren)
Wealth-Lab team