# Value at Risk via a Monte Carlo Approach

Value at Risk is the maximum loss on an investment over a given time period with a given confidence level. There are a few different approaches we can take to estimating Value at Risk.

Parametric Approach: A historical simulation based on the distribution of past returns

Nonparametric Approach: No assumptions on the distribution of returns

Monte Carlo Approach: Extrapolating and creating future data to estimate Value at Risk

As implied by the title of this post, we will be estimating Value at Risk via a Monte Carlo approach. What we are doing here is generating future prices via a probability simulation of future outcomes. We will generate the stock movement based on the asset’s historical volatility. With this historical volatility, there will be an element of randomness or a random “shock.” Different Monte Carlo models may require different inputs. By analyzing historical data, we can determine volatility, the average daily return, and drift of an asset. All of these can be used within a Monte Carlo model. Let’s take a look at the formula used to generate the next day’s price.

We are taking the last days price and multiplying it by 1 + a random shock which is created by drawing a sample of the distribution given the historical volatility of an asset.

Let’s dive into the script…

Note for my data source I am using quandl. Let’s examine the output.

Analyzing the outputted histogram, the current stock price is located at the center of the distribution. The Value at Risk would be the current stock price subtracted from the price 5’th percentile price of the distribution. Below is what the Value at Risk metrics would be at different confidence intervals.

#### programmingforfinance

Hi, I'm Frank. I have a passion for coding and extend it primarily within the realm of Finance.

View all posts

• Peter Koppelman says:

Frank –

When you show the price at a confidence interval on the histogram, shouldn’t you have a price below the current stock price and a price above the current stock price? Aren’t confidence intervals usually plus or minus a mean number? Or are you only worried about the lower bound as this is a risk management model and you’re just worried about a potential loss?

I went through your code and I think that there are ways to improve it. I think that it can be faster and more efficient.

• Marcel says:

Dear,

You can have one-sided confidence interval as well, which goes to infinity on the non-interesting side.