# Historical Value at Risk With Python

Background:

Value at risk is the maximum loss possible with a given level of confidence over a predetermined time frame. This post will specifically cover historical VaR, or nonparametric method due to the fact we are using prior data to estimate our Value at Risk metric. Most of us will likely be familiar with the concept of a normal distribution. If we calculate periodic returns for an asset, we can sort the returns in ascending order and plot them on a histogram as such. We can access different percentiles of the distribution without physically creating the histogram. The histogram better illustrates Value at Risk in the traditional sense.

What the confidence interval means:

Typical confidence intervals chosen for Value at Risk are 95%, 99%, and 99.99%, though they are not limited to these numbers. When you hear say this is the Value at Risk of an investment at a 95% confidence level, they are really saying they are 95% confident the losses won’t exceed the outputted number. So with a 95% confidence level, this implies we choose the 5’th percentile of the distribution of returns. This also implies the other 5% of the time they can expect the losses on the investment to exceed the outputted value. One also needs to examine the frequency of the losses exceeding the Value at Risk metric also. Since we cover a historical approach, it may not be as fitting to use this model as an example, though it can still be applicable. For example, our model may estimate a one day Value at Risk of -2.16%. We can do some simple math and calculate the number of days that the losses exceed the Value at Risk calculated. If there are 252 days of returns, then 0.05 (95% confidence) multiplied by 252 total days would come out to 12.6 total days. If the Value at Risk is exceeded more than 12.6 times (returns go below VaR) then the model will likely need to be reevaluated. This is usually examined in a backtest which is beyond the scope of this post.

Note: One major assumption of estimating value at risk with a nonparametric approach is that the returns are normally distributed

Creating a model in Python:

Let’s jump into Python to analyze VaR on a historical level. Note all graphs will represent the 95% confidence VaR.

Single Asset VaR:

Multi-Asset VaR: