Max drawdown measures largest peak-to-trough decline. Critical for tail risk—it captures worst-case, unlike symmetric volatility.
MaxDrawdown = (Trough - Peak) / Peak
// Calculate maximum drawdown from price series
function maxDrawdown(prices) {
let maxDD = 0;
let peak = prices[0];
for (const price of prices) {
if (price > peak) {
peak = price; // New high found
}
const dd = (peak - price) / peak;
if (dd > maxDD) {
maxDD = dd; // New max drawdown
}
}
return maxDD;
}
// GBM simulation for price path
function simulateGBM(S0, mu, sigma, T) {
const dt = T / 60; // monthly steps
const prices = [S0];
let S = S0;
for (let i = 0; i < 60; i++) {
const drift = (mu - 0.5 * sigma * sigma) * dt;
const shock = sigma * Math.sqrt(dt) * randn();
S = S * Math.exp(drift + shock);
prices.push(S);
}
return prices;
}