{"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>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>

After backtest is run, we can see our custom metrics in the backtest report.<\/p>

More information about creating custom metrics can be found in the manual:
http:\/\/www.amibroker.com\/guide\/a_custommetrics.html<\/a><\/p>","protected":false},"excerpt":{"rendered":"

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 hereBuy = Cross( MACD(), Signal() );Sell = Cross( Signal(), MACD() )After backtest is run, we can […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[53,15,30,21],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1009"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=1009"}],"version-history":[{"count":2,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1009\/revisions"}],"predecessor-version":[{"id":1011,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/1009\/revisions\/1011"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=1009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=1009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=1009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}