January 6, 2015
How to display interest gains in the backtest report
The default backtest report shows total Net Profit figure, which includes both trading profits and interest earnings. With Custom Backtest procedure we can easily isolate these components by summing up profits and loses from individual trades, then subtracting trading gains from the Net Profit and report them as separate metrics.
SetCustomBacktestProc( "" );
if ( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject();
bo.Backtest(); // run default backtest procedure
// read Net Profit, Winners and Losers profits from the report
st = bo.GetPerformanceStats( 0 );
netProfit = st.GetValue( "NetProfit" );
tradeProfits = st.GetValue("WinnersTotalProfit") + st.GetValue("LosersTotalLoss");
bo.AddCustomMetric( "Trading profits", tradeProfits );
bo.AddCustomMetric( "Interest earnings", netProfit - tradeProfits );
}
// trading rules here
Buy = Cross( MACD(), Signal() );
Sell = Cross( Signal(), MACD() )
After backtest is run, we can see our custom metrics in the backtest report.
More information about creating custom metrics can be found in the manual:
http://www.amibroker.com/guide/a_custommetrics.html
Filed by Tomasz Janeczko at 12:18 am under Custom Backtest
Comments Off on How to display interest gains in the backtest report