Quantcast
Channel: AFL – AmiBroker Knowledge Base
Viewing all articles
Browse latest Browse all 24

How to display interest gains in the backtest report

$
0
0

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);
    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 CrossMACD(), Signal() );
Sell CrossSignal(), 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


Viewing all articles
Browse latest Browse all 24

Trending Articles