Hi RZ --

You can do this by creating a custom objective function.

It could as simple as assigning the custom function a value of 0 whenever
the parameter set results show maximum system drawdown exceeds 30%.

Try this:

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

//    LimitDrawdown.afl
//
//    Use CustomBacktester to limit
//    drawdown in trading systems.
//
//    Howard Bandy
//    June 2010
//
OptimizerSetEngine( "cmae" );

//    The custom backtest code
//    to penalize results that do not
//    meet your specifications

DesiredDDLimit = 30;

SetCustomBacktestProc( "" );

if ( Status( "action" ) == actionPortfolio )
{
    bo = GetBacktesterObject();
    bo.backtest();
    st = bo.getperformancestats( 0 );
    MaxSysDD = abs( st.getvalue( "MaxSystemDrawdownPercent" ) );
    NetProfPct = st.getvalue( "NetProfitPercent" );
    ObFn = ( MaxSysDD < DesiredDDLimit ) * NetProfPct;
    bo.addcustommetric( "FilteredNetProfit", ObFn );
}


//    The Buy and Sell signals

MA1Len = Optimize( "MA1Len", 5, 1, 100, 1 );

MA2Len = Optimize( "MA2Len", 20, 1, 100, 1 );

MA1 = EMA( C, MA1Len );

MA2 = EMA( C, MA2Len );

Buy = Cross( MA1, MA2 );

Sell = Cross( MA2, MA1 );



e = Equity();

Plot( e, "E", colorGreen, styleLine );
////////////////// end ////////////////////

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

Thanks,
Howard


On Fri, Jun 11, 2010 at 6:37 AM, ics4mer <[email protected]> wrote:

>
>
> Hi,
>
> Doing a bit of backtesting lately, and I was wondering how to limit the
> drawdown while using another metric for the objective function.
>
> Lets say that I want to optimize for Net Profit, but I won't accept
> parameter sets that result in a drawdown of more than 30%
>
> I know it can be done (AB does anything).
>
> Could somebody give me a pointer please?
> I can't find explicit references to it in the archive, and I don't think
> I'm ready for some of the more intricate parts of the CBT.
>
> TIA
>
> RZ
>
>  
>

Reply via email to