Equity() vs porfolio equity

#1
Hi all, :)
this is my 1st post in traderji.com

I'm using Amibroker 5.51.2 in Win7 Professional

I'm learning the exercise in Howard Bandy Introduction to Amibroker with the following code.

-----------------------------
FastMA = MA(C, 5);
SlowMA = MA(C, 20);

Buy = Cross(FastMA, SlowMA);
Sell = Cross(SlowMA, FastMA);

Plot(C, "C", colorBlack, styleCandle);
e = Equity();
Plot(e, "equity", colorGreen, styleLine | styleOwnScale);
---------------------------


When I click backtest, AB automatically create a new pane with Portfolio Equity value.

Then, I manually plot the Equity() chart below the Portfolio equity chart by clicking Apply Indicator in the AFL Editor.

However, I found out that the equity value is different for both charts at any time.

I'm running the backtest on a single symbol.

I think it may due to the new ~~~equity symbol that AB creates when we run a backtest. But, I cant figure out why there is difference even running on a single symbol.

anyone familiar with this problem?

Thanks,
Bursana
 
#2
Hi all, :)
this is my 1st post in traderji.com

I'm using Amibroker 5.51.2 in Win7 Professional

I'm learning the exercise in Howard Bandy Introduction to Amibroker with the following code.

-----------------------------
FastMA = MA(C, 5);
SlowMA = MA(C, 20);

Buy = Cross(FastMA, SlowMA);
Sell = Cross(SlowMA, FastMA);

Plot(C, "C", colorBlack, styleCandle);
e = Equity();
Plot(e, "equity", colorGreen, styleLine | styleOwnScale);
---------------------------


When I click backtest, AB automatically create a new pane with Portfolio Equity value.

Then, I manually plot the Equity() chart below the Portfolio equity chart by clicking Apply Indicator in the AFL Editor.

However, I found out that the equity value is different for both charts at any time.

I'm running the backtest on a single symbol.

I think it may due to the new ~~~equity symbol that AB creates when we run a backtest. But, I cant figure out why there is difference even running on a single symbol.

anyone familiar with this problem?

Thanks,
Bursana
Anyone is able to answer to this very very old thread?
I have the same problem.
tks
 

trash

Well-Known Member
#3
It's all mentioned in the AmiBroker help.
Equity() function is single security equity but not portfolio equity!
~~~Equity symbol is portfolio equity.

Read... just read and try to understand while reading instead of making up something yourself or whatever. Everything is written down already.
 

trash

Well-Known Member
#4
Instead of ~~~Equity symbol (i.e. calling it via eq = Foreign("~~~Equity", "C"); ) portfolio equity array can be stored via custom backtester (CBT) also.

And as result it can be plotted after analysis or whatever you wanna do with it.

Code:
// your system here 
period = 20; // number of averaging periods 
m = MA( Close, period ); // simple moving average
Buy = Cross( Close, m ); // buy when close crosses ABOVE moving average
Sell = Cross( m, Close ); // sell when closes crosses BELOW moving average
Short = Cover = 0;
// your system here


SetCustomBacktestProc( "", True );
if ( Status( "action" ) == actionPortfolio ) {
    bo = GetBacktesterObject();
    bo.Backtest();
    // storing portfolio equity
    StaticVarSet( "PortfolioEquity", bo.EquityArray() );
}

if( Status( "action" ) == actionIndicator ) {
    // calling portfolio equity after analysis
    portfolioequity = StaticVarGet( "PortfolioEquity" );
    //
    if( LastValue( Cum( portfolioequity ) ) == 0 )
        Title = EncodeColor( colorRed ) + "Execute an analysis first!!";
    //
    Plot( portfolioequity, "PortFolio Equity", colorBrightGreen, styleLine );
}
So all in all the only problem is a READING problem ( once again).
 
Last edited:

trash

Well-Known Member
#5
You also need to read about parameters of Equity() function. I.e if you just use Equity() then you apply default arguments Equity( 0, -1, 0, 0 )
Also keep in mind that Equity() function is old single security backtester that does not offer/support features implemented in newer AB versions.

Reading, understanding and correctly applying are important things.

Equity
- calculate single-symbol equity line Trading system toolbox
(AFL 2.0)


SYNTAX equity( Flags = 0, RangeType = -1, From = 0, To = 0 )
RETURNS ARRAY
FUNCTION NOTE: This function is left here for backward compatibility and is using old, single-security backtester. New coding should rather use portfolio-level equity (special ~~~EQUITY ticker).
Function:
Returns single-security Equity line based on buy/sell/short/cover rules, buy/sell/short/coverprice arrays, all apply stops, and all other backtester settings.

Flags - defines the behaviour of Equity function
0 : (default) Equity works as in 3.98 - just calculates the equity array
1 : works as 0 but additionally updates buy/sell/short/cover arrays so all redundant signals are removed exactly as it is done internally by the backtester plus all exits by stops are applied so it is now possible to visualise ApplyStop() stops.
2 : (advanced) works as 1 but updated signals are not moved back to their original positions if buy/sell/short/cover delays set in preferences are non-zero. Note: this value of flag is documented but in 99% of cases should not be used in your formula. Other values are reserved for the future.

RangeType - defines quotations range being used:
-1 : (default) use range set in the Automatic analysis window
0 : all quotes
1 : n last quotes (n defined by 'From' parameter)
2 : n last days (n defined by 'From' parameter)
3 : From/To dates

From : defines start date (datenum) (when RangeType == 3) or "n" parameter (when RangeType == 1 or 2)
To: defines end date (datenum) (when RangeType == 3) otherwise ignored

datenum defines date the same way as DateNum() function as YYYMMDD
where YYY is (year - 1900), MM is month, DD is day

December 31st, 1999 has a datenum of 991231
May 21st, 2001 has a datenum of 1010521 All these parameters are evaluated at the time of the call of Equity function. Complete equity array is generated at once. Changes to buy/sell/short/cover rules made after the call have no effect. Equity function can be called multiple times in single formula.
IMPORTANT NOTE: Equity() function uses so called "old" single-security backtester that offers only subset of features of new backtester. To retrieve value of portfolio-level equity generated by new backtester use Foreign("~~~EQUITY", "C").
 

Similar threads