VaR estimates maximum loss over a horizon at a given confidence. A 1-day 95% VaR of $10K means 95% chance you won't lose more than $10K in a day.
// Parametric VaR calculation
function calculateVaR(V, sigma, T, confidence) {
const zScores = { 90: 1.282, 95: 1.645, 99: 2.326 };
const z = zScores[confidence];
// VaR = V × σ × √T × z
const varAmount = V * sigma * Math.sqrt(T) * z;
return varAmount;
}
// Example: $1M portfolio, 2% daily vol, 1 day, 95%
calculateVaR(1000000, 0.02, 1, 95); // returns $32,900