A Practical Guide to Value at Risk Using Python
A Practical Guide to Value at Risk Using Python
Every portfolio carries risk. The question is not whether something can go wrong it can and it will but how much can go wrong, and how often. Value at Risk, or VaR, is the quantitative answer to that question.
In this article I’ll walk through three distinct approaches to calculating VaR – Historical Simulation, Parametric (Normal and Student-t), and Monte Carlo – using a real 6-asset US/India equity portfolio. I’ll also show how to backtest each model so you know which one to trust.
All code is in Python. The full implementation is on my GitHub.
- What Is Value at Risk ? And Why Does It Matter?
- VaR at the 95% confidence level means: on 95 out of 100 trading days, your portfolio loss will not exceed this number. The remaining 5 days the tail are where things get interesting, and dangerous.
- Three parameters define every VaR calculation:
- Confidence level – typically 95% or 99%. Higher confidence = larger VaR estimate.
- Time horizon – 1-day VaR is most common for trading desks. 10-day for regulatory capital.
- Portfolio composition – weights, correlations, and the return distribution of each asset.
For this project I used a 6-asset portfolio: AAPL, GOOGL, TSLA on the US side and RELIANCE.NS, TCS.NS, INFY.NS on the Indian side with live USD/INR FX conversion to normalise returns into a single currency.
- Method 1 : Historical Simulation
Historical simulation is the most intuitive approach. Take the last N days of actual portfolio returns, sort them, and read off the loss at your chosen percentile. No distribution assumption required the data speaks for itself.
Pros
- No distribution assumption. Captures fat tails, skew, and real market behaviour automatically.
- Simple to implement and explain to non-technical stakeholders
Cons
- Entirely backward looking. A regime shift (new volatility environment) won’t show up until it’s already in your historical window.
- Requires a long history typically 250+ trading days to produce stable estimates.
- Method 2 – Parametric VaR (Normal and Student-t)
Parametric VaR assumes returns follow a known distribution. The Normal distribution is the standard starting point you estimate mean (μ) and standard deviation (σ) from historical data, then use the distribution’s quantile function to compute VaR analytically.
Student-t Distribution
Financial returns are not Normal they have fat tails. A daily move of 4 standard deviations happens far more often in markets than the Normal distribution predicts. The Student-t distribution adds a degrees-of-freedom parameter (ν) that controls tail weight lower ν = fatter tails.
Fit Student-t to returns
In my portfolio, the Student-t model consistently produced higher VaR estimates than Normal – because Indian equity returns (RELIANCE, TCS, INFY) showed significant excess kurtosis. The Normal model was underestimating tail risk.
- Method 3 – Monte Carlo Simulation
How It Works
Monte Carlo VaR simulates thousands of hypothetical future return scenarios by sampling from a fitted distribution, then computes VaR from the simulated loss distribution. It is the most flexible method and the most computationally intensive.
With 100,000 simulations, the Monte Carlo estimate converges closely to the Parametric Normal result – because both sample from the same Normal assumption. The real power of Monte Carlo comes when you use non-Normal distributions, regime-switching models, or correlated multi-asset simulations as the sampling engine.
- Backtesting : How Do You Know If Your Model Is Right?
A VaR model that has never been validated is just an assumption wearing a number. Backtesting checks whether your model’s VaR breaches days when actual loss exceeded VaR occurred at the rate the model predicted.
Kupiec POF Test
The Kupiec Proportion of Failures (POF) test checks whether the observed breach rate is statistically consistent with the expected rate. At 95% VaR, you expect 5% breaches. If your model shows 12% breaches, something is wrong.
Christoffersen Test
The Christoffersen test goes further it checks not just the breach rate but whether breaches are clustered in time. A good VaR model should produce independent breaches. If you breach on Monday and Tuesday and Wednesday, your model is not capturing volatility clustering – and that is a risk management failure, not just a statistical one.
In my results: Historical VaR passed Kupiec but failed Christoffersen – breaches clustered during the March 2020 and May 2022 drawdown periods. The Student-t model passed both tests across all 6 assets
- Results – What the Numbers Said
Across the 6-asset US – India portfolio, the three methods produced meaningfully different estimates:
Asset: AAPL (95% confidence, 1-day horizon)
- Historical Simulation: −1.84%
- • Parametric Normal: −1.71%
- • Parametric Student-t: −2.03% ← highest, most conservative
- • Monte Carlo (100K): −1.73%
- The Student-t model consistently produced the most conservative (largest) VaR estimates – appropriate for a portfolio with Indian equity exposure where return distributions showed excess kurtosis (fat tails).
- Key finding: The Normal distribution underestimates tail risk in Indian equity returns. A risk manager using only the Parametric Normal model would be systematically underestimating their downside exposure on high-volatility days.
- What I Learned – And What Comes Next
Three things that surprised me during this project:
- Distribution choice matters more than method choice. The gap between Normal and Student-t VaR was larger than the gap between Historical and Parametric methods. Getting the tail assumption right is more important than which computational approach you use.
- Backtesting is not optional. Without Kupiec and Christoffersen tests, I would have accepted the Historical model as adequate. The Christoffersen test revealed clustering that the raw breach count missed entirely.
- Indian and US equity returns behave differently. US returns (AAPL, GOOGL) fit the Normal assumption more closely than Indian returns (RELIANCE, TCS) which showed higher kurtosis and required the Student-t model to produce well-calibrated VaR.
- This project feeds directly into my B.Tech Major Project research paper on downside risk optimisation – the next step is extending this VaR framework into CVaR (Conditional Value at Risk) and building a Mean-CVaR efficient frontier. That work is underway with my supervisor, Dr. Atul Tripathi, at USAR Delhi.
Code & Resources
Full implementation with data pipeline, all three VaR methods, backtesting, and visualisation dashboards is available on GitHub.
If you found this useful or have questions about the methodology, feel free to connect on LinkedIn or leave a comment.
Tags: #DataScience. #Python. #RiskAnalytics. #QuantitativeFinance. #Statistics. #VaR. #MachineLearning
– Tauseef Ahmad Khan · New Delhi, India · 2025
메타데이터
- post_id
- d025d1fa737f
- slug
- a-practical-guide-to-value-at-risk-using-python-d025d1fa737f
- url
- https://medium.com/@khantauseefahmad18/a-practical-guide-to-value-at-risk-using-python-d025d1fa737f
- canonical_url
- https://medium.com/@khantauseefahmad18/a-practical-guide-to-value-at-risk-using-python-d025d1fa737f
- author_url
- https://medium.com/@khantauseefahmad18
- status
- ok
- fetched_at
- 2026-06-11 05:11:55