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 [email protected], "bh.hicks" <bh.hi...@...> 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
>