Skip to content

A project focused on modeling market risk using Value at Risk (VaR) and Conditional Value at Risk (CVaR) to assess potential losses in a portfolio. The project uses historical simulation and parametric methods to calculate risk metrics and visualize tail risk exposure.

License

Notifications You must be signed in to change notification settings

1Aditya7/VaR-and-CVaR-Modelling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Portfolio Risk Modeling - VaR and CVaR

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.

Introduction

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.

Methodology

Historical VaR & CVaR

The Historical VaR is calculated by finding the 5th percentile of the portfolio’s returns:

Historical VaR

The Conditional Value at Risk (CVaR) is the average loss in the tail of the distribution beyond the VaR threshold:

Conditional VaR

Parametric VaR & CVaR

The Parametric VaR is based on the assumption that returns follow a normal distribution. It is calculated using the mean and standard deviation of the portfolio’s returns, along with the Z-score for the given confidence level :

Parametric VaR

Where is the critical value corresponding to the confidence level. For a 95% confidence level, = 1.645

The CVaR is calculated by averaging the expected returns below the VaR level:

CVaR

Monte Carlo Simulation

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 Acquisition

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.

Approach

Historical VaR & CVaR

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%)

Parametric VaR & CVaR

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%)

Monte Carlo Simulation

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%)

Results

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

Visualizations

  1. Adjusted Close Price for Sample Stock Tickers

    • Displays the adjusted closing price for AAPL, META, C, and DIS over the past year.

    Stock Price Plot

  2. Apple Percentage Change Histogram

    • A histogram of daily percentage changes for Apple.

    Apple Change Histogram

  3. Portfolio Returns Distribution

    • A histogram showing the distribution of portfolio returns, with VaR and CVaR marked.

    Portfolio Returns Distribution

  4. Monte Carlo Simulation of Portfolio Change

    • A plot showing the simulated portfolio percentage changes, with VaR and CVaR levels.

    Monte Carlo Simulation

Limitations and Future Scope

  • 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.

Future Scope:

  • 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.

Conclusions

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.

About

A project focused on modeling market risk using Value at Risk (VaR) and Conditional Value at Risk (CVaR) to assess potential losses in a portfolio. The project uses historical simulation and parametric methods to calculate risk metrics and visualize tail risk exposure.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published