# Simulating the Value-at-Risk with $t$ distributed returns

I want to understand how the value at risk and the simulating the VaR with simple Monte Carlo method. But I want just a confirmation and are welcome any comments, since I don't have the full picture of this calculations.

Let's say that I have an annual asset with one period of margin risk:


library(quantmod)
getSymbols("WILL5000IND",src="FRED")
wilsh <- na.omit(WILL5000IND)
wilsh <- wilsh["2016-01-01/2016-12-31"]
names(wilsh) <- "TR"
y = wilsh
n=length(y)
logret <- diff(log(wilsh))[-1]


Now I calculate the empirical VaR with $$\alpha = 0.05$$

alpha <- 0.05
rvec <- as.vector(logret)
quantile(rvec,alpha)


With result:

        5%
-0.01253343


Fitting the data in a $$t$$-distribution and calculate through maximum likelihood method the parameters are:

t.fit <- fitdistr(rvec, "t")
round(t.fit$estimate,6) mu = t.fit$estimate
sd = t.fit$estimate df = t.fit$estimate


Now the value at risk of the $$t$$-distributed returns is

q = qt(alpha,df=df)
varfit = as.numeric(mu + sd *sqrt((n-2)/n)*q)
varfit


with result:

-0.01183847


now if I am so far right, I want to simulate the value at risk for one day ahead so I am doing:

rvecs <- rep(0,100000)
library(metRology)
for (i in 1:2) {
rvecs <- rvecs+rt.scaled(100000,
mean=t.fit$$estimate, sd=t.fit$$estimate,
df=t.fit$estimate) } VaRsim = quantile(rvecs,alpha);VaRsim  With result:  5% -0.01659703  I don't know if my simulation is correct since the result (from Monte Carlo is not exactly the same). Also I don't know if my methodology is correct. Any help? ## 1 Answer From your statement, now if I am so far right, I want to simulate the value at risk for one day ahead so I am doing: it looks like you want to forecast Value-at-Risk and not just estimate it from the simulation of a Students t-distribution. If you want to forecast your parametric Monte Carlo VaR, you can follow the framework described below. In general, I am confused about your for-loop, since it seems redundant. If you want to verify that you have done your calculations correctly and thus re-simulate returns from a scaled $$t$$-distribution using rt.scaled, you need to simulate much more samples, try around 2 million samples. ## Forecasting parametric Monte Carlo VaR: The idea of forecasting parametric Monte Carlo VaR on the basis of a model $$f(\theta)$$, lies in simulating a large sample of returns (or log-losses) from the "forecasted" model, $$f(\theta_{t\vert t-1})$$ and then estimate the $$\alpha$$-quantile on your simulated data. Here $$\theta_{t\vert t-1}$$ denotes the conditional parameters for time $$t$$ given the information available at time $$t-1$$ and is (generally) the only thing that recursively changes from day to day. A general framework is described below. ### Framework: 1. Convert your price-series to log-returns (or log-losses). 2. From this, estimate the model parameters $$\theta_{t\vert t-1}$$ using the information available today (aka. $$\mathcal{F}_{t-1}$$) via eg. a moving window or an expanding window. Examples are given below: • Moving window: With a window length of 1000 and a log-return series of $$r_1,\ldots, r_{2000}$$, use the first 1000 data-points to estimate $$\hat{\theta}_{1001 \vert 1000}$$ and use the estimated parameters in your model, $$f(\hat{\theta}_{1001 \vert 1000})$$, to simulate a large sample of log-returns. At time $$t=1001$$, estimate the parameters from the series $$\{r_2,\ldots,r_{1001}\}$$ thus keeping the window length fixed and use these parameters to simulate a large sample of log-returns. This is done recursively. • Expanding window: Follows almost the same idea as a moving window instead of fixing the window-length, we just increase it gradually: for time $$t=1000$$ estimate from $$\{r_1,\ldots,r_{1000}\}$$, for $$t=1001$$ do $$\{r_1,\ldots, r_{1001}\}$$ and so on. 3. For each day, find the one-day ahead $$VaR_{t\vert t-1}(\alpha)$$ forecast as the $$\alpha$$-quantile on the simulated data, ie. $$VaR_{t\vert t-1}(\alpha) = F^{-1}_\alpha(\theta_{t \vert t-1})$$. In your case, $$F^{-1}_\alpha(\mu_{t \vert t-1}, \sigma_{t\vert t-1})$$ is the quantile function of a Student's t distribution, where $$\mu$$ and $$\sigma$$ denotes respectively the scale and location parameter. If you want to assess the out-of-sample VaR performance, you can use Failure rates or the unconditional and conditional coverage tests (see for instance the forecasting section of this paper). ## Code illustration for moving and expanding window: The code below illustrates the moving and expanding window. Within both for-loops we estimate the parameters of the Students' t-distribution, where the first for-loop (the moving window) keeps the window length fixed at 500 and the latter (the expanding window) increases the window length by 1 for each iteration. I encourage you to look it through and get a feel for how it works. I hope it helps. #your own code, extended data from 2016 till 2019 library(quantmod) getSymbols("WILL5000IND",src="FRED") wilsh <- na.omit(WILL5000IND) wilsh <- wilsh["2016-01-01/2019-12-31"] n=length(wilsh) logret <- diff(log(wilsh))[-1] * 100 #initialize window length and matrices: win_length <- 500 est_pars_moving <- matrix(0, ncol = 3, nrow = n - window_length) est_pars_expanding <- matrix(0, ncol = 3, nrow = n - window_length) #Moving window estimation: for(i in (win_length+1):n){ est_pars_moving[(i-win_length), ]<-fitdistr(rvec[(i- win_length):(i-1)], "t")$estimate

}

#Expanding window estimation:
for(i in (win_length+1):n){

est_pars_expanding[(i-win_length), ] <- fitdistr(rvec[1:(i-1)], "t")$estimate }  • Your answer is very clear and helpful.Can you demonstrate these two (moving and expanding) windons estimations in R in order to have a better understanding how this is being implemented? – user57440 Feb 20 at 12:42 • @HungryHomer I have added an additional section illustrating the moving and expanding window in R. It is up to yourself to build upon the code and the above framework in order to obtain the VaR forecasts. – Pleb Feb 20 at 13:12 • In order to obtain the VaR in the forecast I can just code  quantile(est_pars_moving ,alpha)? It seems like you are doing a backtesting like estimation to the Monte Carlo model.Am I right ? – user57440 Feb 20 at 13:19 • The output is a matrix with 3 columns for each parameter of$t$distribution.If I take the mean of each column l=apply(est_pars_moving,2,mean) and find the 0.01 quantile of t: qt(0.01,l) – user57440 Feb 20 at 13:41 • @HungryHomer Backtesting is a process of comparing the forecasted/predicted VaR estimates to the realized losses experienced in the test-set (out of sample set). Failure rates and coverage tests are part of backtesting a VaR framework. Thus, forecasting VaR is just one part of backtesting (the other being the comparison of the realized values). The above code estimates the parameters for the$t$-distribution. For each of these parameters you need to simulate a large sample of returns and then calculate the$\alpha\$-quantile on the simulated data and not take quantile of the parameters itself.
– Pleb
Feb 20 at 14:28