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

1 Star2 Stars3 Stars4 Stars5 Stars (8 votes, average: 4.75 out of 5)
Loading...Loading...

4 Responses to “IO – More Advanced Problems”

  1. Herman
    August 14th, 2007 | 10:29 am

    This is a very nice application! I haven’t run this example yet however this capability definitely is a reason for me to install IO. I have tried this in many other ways and never managed to get it working well. A few questions:

    1) Is there a limit to the number of IO Optimize statements that can be used (>10)?

    2) Can this be integrated with the Walk-Forward procedure (I want to dynamically switch trading systems)?

    3) Is there a way to schedule the combined Optimize/WF operation (for overnight running)?

  2. Fred
    August 14th, 2007 | 11:56 am

    1) I think it has an internal limit of 999.

    2) All parts of IO are fully integrated with each other and with AmiBroker.

    3) Schedule ? … IO has no internal scheduler per se although it can be run by batch and batch jobs can of course be scheduled … BatMan can also be used to run IO although this is to some degree overkill …

  3. August 14th, 2007 | 4:48 pm

    Fred
    In the example afl above, I think you have a mistake. Your afl has the following:
    //IO: EndOSDate: 01/31/2004
    //IO: LastOSDate: 01/31/2004

    Shouldn’t it be:
    //IO: EndISDate: 01/31/2004
    //IO: LastOSDate: 08/13/2007

    Thanks for the IO additions to the KB
    Larry

  4. Fred
    August 20th, 2007 | 8:02 pm

    It’s not a matter of right or wrong …

    Current date is the default for LastOSDate.
    In this case I didn’t want any OOS Testing so I set LastOSDate to be the same as EndISDate.