{"id":952,"date":"2015-01-02T05:20:33","date_gmt":"2015-01-02T10:20:33","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=952"},"modified":"2015-01-03T05:39:22","modified_gmt":"2015-01-03T10:39:22","slug":"using-optimum-parameter-values-in-backtesting","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2015\/01\/02\/using-optimum-parameter-values-in-backtesting\/","title":{"rendered":"Using optimum parameter values in backtesting"},"content":{"rendered":"

After Optimization<\/a><\/strong> process has found optimum values for parameters of our trading system, typically we want to use optimum values in subsequent backtesting or explorations. In order to achieve that, we need to manually update default_val<\/strong> (second) argument of Optimize function with the values obtained from the optimization report. <\/p>

The arguments of Optimize function are shown below (note second parameter marked in dark red color – this is the default value parameter we will be changing after optimization run):<\/p>

some_var = Optimize( \"description\", default_val<\/strong><\/font>, min_val , max_val, step );
<\/code><\/p>

Let us consider the following example formula used for optimization process:<\/p>SetOption<\/span>(<\/span>"ExtraColumnsLocation"<\/span>, <\/span>1<\/span>);
<\/span>periods <\/span>= <\/span>Optimize<\/span>( <\/span>"Periods"<\/span>, <\/span>2<\/span>, <\/span>5<\/span>, <\/span>50<\/span>, <\/span>1 <\/span>); <\/span>\/\/ note that default value is 2
<\/span>Level <\/span>= <\/span>Optimize<\/span>( <\/span>"Level"<\/span>, <\/span>2<\/span>, <\/span>2<\/span>, <\/span>150<\/span>, <\/span>4 <\/span>); <\/span>\/\/ note that default value is 2

<\/span>Buy <\/span>= <\/span>Cross<\/span>( <\/span>CCI<\/span>( <\/span>periods <\/span>), -<\/span>Level <\/span>);
<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>Level<\/span>, <\/span>CCI<\/span>( <\/span>periods <\/span>) )<\/code>

If we perform Optimization process and check the results (for this example we use Net Profit as the optimization target), we can see that the best results use Periods = 6<\/strong> and Level = 126<\/strong>. <\/p>

\"Optimization<\/p>

Now in order to run backtest and obtain exactly the same results as in the respective line of the above Optimization results, we need to enter the values into default argument, so the modified code will look like this:<\/p>SetOption<\/span>(<\/span>"ExtraColumnsLocation"<\/span>, <\/span>1<\/span>);
<\/span>periods <\/span>= <\/span>Optimize<\/span>( <\/span>"Periods"<\/span>, <\/span>6<\/span>, <\/span>5<\/span>, <\/span>50<\/span>, <\/span>1 <\/span>); <\/span>\/\/ we changed default value to 6
<\/span>Level <\/span>= <\/span>Optimize<\/span>( <\/span>"Level"<\/span>, <\/span>126<\/span>, <\/span>2<\/span>, <\/span>150<\/span>, <\/span>4 <\/span>); <\/span>\/\/ we changed default value to 126

<\/span>Buy <\/span>= <\/span>Cross<\/span>( <\/span>CCI<\/span>( <\/span>periods <\/span>), -<\/span>Level <\/span>);
<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>Level<\/span>, <\/span>CCI<\/span>( <\/span>periods <\/span>) )<\/code>

Now we can use the code with modes other than Optimization and the formula will use optimized values we retrieved from the results.<\/p>","protected":false},"excerpt":{"rendered":"

After Optimization process has found optimum values for parameters of our trading system, typically we want to use optimum values in subsequent backtesting or explorations. In order to achieve that, we need to manually update default_val (second) argument of Optimize function with the values obtained from the optimization report. The arguments of Optimize function are […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[39],"tags":[53,14,15,26],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/952"}],"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=952"}],"version-history":[{"count":2,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/952\/revisions"}],"predecessor-version":[{"id":966,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/952\/revisions\/966"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}