{"id":947,"date":"2007-08-13T05:06:57","date_gmt":"2007-08-13T05:06:57","guid":{"rendered":"http:\/\/www.amibroker.org\/userkb\/2007\/08\/13\/g-io-more-advanced-problems\/"},"modified":"2012-08-17T11:05:55","modified_gmt":"2012-08-17T11:05:55","slug":"g-io-more-advanced-problems","status":"publish","type":"post","link":"http:\/\/www.amibroker.org\/editable_userkb\/2007\/08\/13\/g-io-more-advanced-problems\/","title":{"rendered":"IO – More Advanced Problems"},"content":{"rendered":"

This page is obsolete. Current versions of AmiBroker feature built-in non-exhaustive, smart multithreaded optimizer and walk-forward engine.<\/font><\/b><\/p>\n

<\/a>One type of more advanced problem that is easily addressed with Intelligent Optimization is\u00a0that of\u00a0System Generation by use of rule creation, selection and combination.<\/p>\n

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

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.\u00a0 In addition we’ll attach optimizable factors with values of 0 or 1 to the entry and exit side of each of these subsystems\u00a0that allows them to either be used or ignored\u00a0and we’ll use optimizable thresholds for the number of subsystems\u00a0to be on a buy or on a sell to drive when entries and exits take place.<\/p>\n

Below is the\u00a0AFL to accomplish the task … The values in the default values\u00a0of each of the optimization statements are what IO <\/em>put there as a result of the run that took place.<\/p>\n

<\/span>\/\/IO: Fitness:\u00a0\u00a0\u00a0 CAR - MDD\r\/\/IO: Goal:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Trades: &gt;: 4\r\/\/IO: Goal:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Trades: &lt;: 12\r\r\/\/IO: BegISDate:\u00a0 12\/20\/2000\r\/\/IO: EndOSDate:\u00a0 01\/31\/2004\r\/\/IO: LastOSDate: 01\/31\/2004\r\r<\/span>M1Len\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"M1Len"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 52<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0 100<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>M2Len\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"M2Len"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 40<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0 100<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>M3Len\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"M3Len"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 48<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0 100<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>MBB\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"MBB"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 0<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>MSS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"MSS"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 0<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r\r<\/span>M1 <\/span>= <\/span>AMA<\/span>(<\/span>C<\/span>, <\/span>2 <\/span>\/ (<\/span>M1Len <\/span>+ <\/span>1<\/span>));\r<\/span>M2 <\/span>= <\/span>AMA<\/span>(<\/span>C<\/span>, <\/span>2 <\/span>\/ (<\/span>M2Len <\/span>+ <\/span>1<\/span>));\r<\/span>M3 <\/span>= <\/span>M1 <\/span>- <\/span>M2<\/span>;\r<\/span>M4 <\/span>= <\/span>AMA<\/span>(<\/span>M3<\/span>, <\/span>2 <\/span>\/ (<\/span>M3Len <\/span>+ <\/span>1<\/span>));\r<\/span>MB <\/span>= <\/span>M3 <\/span>&<\/span>gt<\/span>; <\/span>M4<\/span>;\r<\/span>MS <\/span>= <\/span>M3 <\/span>&<\/span>lt<\/span>; <\/span>M4<\/span>;\r\r<\/span>\/\/Plot(M3, \"M3\", colorRed);\r\/\/Plot(M4, \"M4\", colorWhite);\r\r<\/span>S1Len\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"S1Len"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 44<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0 100<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>S2Len\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"S2Len"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 55<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0 100<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>S3Len\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"S3Len"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 58<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0 100<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>SBB\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"SBB"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 0<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>SSS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"SSS"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 0<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r\r<\/span>S1H <\/span>= <\/span>HHV<\/span>(<\/span>C<\/span>, <\/span>S1Len<\/span>);\r<\/span>S1L <\/span>= <\/span>LLV<\/span>(<\/span>C<\/span>, <\/span>S1Len<\/span>);\r<\/span>S1\u00a0 <\/span>= (<\/span>C <\/span>- <\/span>S1L<\/span>) \/ (<\/span>S1H <\/span>- <\/span>S1L<\/span>);\r<\/span>S2\u00a0 <\/span>= <\/span>AMA<\/span>(<\/span>S1<\/span>, <\/span>2 <\/span>\/ (<\/span>S2Len <\/span>+ <\/span>1<\/span>));\r<\/span>S3\u00a0 <\/span>= <\/span>AMA<\/span>(<\/span>S2<\/span>, <\/span>2 <\/span>\/ (<\/span>S3Len <\/span>+ <\/span>1<\/span>));\r<\/span>SB\u00a0 <\/span>= <\/span>S2 <\/span>&<\/span>gt<\/span>; <\/span>S3<\/span>;\r<\/span>SS\u00a0 <\/span>= <\/span>S2 <\/span>&<\/span>lt<\/span>; <\/span>S3<\/span>;\r\r<\/span>\/\/Plot(S2, \"S2\", colorRed);\r\/\/Plot(S3, \"S3\", colorWhite);\r\r<\/span>R1Len\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"R1Len"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 74<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0 100<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>R2Len\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"R2Len"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 72<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0 100<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>R3Len\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"R3Len"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 48<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0 100<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>RBB\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"RBB"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 0<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>RSS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"RSS"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 0<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r\r<\/span>R1\u00a0 <\/span>= <\/span>RSIa<\/span>(<\/span>C<\/span>, <\/span>R1Len<\/span>);\r<\/span>R2\u00a0 <\/span>= <\/span>AMA<\/span>(<\/span>R1<\/span>, <\/span>2 <\/span>\/ (<\/span>R2Len <\/span>+ <\/span>1<\/span>));\r<\/span>R3\u00a0 <\/span>= <\/span>AMA<\/span>(<\/span>R2<\/span>, <\/span>2 <\/span>\/ (<\/span>R3Len <\/span>+ <\/span>1<\/span>));\r<\/span>RB\u00a0 <\/span>= <\/span>R2 <\/span>&<\/span>gt<\/span>; <\/span>R3<\/span>;\r<\/span>RS\u00a0 <\/span>= <\/span>R2 <\/span>&<\/span>lt<\/span>; <\/span>R3<\/span>;\r\r<\/span>\/\/Plot(R2, \"R2\", colorRed);\r\/\/Plot(R3, \"R3\", colorWhite);\r\r<\/span>C1Len\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"C1Len"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 17<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0 100<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>C2Len\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"C2Len"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 50<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0 100<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>C3Len\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"C3Len"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 16<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0 100<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>CBB\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"CBB"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 0<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>CSS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"CSS"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 0<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r\r<\/span>C1 <\/span>= <\/span>ROC<\/span>(<\/span>C<\/span>, <\/span>C1Len<\/span>);\r<\/span>C2 <\/span>= <\/span>AMA<\/span>(<\/span>C1<\/span>, <\/span>2 <\/span>\/ (<\/span>C2Len <\/span>+ <\/span>1<\/span>));\r<\/span>C3 <\/span>= <\/span>AMA<\/span>(<\/span>C2<\/span>, <\/span>2 <\/span>\/ (<\/span>C3Len <\/span>+ <\/span>1<\/span>));\r<\/span>CB <\/span>= <\/span>C2 <\/span>&<\/span>gt<\/span>; <\/span>C3<\/span>;\r<\/span>CS <\/span>= <\/span>C2 <\/span>&<\/span>lt<\/span>; <\/span>C3<\/span>;\r\r<\/span>\/\/Plot(C2, \"C2\", colorRed);\r\/\/Plot(C3, \"C3\", colorWhite);\r\r<\/span>BTot\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"BTot"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 4<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r<\/span>STot\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span>= <\/span>Optimize<\/span>(<\/span>"STot"<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 3<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 4<\/span>,<\/span>\u00a0\u00a0\u00a0\u00a0 1<\/span>);\r\r<\/span>Buy\u00a0 <\/span>= <\/span>MB <\/span>* <\/span>MBB <\/span>+ <\/span>SB <\/span>* <\/span>SBB <\/span>+ <\/span>RB <\/span>* <\/span>RBB <\/span>+ <\/span>CB <\/span>* <\/span>CBB <\/span>&<\/span>gt<\/span>;= <\/span>BTot<\/span>;\r<\/span>Sell <\/span>= <\/span>MS <\/span>* <\/span>MSS <\/span>+ <\/span>SS <\/span>* <\/span>SSS <\/span>+ <\/span>RS <\/span>* <\/span>RSS <\/span>+ <\/span>CS <\/span>* <\/span>CSS <\/span>&<\/span>gt<\/span>;= <\/span>STot<\/span>;<\/span><\/pre>\n

You’ll notice\u00a0a couple of comments at the top of the AFL.\u00a0 These are IO Directives and always take this form\u00a0so as to\u00a0never interfere with the normal operation of AFL in AmiBroker.\u00a0 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.\u00a0<\/p>\n

The other\u00a0thing that could be noticed about the\u00a0AFL is that it could not be processed by AmiBroker’s optimizer directly because the number of optimization statements would result in an error.\u00a0 Even if the AFL could be run through the Exhaustive Search\u00a0optimizer 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\u00a0there\u00a0are 4 * 10 ^ 27 combinations of parameter values.\u00a0 IO<\/em> however, has no such limitations in terms of optimization statements and will handle the the passing of parameter values to\u00a0AmiBroker to be tested.<\/p>\n

As can be seen from the summary below, IO<\/em> tested a little more than 33000 combinations\u00a0and took a little less than 15 minutes to come up with a solution to the problem.<\/p>\n

\u00a0The results of that run are shown graphically below …
\n
\"io-sys-gen.png\"<\/a><\/p>\n

This is not exactly what I’d call stellar results but this\u00a0was not intended to be a viable system.\u00a0 It was only intended to demonstrate a different more generic type of problem that\u00a0IO<\/em> and AmiBroker can together solve.\u00a0<\/p>\n

A\u00a0shareware version of IO<\/em> with full documentation can be found in the AmiBroker Files Section \u2026
\n\u00a0
http:\/\/groups.yahoo.com\/group\/amibroker\/files\/IO.zip<\/a>p<\/p>\n","protected":false},"excerpt":{"rendered":"

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\u00a0that of\u00a0System Generation by use of rule creation, selection and combination. What we’ll do in this simple example is to write a variety of loose […]<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[115],"tags":[],"_links":{"self":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/947"}],"collection":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/comments?post=947"}],"version-history":[{"count":4,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/947\/revisions"}],"predecessor-version":[{"id":3500,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/947\/revisions\/3500"}],"wp:attachment":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/media?parent=947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/categories?post=947"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/tags?post=947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}

\"io-summary.png\"<\/a><\/p>\n