{"id":1075,"date":"2015-02-05T17:15:30","date_gmt":"2015-02-05T22:15:30","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=1075"},"modified":"2015-02-11T17:16:06","modified_gmt":"2015-02-11T22:16:06","slug":"using-exclude-statement-to-skip-unwanted-optimization-steps","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2015\/02\/05\/using-exclude-statement-to-skip-unwanted-optimization-steps\/","title":{"rendered":"Using Exclude statement to skip unwanted optimization steps"},"content":{"rendered":"
Sometimes when we optimize our system, we may want to use only a subset of all parameter permutations for our analysis and ignore the others that do not meet our requirements.<\/p>
For example – if we test a simple trend-following strategy, where we enter long position when short MA crosses above long MA using code such as:<\/p> Then, shortPeriods parameter value should remain smaller than longPeriods, otherwise the trading rules would work against the main principle of the tested strategy.<\/p> There is an easy way to ignore the unwanted sets of parameters by using Exclude<\/strong> statement in our code. If the variable is true – the backtester will not calculate any statistics for that particular run:<\/p> The information from Info<\/strong> tab of Analysis<\/strong> window shows the difference between first execution (all 10000 backtest runs) and second one using Exclude<\/strong> statement. Note reduced number of steps and reduced optimization time.<\/p> <\/p>","protected":false},"excerpt":{"rendered":" Sometimes when we optimize our system, we may want to use only a subset of all parameter permutations for our analysis and ignore the others that do not meet our requirements.For example – if we test a simple trend-following strategy, where we enter long position when short MA crosses above long MA using code such […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[39],"tags":[],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1075"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=1075"}],"version-history":[{"count":2,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1075\/revisions"}],"predecessor-version":[{"id":1078,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1075\/revisions\/1078"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=1075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=1075"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=1075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}shortPeriods <\/span>= <\/span>Optimize<\/span>(<\/span>"Short MA"<\/span>, <\/span>10<\/span>, <\/span>1<\/span>, <\/span>100<\/span>, <\/span>1<\/span>);
<\/span>longPeriods <\/span>= <\/span>Optimize<\/span>(<\/span>"long MA"<\/span>, <\/span>50<\/span>, <\/span>1<\/span>, <\/span>100<\/span>, <\/span>1<\/span>);
<\/span>Buy <\/span>= <\/span>Cross<\/span>( <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>shortPeriods<\/span>), <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>longPeriods<\/span>) );
<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>longPeriods<\/span>), <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>shortPeriods<\/span>) )<\/code>shortPeriods <\/span>= <\/span>Optimize<\/span>(<\/span>"Short MA"<\/span>, <\/span>10<\/span>, <\/span>1<\/span>, <\/span>100<\/span>, <\/span>1<\/span>);
<\/span>longPeriods <\/span>= <\/span>Optimize<\/span>(<\/span>"long MA"<\/span>, <\/span>50<\/span>, <\/span>1<\/span>, <\/span>100<\/span>, <\/span>1<\/span>);
<\/span>Buy <\/span>= <\/span>Cross<\/span>( <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>shortPeriods<\/span>), <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>longPeriods<\/span>) );
<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>longPeriods<\/span>), <\/span>MA<\/span>( <\/span>Close<\/span>, <\/span>shortPeriods<\/span>) );
<\/span>Exclude <\/span>= <\/span>shortPeriods <\/span>>= <\/span>longPeriods<\/span><\/code>