{"id":1009,"date":"2015-01-06T00:18:50","date_gmt":"2015-01-06T05:18:50","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/?p=1009"},"modified":"2015-01-05T20:21:11","modified_gmt":"2015-01-06T01:21:11","slug":"how-to-display-interest-gains-in-the-backtest-report","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2015\/01\/06\/how-to-display-interest-gains-in-the-backtest-report\/","title":{"rendered":"How to display interest gains in the backtest report"},"content":{"rendered":"
The default backtest report shows total Net Profit<\/strong> 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<\/strong> and report them as separate metrics.<\/p> After backtest is run, we can see our custom metrics in the backtest report.<\/p>SetCustomBacktestProc<\/span>( <\/span>"" <\/span>);
if ( <\/span>Status<\/span>( <\/span>"action" <\/span>) == <\/span>actionPortfolio <\/span>)
{
<\/span>bo <\/span>= <\/span>GetBacktesterObject<\/span>();
<\/span>bo<\/span>.<\/span>Backtest<\/span>(); <\/span>\/\/ run default backtest procedure
\/\/ read Net Profit, Winners and Losers profits from the report
<\/span>st <\/span>= <\/span>bo<\/span>.<\/span>GetPerformanceStats<\/span>( <\/span>0 <\/span>);
<\/span>netProfit <\/span>= <\/span>st<\/span>.<\/span>GetValue<\/span>( <\/span>"NetProfit" <\/span>);
<\/span>tradeProfits <\/span>= <\/span>st<\/span>.<\/span>GetValue<\/span>(<\/span>"WinnersTotalProfit"<\/span>) + <\/span>st<\/span>.<\/span>GetValue<\/span>(<\/span>"LosersTotalLoss"<\/span>);
<\/span>bo<\/span>.<\/span>AddCustomMetric<\/span>( <\/span>"Trading profits"<\/span>, <\/span>tradeProfits <\/span>);
<\/span>bo<\/span>.<\/span>AddCustomMetric<\/span>( <\/span>"Interest earnings"<\/span>, <\/span>netProfit <\/span>- <\/span>tradeProfits <\/span>);
}
<\/span>\/\/ trading rules here
<\/span>Buy <\/span>= <\/span>Cross<\/span>( <\/span>MACD<\/span>(), <\/span>Signal<\/span>() );
<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>Signal<\/span>(), <\/span>MACD<\/span>() )<\/code>