Monte Carlo Value at Risk and Inverse-CDF Sampling
Summary
The document outlines a basic Monte Carlo procedure for estimating single-asset Value at Risk: choose a return distribution, estimate its parameters, simulate returns, revalue the position under each scenario, and read the loss quantile for the chosen confidence level. It explains inverse-transform sampling, in which a uniform random draw is mapped through the inverse cumulative distribution function; a gamma quantile function is given as an implementation example.
The answer confirms this sampling principle and notes that dedicated algorithms may be preferable when inverse CDF evaluation is difficult. It also introduces importance sampling for tail-focused estimation: draw more often from regions that matter to the VaR estimate and weight observations by the ratio of the target density to the sampling density. This may reduce estimator variance, but the document does not provide a validated VaR comparison. The result depends on the assumed return distribution, parameter estimates, scenario count, and correct weighting; the gamma assumption itself is presented by the questioner, not justified by evidence.
Key ideas
- A Monte Carlo VaR estimate simulates market scenarios and takes the corresponding tail quantile of revalued positions.
- Inverse-transform sampling maps uniform draws through the chosen distribution's inverse CDF.
- Distribution-specific sampling algorithms can be useful when inverse CDF calculation is difficult.
- Importance sampling targets low-probability regions and uses density-ratio weights to estimate tail quantities.
- The chosen return model and its parameter estimates are key sources of uncertainty.
Tags
Full text
# Computing Montecarlo VaR for a single asset
# Computing Montecarlo VaR for a single asset
I'm trying to understand the procedure to compute the Value-at-Risk for a single asset by implementing the Montecarlo technique.
Here it follows the procedure step-by-step in 5 points:
- selecting the probability density function f(x) which best approximates the distribution of the market returns
- estimating the parameters for the selected distribution f(x)
- simulating N scenarios from the distribution f(x)
- calculating the position's market value for each scenario
- cutting off the resulting probability distribution at the percentile corresponding to the desired confidence level
First of all, I would like to understand whether the procedure is theoretically correct; according to you, is this process correct to compute the VaR?
Moreover, for the point (3), I broke down such point in 2 sub-steps:
- extracting a number u from the Uniform distribution
- computing the value x, such that x = $F^{-1}$(u)
How can I compute properly the inverse cumulative distribution in order to get the value $F^{-1}$(u)?
I did it by using the quantile SAS function within the following data step, by assuming that the returns follow a Gamma distribution, $\Gamma(\alpha,\theta)$, where $\alpha$ is the shape parameter and $\theta$ the scaling parameter.
The data step is as follows:
> `data distribution_sample (keep = _U_ x); call streaminit(&seed.); /* (3) simulate x scenarios from the selected distribution */ do i = 1 to %eval(10*&nmc.); /* Extracting a number _U_ from the uniform distribution */ _U_ = rand("Uniform"); x = QUANTILE('GAMMA', _U_,&alpha.,&theta.); /*the QUANTILE function returns the inverse of the CDF function*/ output; end; run; `
```
data distribution_sample (keep = _U_ x);
call streaminit(&seed.);
/* (3) simulate x scenarios from the selected distribution */
do i = 1 to %eval(10*&nmc.);
/* Extracting a number _U_ from the uniform distribution */
_U_ = rand("Uniform");
x = QUANTILE('GAMMA', _U_,&alpha.,&theta.); /*the QUANTILE function returns the inverse of the CDF function*/
output;
end;
run;
```
According to you, is correct such procedure to solve the step (3)?
Thanks all in advance!!
## Answer by Attack68 (score 1)
https://quant.stackexchange.com/a/42457
The process you describe of random sampling from a distribution is correct. Calculate a uniform random variable $u$ and then convert that to a value $x$ by requiring that $x$ is the minimum value for which $F(x) \geq u$. Then $x$ can be said to be sampled from $f(x)$. You are right that in practice this can be hard depending upon the underlying $f(x)$. Take, for example, the normal distribution. The box-muller algorithm is an effective and accurate way to sample from this distribution but it is a sufficiently clever (in my opinion) concept that highlights the difficult in generalising the process. Of course there are numerical, and computationally intensive ways I'm sure but they don't necessarily scale so often sampling algorithms have been developed for different distributions. Indeed the gamma distribution, I'm sure will have its own its own implementation: http://www.hongliangjie.com/2012/12/19/how-to-generate-gamma-random-variables/
When sampling you should be concerned about the variance of your estimator. One technique to reduce the variance of your estimator (and thereby have a higher notion of confidence it is predictive power of your population statistic) is to use importance sampling. When sampling a very low probability of events (and hence infrequently sampled values) might contribute a reasonably large amount of the expected value (for example very low probability of complete default on bonds). In these cases sampling more frequently from the lower probabilities but scaling the results according to the true distribution yields a more consistently accurate estimator.
Edit:
In your script you explicitly generate samples from the $\Gamma(\alpha, \theta)$ distribution using the quantile for a uniform RV. You don't explicitly show any code that does anything with your sample, but presumably calculate some profit and loss value assuming that market movement. But lets say that specific points of interest are in the regions of the distribution which have low pdf, i.e. around zero perhaps and in the right hand tail. What you can do is generate samples from distributions that have higher density in those regions. Suppose instead you generated samples from a normal distribution, $\mathcal{N}(\alpha \theta, 2k\theta^2)$ you can obtain the ratio: $\frac{f(x)}{g(x)}$, where f(x) is your underlying true (gamma) distribution pdf and g(x) is your sample (normal) distribution pdf. Most often this technique is used to calculate means and you multiply all data values by this fraction to obtain a weighted average.
Now in your case when you are attempting to find the VaR you are interested in say the lowest 5% of values. If you sampled from the Gamma distribution 100 times and ordered your values you would progress 5 along and read out that value: you have inherently assigned each datapoint the unit value 1 and progressed until the sum of 5. When using importance sampling try assigning weights to your values by the above ratio. You will get more samples in the wider regions but their weight is lower so to discover the 5% quantile you might take more into account:
Sampling 100 from Gamma:
weight: [1,1,1,1,1,1,......]
pnl: [1,3,5,7,8,9,10,11,....] Var = 9
Sampling from Normal:
weight: [0,0,0.1,0.5,0.6,0.7,0.8,0.9,0.9,0.9,0.9,0.95,...]
pnl: [-100,-100,0.1,0.4,0.5,0.8,1,1,2,4,7,8...] Var = 4.
The art is of course choosing a sample distribution that optimises the lowest variance and is computationally efficient. Wiki has a good page on this.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.