IO – More Advanced Problems

This page is obsolete. Current versions of AmiBroker feature built-in non-exhaustive, smart multithreaded optimizer and walk-forward engine.

One type of more advanced problem that is easily addressed with Intelligent Optimization is that of System Generation by use of rule creation, selection and combination.

What we’ll do in this simple example is to write a variety of loose rules for both the entry and exit side of a long only intermediate term system and let intelligent optimization find the rules that work best together for entries and exits.

The general indicators we’ll use are a MACD, Stochastic, RSI & ROC each of which will be considered to be either on a buy or on a sell by using 3 length parameters each.  In addition we’ll attach optimizable factors with values of 0 or 1 to the entry and exit side of each of these subsystems that allows them to either be used or ignored and we’ll use optimizable thresholds for the number of subsystems to be on a buy or on a sell to drive when entries and exits take place.

Below is the AFL to accomplish the task … The values in the default values of each of the optimization statements are what IO put there as a result of the run that took place.

//IO: Fitness:    CAR - MDD
//IO: Goal:       Trades: >: 4
//IO: Goal:       Trades: <: 12

//IO: BegISDate:  12/20/2000
//IO: EndOSDate:  01/31/2004
//IO: LastOSDate: 01/31/2004

M1Len      Optimize("M1Len",          52,     1,   100,     1);
M2Len      Optimize("M2Len",          40,     1,   100,     1);
M3Len      Optimize("M3Len",          48,     1,   100,     1);
MBB        Optimize("MBB",             1,     0,     1,     1);
MSS        Optimize("MSS",             1,     0,     1,     1);

M1 AMA(C/ (M1Len 1));
M2 AMA(C/ (M2Len 1));
M3 M1 M2;
M4 AMA(M3/ (M3Len 1));
MB M3 &gtM4;
MS M3 &ltM4;

//Plot(M3, "M3", colorRed);
//Plot(M4, "M4", colorWhite);

S1Len      Optimize("S1Len",          44,     1,   100,     1);
S2Len      Optimize("S2Len",          55,     1,   100,     1);
S3Len      Optimize("S3Len",          58,     1,   100,     1);
SBB        Optimize("SBB",             0,     0,     1,     1);
SSS        Optimize("SSS",             1,     0,     1,     1);

S1H HHV(CS1Len);
S1L LLV(CS1Len);
S1  = (S1L) / (S1H S1L);
S2  AMA(S1/ (S2Len 1));
S3  AMA(S2/ (S3Len 1));
SB  S2 &gtS3;
SS  S2 &ltS3;

//Plot(S2, "S2", colorRed);
//Plot(S3, "S3", colorWhite);

R1Len      Optimize("R1Len",          74,     1,   100,     1);
R2Len      Optimize("R2Len",          72,     1,   100,     1);
R3Len      Optimize("R3Len",          48,     1,   100,     1);
RBB        Optimize("RBB",             0,     0,     1,     1);
RSS        Optimize("RSS",             1,     0,     1,     1);

R1  RSIa(CR1Len);
R2  AMA(R1/ (R2Len 1));
R3  AMA(R2/ (R3Len 1));
RB  R2 &gtR3;
RS  R2 &ltR3;

//Plot(R2, "R2", colorRed);
//Plot(R3, "R3", colorWhite);

C1Len      Optimize("C1Len",          17,     1,   100,     1);
C2Len      Optimize("C2Len",          50,     1,   100,     1);
C3Len      Optimize("C3Len",          16,     1,   100,     1);
CBB        Optimize("CBB",             1,     0,     1,     1);
CSS        Optimize("CSS",             1,     0,     1,     1);

C1 ROC(CC1Len);
C2 AMA(C1/ (C2Len 1));
C3 AMA(C2/ (C3Len 1));
CB C2 &gtC3;
CS C2 &ltC3;

//Plot(C2, "C2", colorRed);
//Plot(C3, "C3", colorWhite);

BTot       Optimize("BTot",            2,     1,     4,     1);
STot       Optimize("STot",            3,     1,     4,     1);

Buy  MB MBB SB SBB RB RBB CB CBB >= BTot;
Sell MS MSS SS SSS RS RSS CS CSS >= STot;

You’ll notice a couple of comments at the top of the AFL.  These are IO Directives and always take this form so as to never interfere with the normal operation of AFL in AmiBroker.  What they do is almost self explanatory but I won’t go into explaining their specific function here as all Directives are throughly described in the full documentation. 

The other thing that could be noticed about the AFL is that it could not be processed by AmiBroker’s optimizer directly because the number of optimization statements would result in an error.  Even if the AFL could be run through the Exhaustive Search optimizer in AmiBroker it’s not likely that the problem would be solved before the Sun turned into a red giant and engulfed the earth as there are 4 * 10 ^ 27 combinations of parameter values.  IO however, has no such limitations in terms of optimization statements and will handle the the passing of parameter values to AmiBroker to be tested.

As can be seen from the summary below, IO tested a little more than 33000 combinations and took a little less than 15 minutes to come up with a solution to the problem.

io-summary.png

 The results of that run are shown graphically below …
io-sys-gen.png

This is not exactly what I’d call stellar results but this was not intended to be a viable system.  It was only intended to demonstrate a different more generic type of problem that IO and AmiBroker can together solve. 

A shareware version of IO with full documentation can be found in the AmiBroker Files Section …
 http://groups.yahoo.com/group/amibroker/files/IO.zipp

Comments are closed.