Var Approaches

This article provides a detailed exploration of three different approaches for calculating Value at Risk (VaR) – Historical, Variance-Covariance, and Monte Carlo Simulation. The analysis is based on Nifty data spanning from January 1, 2021, to August 14, 2023, and the confidence level chosen is 99%. Here are the results:

  • Historical VaR: 2.64%
  • Variance-Covariance VaR: 2.17%
  • Monte Carlo VaR: 2.18%

The study offers insights into how these approaches are applied and compares their outcomes in assessing risk.

# Importing libraries

import numpy as np
import pandas as pd
import yfinance as yf

import warnings
warnings.filterwarnings("ignore")

# Getting Historical data of Nifty from Yahoo Finance

df = yf.download('^NSEI', '2021-01-01', '2023-08-14')
df = df[['Close']]
df['returns'] = df.Close.pct_change()

# Calculating Historical VaR

Historical_VaR_99 = df['returns'].quantile(0.01)
print(Historical_VaR_99)

# Calculating Variance - Covariance VaR

mean = np.mean(df['returns'])
std_dev = np.std(df['returns'])
VarianceCovariance_VaR_99 = norm.ppf(0.01, mean, std_dev)
print(VarianceCovariance_VaR_99)

# Calculating  Montecarlo Simulation VaR

np.random.seed(42)
n_sims = 1000000
simulated_returns = np.random.normal(mean, std_dev,n_sims)
Simulated_VaR_99 = np.percentile(simulated_returns,1)
print(Simulated_VaR_99)

Output of the above code