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

[amibroker] Help with Custom Objective Function


  • Date: Tue, 23 Feb 2010 20:01:20 -0800 (PST)
  • From: B S <bs2167@xxxxxxxxx>
  • Subject: [amibroker] Help with Custom Objective Function

PureBytes Links

Trading Reference Links



Hi- I'm trying to implement the following objective function:
 
= median monthly return / avg of 5 worst monthly returns
 
but I am completely stumped on how to calculate these two items in a loop.  Here's my code...anyone have ideas on how to calculate MoMed and AvgFive below?  Appreciate any help...i've got no chance alone. 
 

SetCustomBacktestProc("");

if (Status("action") == actionPortfolio)

{

    bo = GetBacktesterObject()

    bo.Backtest();

   

    mo = Month();

    LastMonthC = bo.InitialEquity;

    Count = 0;

////////////////////////////

// SKIP non-trading bars

////////////////////////////

    for( i = 0; i < BarCount; i++ )

    {

        if( C[i] )

        {

            startbar = i;

            break;

        }

    }

   

    for( i = startbar + 1; i < BarCount; i++ )

    {

        if(mo[i] != mo[i-1])

        {

            Count++;  //determine # of months in backtest

            Chg = C / LastMonthC - 1//get % chg for this month

            VarSet("ChgMon" + NumToStr(Count,1.0), Chg);  //save this month's % chg

            LastMonthC = C[i];  //store this month's equity level to calculate % chg next month

        }

    }

 

    for( i = 0; i < Count; i++ )

    {

        MoMed =   ???     //determine median monthly return

        AvgFive = ???  //determine average return of 5 worst months

    }

   

    MedRatio = MoMed / -AvgDD;

    bo.AddCustomMetric("MedRatio", MedRatio);

}




__._,_.___


**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

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





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___