Amibroker性能 - 让数据说话

Discussion in 'AmiBroker' started by espresso, Mar 14, 2010.

  1. 今天无意中在WLD板块看到有海友说做不到10年的日线回测时WLD跑不动了,回想我最近用Amibroker做的回测,发现这区别也太大了。特地把我使用AB做回测的结果向大家报告一下,需要做大数据量回测的朋友可以考虑一下Amibroker。它在性能和稳定性方面的表现的确不同凡响,至少我使用的情况是这样的。

    最近用Amibroker在EURUSD小时线上测试一个简单策略。时间范围是8年,从2001年5月到2009年5月。因为涉及到参数优化,连续跑了2万多次完整的策略,共6个多小时。我大概算了一下,平均不到2秒钟就完成一次运行。虽然我测试的策略不是很复杂,但是那天测试完之后,我对AB的性能和稳定性的确是非常地满意。

    上面的测试是在32bit/2GB的HP笔记本上完成的,Amibroker还有64位版本,运行在64bit/8GB的Windows7上面的性能就可想而知。

    ============================================
    平均不到2秒运行一次策略是这样算出来的:
    6.5 小时 x 60min x 60sec / 21000 = 1.11 秒

    之前没有意识到,现在自己算一下都觉得有点不可思议。我的策略比较简单也是一个原因吧。 :D
     
  2. WLD 5也很快的,我使用55-day channel breakout system by Van K. Tharp in "Trade Your Way to Financial Freedom" (pg. 286)来测试20年日线DOW JONES 30 指数数据是不到1/5秒(188ms),用的还是破电脑呢。
     
  3. 然后再用上面的策略来投资组合测试DOW JONES 指数所有成份股(30只)20年日线数据用的是1.5秒。
     
  4. 嗯,刚才看到是那个WLD很慢的帖子有更新说好像是因为emule也在上面跑。
    搞得WLD的版主都被惊动了,不好意思啊,呵呵。非常欢迎这样有具体数据的帖子!!

    除非在相同硬件上使用完全相同的时间范围去测试完全相同的策略才能比较平台之间的差别。
    交易平台的选择有很多个人的因素在里面,也是不能强求的。
     
  5. 我也是有点兴趣所来看看,duker投资组合测试的是1700多只股票。。。一下子就通过没发生问题才怪呢。
     
  6. 这个问题的关键在交易策略
    简单的策略 和 复杂策略是没有可比性的
    就好像考试的时候大家的卷子都不一样 得出来的分数怎么比啊
     
  7. 不知哪位大侠能够在同样的条件下,对2个平台作个对比?
     
  8. Amibroker 速度快是公认的。而WLD3在那时代也是差不多最慢的,WLD5应该快上很多了吧。
    看过说明,Amibroker是用的数组运算方式,所以特别快。不过有时有些小小的疑问,这样计算虽然很快,但能不能完美的模拟时序? 而WLD和其他工具应该都是顺序执行,按照数据的bar然后一条条的计算下去了。
     
  9. AB是相当快,扫描整个A股市场,我测试过在一个5秒的周期内,扫描可以达到数百只不同的品种,当然与硬件还是有很大关系。。在ab的kb中有介绍AFL execution speed.

    http://www.amibroker.com/kb/2008/08/12/afl-execution-speed/

    AmiBroker Formula Language (AFL) thanks to its array processing model is able to run at the same speed as code written in assembler (i.e. machine code). The following article explains how.

    AFL runs with native assembly speed when using array operations.
    A simple array multiplication like this:

    X = Close * H; // array multiplication (each array element is multiplied)

    gets compiled by AmiBroker to just 8 assembly instructions:
    loop: mov edx,dword ptr [esp+58h]
    inc esi ; increase counters
    add eax,4
    cmp esi,edi
    fld dword ptr [edx+esi*4-4] ; get element of close array
    fmul dword ptr [eax+ecx-4] ; multiply by element of high array
    fstp dword ptr [eax-4] ; store result
    jl loop ; continue until all elements are processed


    As you can see there are three 4 byte memory accesses per loop iteration (2 reads each 4 bytes long and 1 write 4 byte long)

    With such tight loop, single processor core running an AFL formula is able to saturate memory bandwidth in majority of most common operations/functions if total array sizes used in given formula exceedes DATA cache size.

    On my (2 year old) 2GHz Athlon x2 64 single iteration of this loop takes 6 nanoseconds (see benchmark code below). 6 nanoseconds to process one bar of data, or 166 million bars per second. So, during 6 nanoseconds we have 8 byte reads and 4 byte store. Thats (8/(6e-9)) bytes per second = 1333 MB per second read and 667 MB per second write simultaneously i.e. 2GB/sec combined !

    Now if you look at memory benchmarks you will see that 2GB/s is the limit of system memory speed on Athlon x64 (DDR2 dual channel)
    And that’s considering the fact that Athlon has superior-to-intel on-die integrated memory controller (hypertransfer)

    // benchmark code
    // for accurrate results run it on LARGE arrays -
    // intraday database, 1-minute interval, 50K bars or more)
    GetPerformanceCounter(1);
    for(k = 0; k < 1000; k++ ) X = C * H;
    "Time per single iteration ="+1e-3*GetPerformanceCounter()/(1000*BarCount);

    Only really complex operations that use *lots* of FPU (floating point) cycles such as trigonometric (sin/cos/tan) functions are slow enough for the memory to keep up.
     
  10. 这和你提供的数据的最小精度有关,如果有tick data那么可以做精确到tick的模拟。如果你有1hr数据,那么做1hr以上的模拟时,AB会转换到指定的时间框架上,比如4hr或者daily。毕竟,大多数策略关心的只是high, low, open, close, volume这几个值。