This project implements risk modeling for a stock portfolio using three different methods: Historical VaR & CVaR, Parametric VaR & CVaR, and Monte Carlo Simulation. It also provides a detailed analysis of the portfolio's returns distribution and evaluates risk at a 95% confidence level.
Risk management is an essential aspect of portfolio management, and this project focuses on calculating and visualizing risk using various techniques:
- Value at Risk (VaR): Measures the maximum potential loss in value of the portfolio within a given confidence level.
- Conditional Value at Risk (CVaR): Estimates the average loss beyond the VaR threshold.
- Monte Carlo Simulation: Uses random sampling to simulate potential future portfolio returns, allowing us to assess risk based on a large number of scenarios.
The stock portfolio includes four assets: Apple (AAPL), Meta (META), Citigroup (C), and Disney (DIS). The risk metrics are calculated at a 95% confidence level.
The Historical VaR is calculated by finding the 5th percentile of the portfolio’s returns:
The Conditional Value at Risk (CVaR) is the average loss in the tail of the distribution beyond the VaR threshold:
The Parametric VaR is based on the assumption that returns follow a normal distribution. It is calculated using the mean 


Where 

The CVaR is calculated by averaging the expected returns below the VaR level:
The Monte Carlo Simulation models potential future outcomes of the portfolio by randomly sampling returns from a normal distribution and simulating a large number of scenarios. The portfolio returns at each time step are calculated as a weighted sum of the returns of the individual assets:
Simulated VaR and CVaR are calculated from the portfolio returns in the simulated scenarios.
Data for this project was retrieved from Yahoo Finance for the following tickers: AAPL, META, C, and DIS. The data covers the past year and includes the adjusted closing price for each asset.
df = yf.download(['AAPL','META', 'C', 'DIS'], start=start_date, end=end_date)['Adj Close']The data is then cleaned by dropping any missing values and calculating the daily percentage change in the prices.
The historical VaR is calculated by finding the 5th percentile of the portfolio’s returns.
var = port_returns.quantile(q=1-confidence_level)
cvar = port_returns[port_returns <= var].mean()The results are displayed as follows:
Historical VaR at 0.95 confidence level: -1578.54 (-1.58%)
Historical CVaR at 0.95 confidence level: -2283.19 (-2.28%)
The parametric VaR is calculated using the Z-score for a 95% confidence level and the portfolio's standard deviation and mean returns.
z_score = norm.ppf(q=1-confidence_level)
var = - (norm.ppf(confidence_level)*port_std_dev - port_mean_return)
cvar = 1 * (port_mean_return - port_std_dev * (norm.pdf(z_score)/(1-confidence_level)))The parametric VaR and CVaR results are:
Parametric VaR at 0.95 confidence level: -1597.35 (-1.60%)
Parametric CVaR at 0.95 confidence level: -2041.27 (-2.04%)
In the Monte Carlo Simulation, 400 scenarios are simulated to predict the portfolio’s future returns. The simulations use a Cholesky decomposition of the covariance matrix to generate correlated returns for each stock in the portfolio.
L = np.linalg.cholesky(cov_matrix)
daily_pct_change = meanM + np.inner(L, Z)Monte Carlo VaR and CVaR are calculated from the simulated portfolio returns:
Monte Carlo VAR at 95% confidence level: $108473.76 (-1.57%)
Monte Carlo CVA at 95% confidence level: $102057.64 (-2.02%)
The risk measures for the portfolio were calculated using three different methods:
- Historical VaR and CVaR: Estimates the risk based on actual historical data.
- Parametric VaR and CVaR: Assumes returns are normally distributed and calculates risk using statistical parameters.
- Monte Carlo Simulation: Simulates future portfolio outcomes based on random sampling and estimates risk from simulated scenarios.
Historical VaR: -1578.54
Parametric VaR: -1597.35
Monte Carlo VaR: -108473.76
-
Adjusted Close Price for Sample Stock Tickers
- Displays the adjusted closing price for AAPL, META, C, and DIS over the past year.
-
Apple Percentage Change Histogram
- A histogram of daily percentage changes for Apple.
-
Portfolio Returns Distribution
- A histogram showing the distribution of portfolio returns, with VaR and CVaR marked.
-
Monte Carlo Simulation of Portfolio Change
- A plot showing the simulated portfolio percentage changes, with VaR and CVaR levels.
- Assumption of Normality: The parametric VaR assumes that returns follow a normal distribution, which may not capture extreme market events.
- Monte Carlo Assumptions: While Monte Carlo simulations are powerful, they rely on the assumption that historical data and volatility patterns will continue into the future.
- Data Quality: The results are sensitive to the data used. More granular data and longer time frames could provide a more accurate risk analysis.
- Implementing more sophisticated methods like GARCH models for volatility forecasting.
- Enhancing Monte Carlo simulations with more realistic models for asset returns.
- Extending the analysis to include more assets and test the portfolio under different market conditions.
This project demonstrates how to calculate and visualize key risk metrics for a stock portfolio using historical, parametric, and Monte Carlo simulation methods. The results provide a comprehensive view of the potential risks faced by the portfolio and can be used by investors to manage exposure to market fluctuations.









