VaR calculator
Compare parametric, historical and Monte Carlo Value at Risk and expected shortfall on the same returns.
How it works
Value at Risk is a loss threshold: at 99% confidence over one day, a VaR of 25,000 means losses should exceed 25,000 on about 1 day in 100. Expected shortfall (ES) answers the next question: on those bad days, how much do you lose on average?
The three methods differ in how they model the tail. Parametric assumes a normal distribution, which usually understates fat tails. Historical uses the actual returns, so it is only as good as the window. Monte Carlo here fits a Student-t distribution to the sample's kurtosis and simulates from it.
Assumptions
- Returns are daily, in decimals or percent, and the portfolio value is constant over the horizon.
- Historical VaR scales the 1-day quantile by the square root of the horizon.
- Monte Carlo draws independent daily Student-t returns with degrees of freedom set from the sample's excess kurtosis (between 3 and 30), and sums them over the horizon.
- The sample data is synthetic, with volatility clustering and fat tails. Paste your own returns to replace it.
Show the codePython, runs in the playground
import numpy as np
from scipy.stats import norm, t, kurtosis
rng = np.random.default_rng(7)
returns = rng.standard_t(5, 1000) * 0.011 * np.sqrt(3 / 5) # replace with your daily returns
value, conf, h = 1_000_000, 0.99, 1
mu, sd = returns.mean(), returns.std(ddof=1)
z = norm.ppf(conf)
print(f"Parametric VaR: {value * (z * sd * np.sqrt(h) - mu * h):,.0f}")
q = np.quantile(returns, 1 - conf)
print(f"Historical VaR: {-q * value * np.sqrt(h):,.0f}")
print(f"Historical ES: {-returns[returns <= q].mean() * value * np.sqrt(h):,.0f}")
df = np.clip(6 / max(kurtosis(returns), 0.2) + 4, 3, 30) # Student-t fitted by moments
sims = mu + sd * np.sqrt((df - 2) / df) * t.rvs(df, size=(50_000, h), random_state=1).sum(axis=1)
print(f"Monte Carlo VaR (t, df={df:.1f}): {-np.quantile(sims, 1 - conf) * value:,.0f}")
Questions
Which VaR method is best?
None on its own. Historical captures fat tails but depends on the window; parametric is smooth but assumes normality; Monte Carlo is flexible but only as good as the fitted model. Banks compare several and backtest them.
Why is expected shortfall larger than VaR?
ES averages the losses beyond the VaR threshold, so it is always at least as large. Regulators now prefer ES because it reflects how bad the tail is, not just where it starts.
Can I scale 1-day VaR to 10 days with the square root of 10?
Only if returns are independent and identically distributed. Volatility clustering and autocorrelation make the square-root rule a rough approximation.
Is my data uploaded anywhere?
No. Everything runs in your browser.
Educational use only, not investment advice. Results depend on the model's assumptions listed above and on your inputs. Calculations run in your browser and nothing you enter is sent to a server.