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
}