04_Amibroker_ How To Optimize A Trading System Automatically

Amibroker is probably one of the best “bang for your buck” charting packages available.  Apart from the back-testing capabilities allowing you to easily back-test a stock or portfolio of stocks, it has another amazing feature that saves you time and you are absolutely going to love.

Amibroker 可能是最好的“物超所值”图表软件包之一。 除了回测功能允许您轻松回测股票或股票投资组合之外,它还有另一个令人惊叹的功能,可以节省您的时间,您绝对会喜欢的。

That feature is optimization.

该功能就是优化。

 

 

What Is Optimizing A Trading System In Amibroker?

什么是优化 Amibroker 中的交易系统?

Optimizing a trading system in Amibroker allows us to back-test our chosen stock, or group of stocks to see if our method works.  But further to this, in Optimizing our trading system we automatically get performance data on a large range of different parameters so we can choose the best combination of rules to use.  This optimizing process often takes only a few minutes.

优化 Amibroker 中的交易系统使我们能够回测我们选择的股票或一组股票,看看我们的方法是否有效。 但除此之外,在优化我们的交易系统时,我们会自动获取大量不同参数的性能数据,以便我们可以选择要使用的最佳规则组合。 这个优化过程通常只需要几分钟。

 

For example:

例如:

Let’s say we are using a simple Moving Average crossover system, where we buy when the 25 Day Moving Average crosses above the 100 Day Moving Average.

假设我们使用一个简单的移动平均线交叉系统,当 25 天移动平均线穿过 100 天移动平均线时我们买入。

 

 

We back-test out results, and the results are OK.  Nothing stellar.

我们回测结果,结果没问题。 没什么明星的。

 

But then we use a simple “Optimize” command, we can also test the Moving Averages between 0 and 200 to see which Moving Average works best.  The results are finished within minutes, and we can instantly see that there is a better Moving Average combination we could be using.

但随后我们使用一个简单的“优化”命令,我们还可以测试 0 到 200 之间的移动平均线,看看哪个移动平均线效果最好。 结果在几分钟内就完成了,我们可以立即看到我们可以使用更好的移动平均线组合。

 

How To Optimize A Trading System In Amibroker Using Amibroker AFL

如何使用 Amibroker AFL 优化 Amibroker 中的交易系统

So let’s get to it.  First, as always, we need a little bit of Amibroker AFL code to get us started.

那么让我们开始吧。 首先,一如既往,我们需要一点 Amibroker AFL 代码来帮助我们开始。

  • From the main screen of Amibroker, go to Analysis > Formula Editor.

从 Amibroker 的主屏幕,转至分析 > 公式编辑器。

  • Enter the following code into the formula editor:

在公式编辑器中输入以下代码:

FastMALength = Optimize( “FMA”, 100, 5, 100, 1);

SlowMALength = Optimize( “SMA”, 25, 1, 100, 1);

FastMA = MA(C, FastMALength );

SlowMA = MA(C, SlowMALength );

Buy = Cross(FastMA, SlowMA);

Sell = Cross(SlowMA, FastMA);

 

  • If it doesn’t copy and paste correctly, you may need to type it out into Amibroker, the code definitely works.

如果无法正确复制和粘贴,您可能需要将其输入到 Amibroker 中,该代码绝对有效。

  • The Amibroker Formula Language quickly explained: The first section sets up our Optimize rules.  It tells Amibroker that our Array word “FastMALength”, when we use it, will equal our Optimization that follows.  Then with “Optimize”, it first gives it a name (for the output table in our results), then our preferred value (100), our minimum value (5), maximum value (100) and the increments we go up by with each new test (1).  You can change these number to suit you, and the Optimize function, once assigned to an ARRAY (like our FastMALength example), can be used with many different tools.

Amibroker 公式语言快速解释:第一部分设置我们的优化规则。 它告诉 Amibroker,当我们使用它时,我们的数组单词“FastMALength”将等于我们接下来的优化。 然后使用“优化”,它首先给它一个名称(用于我们结果中的输出表),然后是我们的首选值(100)、最小值(5)、最大值(100)以及我们增加的增量 每个新测试 (1)。 您可以更改这些数字以适合您,并且优化功能一旦分配给 ARRAY(如我们的 FastMALength 示例),就可以与许多不同的工具一起使用。

You can save it if you like, then click Tools > Send To Auto Analysis.

如果愿意,您可以保存它,然后单击“工具”>“发送到自动分析”。

The Automatic Analysis window appears.  Now we work from left to right before we ultimately press the Optimize button.

出现自动分析窗口。 现在我们从左到右工作,然后最终按下“优化”按钮。

  • Under “Apply To”, select either “Use Filter” and choose the watchlist you want to test, or “current stock” if you want to test the stock you are currently viewing

在“应用到”下,选择“使用过滤器”并选择您要测试的监视列表,或者如果您想测试当前正在查看的股票,则选择“当前股票”

  • Under “Range”, select “From” and choose the date ranges you want to test

在“范围”下,选择“从”并选择要测试的日期范围

  • Then click settings, choose “Periodicity” > Daily (or Weekly if you prefer trading on a weekly timeframe), and under the report tab, select “Trade List”

然后单击设置,选择“周期性”>“每日”(如果您喜欢在每周时间范围内进行交易,则选择“每周”),然后在报告选项卡下选择“交易列表”

  • Click OK

单击“确定”

  • Then click on the arrow next to Optimize, ensure it is set to Optimize Portfolio, then click Optimize!

然后单击“优化”旁边的箭头,确保将其设置为“优化投资组合”,然后单击“优化”!

Viewing Your Optimization Results

查看您的优化结果

Once the system has finished optimizing, it will display a series of results for you to sort through.  You will see things like CAR (Compound Annual Return), Maximum trade or system drawdown (losing streaks), Win Percentage, total trades, average profit and average loss and much more.

系统完成优化后,会显示一系列结果供您排序。 您将看到诸如 CAR(复合年回报率)、最大交易或系统回撤(连续亏损)、获胜百分比、总交易、平均利润和平均损失等信息。

 

One of the most common methods of judging a trading system is the CAR / MDD.  This is the Compound Annual Return divided by the Maximum Drawdown, and basically helps us pick the system with the highest annual return versus the maximum drawdown.  If you click on the CAR / MDD column, it should show an arrow pointing down and show you the results from top to bottom.

判断交易系统最常见的方法之一是CAR/MDD。 这是复合年回报率除以最大回撤,基本上可以帮助我们选择年回报率最高与最大回撤的系统。 如果单击 CAR / MDD 列,它应该显示一个向下的箭头,并从上到下显示结果。

 

You can then scan over the rest of the results, see which combination of moving averages worked best, and see how many trades were taken overall.

然后,您可以浏览其余结果,查看哪种移动平均线组合效果最好,并查看总共进行了多少笔交易。

Try It Out For Yourself

自己试试吧

So now you have the basics of optimizing a trading system in Amibroker.  Try it out with different indicators or methods, and see if you can optimize a trading system for yourself!

现在您已经掌握了在 Amibroker 中优化交易系统的基础知识。 尝试使用不同的指标或方法,看看您是否可以为自己优化交易系统!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值