amibroker

HomeKnowledge Base

How to create copy of portfolio equity?

As you know Portfolio backtester creates special ticker “~~~EQUITY” which holds portfolio-level equity of the system under test. Some may find it useful to save this equity into another symbol after backtest for future analysis and/or comparison. Good news is that it is possible to do that automatically using custom backtester procedure and AddToComposite function. The formula below shows how.

// A pre-5.50 way of making portfolio copy
// YOUR TRADING SYSTEM HERE
// ....
SetCustomBacktestProc("");
if( 
Status("action") == actionPortfolio )
{
 
bo GetBacktesterObject();
 
bo.Backtest();
 
AddToCompositeForeign("~~~EQUITY","C"),
                 
"~~~MY_EQUITY_COPY""X",
                 
atcFlagDeleteValues atcFlagEnableInPortfolio );

Please note that prior to version 4.78.1 BETA, atcFlagEnableInPortfolio did not work in combination with atcFlagCompositeGroup (or atcFlagDefaults) so we needed to avoid this flag in the code above, to make it work fine with previous versions of AmiBroker. In version 4.78.1 it works with all combinations of flags, so you don’t need to worry about this any more.As you know Portfolio backtester creates special ticker

IMPORTANT UPDATE: As of AmiBroker version 5.50 a new property of Backtester object is available: EquityArray that should be used instead of Foreign(“~~~EQUITY”,”C”). This is so because now backtester can be run in many instances and each instance has its own, private equity. So for AmiBroker 5.50 correct code looks as follows:
// The code for AmiBroker 5.50 and above
// YOUR TRADING SYSTEM HERE
// ....
SetCustomBacktestProc("");
if( 
Status("action") == actionPortfolio )
{
 
bo GetBacktesterObject();
 
bo.Backtest();
 
AddToCompositebo.EquityArray,
                 
"~~~MY_EQUITY_COPY""X",
                 
atcFlagDeleteValues atcFlagEnableInPortfolio );

3 Responses to “How to create copy of portfolio equity?”

  1. Bo Ek
    December 30th, 2006 | 10:11 am

    How do you watch your real equity curve? I mean after manually putting in real life
    buy/sell and deposit/withdraw actions. Is it possible to just plot the equity curve
    without any backtesting or similar?

  2. January 1st, 2007 | 8:01 am

    Yes it is possible, this article shows how to do that: http://www.amibroker.com/kb/2006/05/06/discretionary-equity/

  3. Herman
    April 7th, 2007 | 12:31 am

    I can’t get it to work TJ, I tried running this code in the AA Portfolio Tester:

    Buy=Sell=Short=Cover=0;
    if( Status(“action”) == actionPortfolio ) _TRACE(“# actionPortfolio test”);

    DBV Shows no output, also “actionPortfolio” is not documented in the Help.