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

[amibroker] Re: Custom Optimization Metric



PureBytes Links

Trading Reference Links

Ok, I am making progress on this but getting hung up on the standard deviation calculations.  I have been through most of all 800+ posts that mention standard deviation but haven't been able to figure this out.  If anyone can offer some insight into why my TradeStDev is coming back empty, I would very much appreciate it as I barely have any hair left.


SetCustomBacktestProc("");

if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest(); 
st = bo.GetPerformanceStats(0);

//Get Variables
WLratio=st.GetValue("PayoffRatio");
WinPercent=st.GetValue("WinnersPercent")/100;
PF=st.GetValue("ProfitFactor");
NetProfit=st.GetValue("NetProfit");
MaxDD=st.GetValue("MaxSystemDrawdown");
TestYears=(EndValue( BarIndex() ) - BeginValue( BarIndex() ))/252;
AvgTrade=st.GetValue("AllAvgProfitLossPercent");

// iterate through closed trades
TradeReturn = 0;
NumTrades = 0;

   for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
   {
		TradeReturn[NumTrades] = trade.GetPercentProfit();
		NumTrades++;
   }

// Metrics
Fscore=(((WLratio+1)*WinPercent)-1)/WLratio;
MyF=Fscore*PF;
DDR=(NetProfit/-MaxDD)*(TestYears/20);
TradeStdDev=StDev(TradeReturn,3); 

// Here we add custom metric to backtest report
bo.AddCustomMetric( "W/L Ratio",WLratio);
bo.AddCustomMetric( "Win %",WinPercent);
bo.AddCustomMetric( "ProfitFactor",PF);
bo.AddCustomMetric( "F-Score",Fscore);
bo.AddCustomMetric( "MyF",MyF);
bo.AddCustomMetric( "DDR",DDR);
bo.AddCustomMetric( "AvgTrade%",AvgTrade);
bo.AddCustomMetric( "Test0",TradeReturn[0]);
bo.AddCustomMetric( "Test1",TradeReturn[NumTrades-1]);
bo.AddCustomMetric( "TradeStDev",TradeStdDev);
}


--- In amibroker@xxxxxxxxxxxxxxx, "bh.hicks" <bh.hicks@xxx> wrote:
>
> I have been a long time Traders Studio user and am beginning the process of migrating everything over to AmiBroker.  One of the more useful pieces of code I wrote for Traders Studio was a custom optimization metric that I would like to reproduce in AmiBroker.  I am a little overwhelmed at all the information available and would very much appreciate it if someone could point me towards some sources of info that will allow me to accomplish this.
> 
> The ranking metric does the following:
> 
> Msharpe=(AvgMreturn-.0025)/StDevMreturn (m refers to monthly)
> Tscore=Sqr(TradeCount)* AvgTrade/TradeStdDev (std dev. is of % returns of each trade)
> Fscore=(((WLratio+1)*WinPercent)-1)/WLratio (WLratio is W/L ratio)
> MyF=Fscore*ProfitFactor
> DDR=(NetProfit/MaxDD)*(YearsTested/20)
> 
> CustomScore=Msharpe*MyF*Tscore*DDR
> 
> This did a pretty good job allowing me to quickly rank optimization runs on the criteria that is important to me.
> 
> So although new to AmiBroker, I can work my myself around some moderately difficult code and Trader Studio's object-oriented back end but I really just don't know where to start to dig up how to access this data during backtests an optimization runs. 
> 
> Thanks for any help.
> B
>




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

**** 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/

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/