[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Optimization fitness goals with custom metrics



PureBytes Links

Trading Reference Links

Some of you may find this useful. I'm not sure if this has been
discussed before. If you are writing a fitness function with the CBT,
you can also easily add goals. The code below generates a fitness
value and then penalizes the fitness value for each goal it fails to
attain. If you are using IO, you can do this directly with
IO directives. This is an alternative way to implement goals with or
without IO.

-Steve

SetOption("UseCustomBacktestProc", true);
if ( Status("action") == actionPortfolio )
{
    bo     = GetBacktesterObject();
    bo.Backtest(); // run default backtest procedure
    st     = bo.GetPerformanceStats(0); // get stats for all trades

    kratio =  st.GetValue("KRatio");
    rarmdd =  st.GetValue("RAR/MDD");
    car    =  st.GetValue("CAR");
    mdd    = -st.GetValue("MaxSystemDrawdownPercent");
    upi    =  st.GetValue("UlcerPerformanceIndex");
    winpct =  st.GetValue("WinnersPercent");
    allqty =  st.GetValue("AllQty");
    tradesPerYear = allqty / (BarCount / 252);

    fitness = Max(0,kratio) * Max(0,car) * Max(0,upi) * Max(0,rarmdd);

    // Goal : trades per year > 2
    if (tradesPerYear < 2)
      fitness = tradesPerYear/2 * fitness;

    // Goal : MDD < 10%
    if (mdd > 10)
      fitness = 10/mdd * fitness;

    // Goal : CAR > 10%
    if (car < 10)
      fitness = car/10 * fitness;

    // Goal : winpct > 60%
    if (winpct < 60)
      fitness = winpct/60 * fitness;

    bo.AddCustomMetric("Fitness", fitness);
}


------------------------------------

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/