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
{
    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);
}    (Status("action") == actionPortfolio)


      

Reply via email to