6.2.9Backtesting Frameworks

Understand performance metrics (CAGR, max DD)

2,193 words10 min readdifficulty · medium

What Are We Measuring?

When you backtest a trading strategy, you get a sequence of portfolio values over time: V0,V1,V2,,VTV_0, V_1, V_2, \ldots, V_T. Raw numbers like "portfolio went from ₹100,000 to ₹250,000" are meaningless without context:

  • How long did it take?
  • Did it grow smoothly or with terrifying drops?

Performance metrics standardize results so you can compare strategies, benchmark against indices, and assess risk-adjusted returns.


CAGR (Compound Annual Growth Rate)

Derivation from First Principles

Start with the compound interest formula. If you invest V0V_0 at a constant annual rate rr for nn years:

Vn=V0(1+r)nV_n = V_0 (1 + r)^n

We know V0V_0 (starting capital), VnV_n (ending capital), and nn (years). Solve for rr:

VnV0=(1+r)n\frac{V_n}{V_0} = (1 + r)^n

Take the nn-th root:

(1+r)=(VnV0)1/n(1 + r) = \left(\frac{V_n}{V_0}\right)^{1/n}

Therefore:

Why subtract 1? Because (1+r)(1+r) includes the original capital; subtracting 1 isolates the rate of return.

Why the exponent 1/n1/n? We're reversing the compounding process—taking the geometric mean.

Figure — Understand performance metrics (CAGR, max DD)

Worked Example 1: Simple CAGR Calculation

Setup: Your portfolio grew from ₹1,00,000 to ₹1,80,000 over 3 years.

Step 1: Identify values.

  • Vstart=100000V_{\text{start}} = 100000
  • Vend=180000V_{\text{end}} = 180000
  • n=3n = 3

Step 2: Apply formula. CAGR=(180000100000)1/31\text{CAGR} = \left(\frac{180000}{100000}\right)^{1/3} - 1

Why this step? We need the ratio of ending to starting value—that's the total growth multiplier.

Step 3: Calculate. =(1.8)0.3331=1.21641=0.2164= (1.8)^{0.333} - 1 = 1.2164 - 1 = 0.2164

Result: CAGR = 21.64% per year.

Interpretation: Even though the portfolio didn't grow exactly 21.64% every year (maybe +30%, +10%, +25%), the equivalent smooth annual rate is 21.64%.


Worked Example 2: Fractional Years

Setup: A strategy runs for 520 days (not a neat number of years). Portfolio: ₹50,000 → ₹68,000.

Step 1: Convert days to years. n=520365=1.4247 yearsn = \frac{520}{365} = 1.4247 \text{ years}

Why this step? CAGR is an annual rate, so time must be in years.

Step 2: Apply formula. CAGR=(6800050000)1/1.42471\text{CAGR} = \left(\frac{68000}{50000}\right)^{1/1.4247} - 1

=(1.36)0.70201=1.23761=0.2376= (1.36)^{0.7020} - 1 = 1.2376 - 1 = 0.2376

Result: CAGR ≈ 23.76%.


Maximum Drawdown (Max DD)

Why It Matters

CAGR can be seductive—"30% annual returns!" sounds amazing. But if achieving that required surviving a 70% drawdown, most retail investors would have exited in panic. Max DD captures emotional pain and capital preservation risk.

Derivation: How to Calculate Max DD

For each point ii in your equity curve:

  1. Running Maximum: Track the highest portfolio value seen so far: Peaki=max(V0,V1,,Vi)\text{Peak}_i = \max(V_0, V_1, \ldots, V_i)

  2. Drawdown at ii: How far below the peak are we now? DDi=ViPeakiPeaki=ViPeaki1\text{DD}_i = \frac{V_i - \text{Peak}_i}{\text{Peak}_i} = \frac{V_i}{\text{Peak}_i} - 1

    Why this formula? Drawdown is a percentage loss from the peak. If peak was ₹100 and current is ₹80, DD = -20%.

  3. Maximum Drawdown: The most negative drawdown across all ii: Max DD=min(DD0,DD1,,DDT)\text{Max DD} = \min(\text{DD}_0, \text{DD}_1, \ldots, \text{DD}_T)

    (We take min\min because drawdowns are negative.)


Worked Example 3: Computing Max DD Step-by-Step

Setup: Daily portfolio values over 7 days:

Day Value (₹)
0 100,000
1 105,000
2 110,000
3 102,000
4 98,000
5 108,000
6 106,000

Step 1: Compute running peak.

Day Value Peak
0 100000 100000
1 105000 105000
2 110000 110000
3 102000 110000
4 98000 110000
5 108000 110000
6 106000 110000

Why track peak? We need to know the highest value up to that point to measure the drop.

Step 2: Compute drawdown at each day.

DDi=ViPeakiPeaki\text{DD}_i = \frac{V_i - \text{Peak}_i}{\text{Peak}_i}

Day Value Peak Drawdown
0 100000 100000 0.00%
1 105000 105000 0.00%
2 110000 110000 0.00%
3 102000 110000 -7.27%
4 98000 110000 -10.91%
5 108000 110000 -1.82%
6 106000 110000 -3.64%

Why this step? Each drawdown shows how far we've fallen from the recent peak.

Step 3: Find maximum drawdown.

Max DD=max(0.00,0.00,0.00,7.27,10.91,1.82,3.64)=10.91%\text{Max DD} = \max(|-0.00|, |-0.00|, |-0.00|, |-7.27|, |-10.91|, |-1.82|, |-3.64|) = 10.91\%

Result: Max DD = 10.91% (occurred on Day 4).


Connecting CAGR and Max DD




Recall Explain to a 12-Year-Old

Imagine you're growing a plant. CAGR is like asking: "If my plant grew the same amount every year, what would that yearly growth be?" Even if it grew a lot one year and a little another, CAGR smooths it out to one steady number—like finding the average speed for a race.

Max Drawdown is the scariest moment. Maybe your plant was 12 inches tall, then a storm broke it down to 8 inches. That 4-inch drop (33% of 12) is your "maximum drawdown"—the worst damage before it recovered. Even if the plant later grew to 20 inches, you still remember that scary moment at 8 inches. That's what Max DD tracks—the worst scare you had along the way.



Connections

  • 6.2.01-Introduction-to-backtesting — Why we need standardized metrics
  • 6.2.08-Equity-curve-analysis — Max DD is derived from equity curves
  • 6.3.01-Sharpe-ratio-and-risk-adjusted-returns — CAGR/Max-DD leads to Calmar; Sharpe uses volatility instead
  • 7.1.04-Position-sizing-and-Kelly-criterion — Max DD informs how much leverage is safe
  • 8.2.02-Psychological-trading-discipline — Surviving Max DD requires mental toughness

#flashcards/stock-market

What does CAGR stand for and what question does it answer?
Compound Annual Growth Rate. It answers: "What fixed yearly return would replicate my total growth if returns compounded smoothly?"
What is the CAGR formula?
CAGR = (V_end / V_start)^(1/n) - 1, where n is number of years.
Why do we subtract 1 in the CAGR formula?
Because (V_end/V_start)^(1/n) gives (1+r), which includes the principal. Subtracting 1 isolates the rate of return r.
A portfolio grows from ₹50,000 to ₹80,000 in 2 years. What is the CAGR?
(80000/50000)^(1/2) - 1 = (1.6)^0.5 - 1 = 1.2649 - 1 = 0.2649 = 26.49%.
What does Maximum Drawdown measure?
The largest peak-to-trough decline in portfolio value during the backtest period, as a percentage. It measures the worst loss from any prior high point.
How do you calculate drawdown at time i?
DD_i = (V_i - Peak_i) / Peak_i, where Peak_i is the highest portfolio value seen up to time i.
Why is Maximum Drawdown important beyond CAGR?
CAGR shows returns but hides volatility and pain. Max DD reveals the worst loss you must survive emotionally, which determines if a strategy is psychologically tradeable.
What is the Calmar Ratio?
Calmar Ratio = CAGR / |Max DD|. It measures risk-adjusted return: higher is better. Example: 20% CAGR with 10% Max DD gives Calmar = 2.0.
What is wrong with averaging annual returns arithmetically instead of using CAGR?
Returns compound, not add. Arithmetic mean ignores compounding. Example: +50% then -50% gives arithmetic mean 0%, but actual result is -25% (100→150→75). CAGR uses geometric mean.
Portfolio values: ₹100k → ₹120k (peak) → ₹90k → ₹110k. What is Max DD?
Peak = 120k. Lowest = 90k. DD = (90-120)/120 = -25%. Max DD = 25%.
If a strategy ran for 730 days, how do you convert this to years for CAGR?
n = 730/365 = 2.0 years.
True or False: Max DD = 40% means the portfolio lost 40% overall by the end.
False. Max DD is the worst moment, not the final result. The portfolio might recover or even gain overall while still having experienced a 40% DD at some point.

Concept Map

standardized into

includes

includes

solved for r gives

reverses compounding via

measures

measures

worst peak-to-trough drop of

enables

balanced against

Portfolio values over time

Performance metrics

CAGR

Maximum Drawdown

Compound interest formula

Geometric mean via nth root

How fast you grow

How much pain you endure

Compare and benchmark strategies

Hinglish (regional understanding)

Intuition Hinglish mein samjho

CAGR aur Maximum Drawdown backtesting ke sabse important performance metrics hain. Agar aap ye nahi samjhe toh strategy compare karna impossible hai.

CAGR matlab "compound annual growth rate"—yeh ek smooth yearly return bata hai jo apka portfolio ka actual growth represent kare. Matlab agar apka paisa 3 saal mein ₹1 lakh se ₹1.8 lakh ho gaya, toh CAGR formula se pta chalega ki equivalent steady annual return kya hai. Formula simple hai: (ending value / starting value)^(1/years) - 1. Yeh geometric mean hai, arithmetic mean nahi—kyunki returns compound hote hain, add nahi hote. Isliye CAGR realistic picture deta hai growth ka.

Maximum Drawdown (Max DD) apko bata hai ki strategy chalate waqt sabse bura pal kya tha. Peak se lowest point tak ka percentage drop—yahi Max DD hai. Agar apka portfolio ₹1.1 lakh tak gaya phir ₹98,000 tak gir gaya, toh Max DD approximately 11% hoga. Yeh emotional pain ko measure karta hai. High CAGR acha lagta hai par agar Max DD 60-70% hai toh koi bhi retail investor dar ke bech dega beech mein. Isliye dono metrics saath mein dekhna zaroori hai—CAGR growth bataye aur Max DD bataye kitna risk lena padega.

Ek achi strategy mein CAGR high hota hai aur Max DD controlled rehta hai. Calmar Ratio (CAGR divided by Max DD) isse quantify karta hai—higher Calmar means better risk-adjusted returns. Jab bhi backtest results dekho, sirf CAGR pe mat jao, Max DD bhi zaroor check karo warna live trading mein ghabra jaoge.

Test yourself — Backtesting Frameworks