Underwater Equity

In the report after running an equity portfolio backtest , the "Underwater Equity" curve is only shown for the portfolio. How do I see the underwater curve for both the Portfolio and a benchmark index on the same graph?

  1. Go to Report Charts folder of Charts window
  2. Right click "2. Underwater Equity" AFL to open in formula editor
  3. Copy drawdown calculation code that is in there and put it below of existing code.
  4. Instead of Eq = C; use Idx = Foreign("YOUR_INDEX", "C");
  5. Add Plot code for that copied calculation
  6. Save AFL and close editor
  7. Run backtest
// Underwater Equity chart
// (C)2009 AmiBroker.com
// Should be used only on ~~~EQUITY or ~~~OSEQUITY symbol
// modified to add benchmark index drawdown
// https://forum.amibroker.com/t/underwater-equity/29710/2

EQ = C;
MaxEQ = Highest( EQ );
DD = 100 * ( Eq - MaxEQ ) / MaxEq;
MaxDD = Lowest( DD );

IdxName = "$SPX";
Idx = Foreign(IdxName,"C");
MaxIdx = Highest( Idx );
DDIdx = 100 * ( Idx - MaxIdx ) / MaxIdx;
MaxDDIdx = Lowest( DDIdx );

Title = StrFormat("Drawdown = %.2g%%, Max. drawdown %.2g%%", DD, LastValue( MaxDD ) );
Title += StrFormat("\nDrawdown %s = %.2g%%, Max. drawdown %s %.2g%%", IdxName, DDIdx, IdxName, LastValue( MaxDDIdx ) );

SetGradientFill( GetChartBkColor(), colorBlue, 0 );

Plot( DD, "Drawdown ", colorBlue, /*styleGradient |*/ styleLine );
Plot( MaxDD, "Max DD", colorViolet, styleNoLabel );

Plot( DDIdx, "Drawdown Index ", colorOrange, styleLine);
Plot( MaxDDIdx, "Max DD Index", colorRed, styleNoLabel );

SetChartOptions( 2, 0, chartGridPercent );

if( Name() != "~~~EQUITY" AND Name() != "~~~OSEQUITY"  ) 
	Title = "Warning: wrong ticker! This chart should be used on ~~~EQUITY or ~~~OSEQUITY only";
5 Likes

Thank you for your help @fxshrat . It is working fine!

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.