Comparing equity curves: rebase first, measure drawdown before sampling
DEV Community

Comparing equity curves: rebase first, measure drawdown before sampling

Plotting several investment curves sounds like a call to plot(). The bug usually arrives before that line: one series already includes dividends and another doesn't, or each has a different start date.

Here's the data-handling lesson behind a Korean chart I published using a common starting balance.

Align timestamps and return definitions

Pick either total-return series (distributions reinvested) or price series for all the benchmarks, and label the choice. In a test comparing simulated portfolios to S&P 500, Nasdaq-100, and Dow benchmarks, the benchmark variant matters as much as the index name.

Treat unmatched timestamps as a data quality question instead of silently replacing missing marks with zeros.

In the small example below, the synthetic inputs are already on common trading dates and do not need adjustments. If your inputs are intraday records, decide the date boundary and aggregation before applying this code.

def rebase(points, initial=10_000):
    if not points or any(value <= 0 for value in points):
        raise ValueError("A positive, nonempty value series is required")
    return [initial * value / points[0] for value in points]

def max_drawdown(points):
    if not points or any(value <= 0 for value in points):
        raise ValueError("A positive, nonempty value series is required")
    peak = points[0]
    worst = 0.0
    for value in points:
        peak = max(peak, value)
        worst = min(worst, value / peak - 1)
    return worst

path = rebase([100, 50, 110])
assert path == [10_000, 5_000, 11_000]
assert max_drawdown(path) == -0.5
assert max_drawdown([path[0], path[-1]]) == 0

Measure drawdown before sampling

An interim crash from 100 to 50 disappears if you only keep endpoints. The year-end curve is still useful as a visual summary; label it as such and calculate the drawdown metric from the finest consistent data available.

A logarithmic chart needs positive levels; the relative drawdown formula doesn't need the plot to be logarithmic.

Add two checks before sharing the graph

  • Identical scales: rebasing a column that is just another column times a constant should produce the same path. That's a unit test, not a judgment about performance.
  • No upside from unavailable history: if a series wasn't observable at the start of your comparison, don't backfill it with today's ingredients and call it history. Label any spliced proxy and when it begins.

The underlying portfolio implementations aren't needed to reproduce these plotting checks. The data definitions, observation frequency, and a tiny synthetic regression test are enough.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.