Abstract: This paper reports our estimates of the Value at Risk using Monte Carlo simulations for which we developed a computer program. Our approach involves obtaining Monte Carlo parameters by fitting real historical data of different periods to probability distributions. We applied the algorithm to the WIG20 and mWIG40 stock indices, and performed simulations for the Value at Risk at 95% and 99% confidence intervals over six estimation periods ranging from 1 trading day to 250 trading days. This approach was evaluated using the percentage failures and the Kupiec Proportion of Failures test. Our results indicate that this method is highly influenced by the choice of past historical and estimation period lengths considered. Overall, we observed that the Monte Carlo computational scheme is a reliable method for quantifying VaR when parametrized well

<a href="https://dx.doi.org/10.15611/fins.2019.2.05">DOI: 10.15611/fins.2019.2.05</a>
<p>JEL Classification: G170</p>
<p><span>Keywords:</span> Monte Carlo, Value at Risk, WIG20, mWIG40, Kupiec, simulations.</p>
<h2>1. Introduction</h2>
<p>The increase in computational power available to people has led to the growth of computational finance. Due to
certain characteristics of some data sets, e.g. example incompleteness, or the objectives of the project, like stock
price predictions, it was natural to merge analytical and numerical tools. One of the applications of computational
finance is to perform risk analysis. The Value at Risk (VaR), recommended by the Basel II agreement [Basel II 2004],
is frequently used as a market risk measure. As VaR helps quantify the potential loss of an investment and
assigns a certain probability to the loss, it plays an important part in the finance industry. This forms our
motivation to study VaR. In common usage, there are three ways to measure VaR – the historical method, the
variance-covariance method, and the Monte Carlo simulations [Holton 2014].</p>
<p>The aim of this paper is to perform Monte Carlo computer simulations to measure the VaR for different investment
periods, past period lengths, and with different confidence intervals. In the following section, we present the
theoretical and computational tools used to estimate the VaR. Section 3. deals with the simulation results for the VaR
with different parameters. Our results show that the Monte Carlo approach works best in estimating VaR at 95% and 99%
with historical window of 500 trading days (2 years) for estimation windows of under one month. We also observe
a dependence of the estimation window length and the historical period on the VaR. The approach presented here is
very general and can be extended to different applications with appropriate parameters.</p>
<h2>2. Theory and computational methods</h2>
<p>In this section we briefly describe the theory used to construct our numerical model – Value at Risk, the Monte Carlo
method, and the computer algorithm.</p>
<h3>2.1. Value at Risk</h3>
<p>We wish to measure the Value at Risk (VaR), which is defined as the maximum possible loss, or equivalently the most
“negative” price change, whose probability is within a pre-defined confidence interval over a pre-defined
time horizon (investment period). This can be better understood with this example: if a portfolio has a VaR
of 700 PLN over the investment period of one week with confidence of 95%, it implies that the portfolio has at most
a 5% chance of losing 700 PLN or more over a period of one week. Equivalently, there is a 95% chance
that the losses over one week will not be greater than 700 PLN for the given portfolio.</p>
<p>This definition of VaR is non-constructive in that it specifies a property that VaR should have, but not on how
to compute VaR. As a result, there are different ways proposed to compute it [Holton 2014]. Additionally the
definition allows use of VaR in risk management and risk measurement. For our purposes, we use the VaR to measure the
risk of the WIG20 and mWIG40 indices [WIG], which correspond to the 20 largest and the next 40 largest stocks
respectively in terms of market capitalization, in the Warsaw Stock Exchange. The stocks within these indices would be
a crucial part of investment portfolios within Poland by different portfolio managers, and so these indices
provide a good application case study.</p>
<h3>2.2. Monte Carlo methods</h3>
<p>We chose the Monte Carlo method [Glasserman 2003] to simulate the WIG20 and mWIG40 values for the different
investment periods of interest. The main advantage of this method is that one can simulate the different sources of
uncertainty that affect these indices.</p>
<p>Monte Carlo methods were initially developed for the physics and chemistry communities. The advantage to deal with
probabilistic events, such as Brownian motion, was a major factor in using these methods in various areas of
finance, such as corporate finance [Savvides 1994], portfolio optimization [Detemple et al. 2003], and risk analysis
[Evans, Olson 1998]. These methods are widely used in dealing with quantities that have a high degree of
uncertainty, and where traditional analytical ways might fail. Our approach uses Monte Carlo to simulate the uncertain
price changes and the uncertainty is determined by real historical data.</p>
<p>Two major limitations of Monte Carlo methods in general are their sensitivity to the model hyper-parameters
(distributions etc.), and the computational costs (multiple iterations and runs).</p>
<h3>2.3. Program algorithm</h3>
<p>Here we present the main essence of the program that calculates the VaR for the WIG20 and mWIG40 indices with Monte
Carlo simulations. This program was fully implemented by us using the Python language. The libraries used for reading
the data, fitting the data, simulating the prices, and plotting the results were ‘pandas’, ‘numpy’, ‘scipy.stats.norm’
and ‘matplotlib.pyplot’.</p>
<ul>
<li>We chose the daily closing prices of the WIG20 and mWIG40 from 02 April 2007 to 22 December 2017 as the objects of
study. The large number of datapoints provides a relatively large sample to test our program for different
investment and historical period lengths.</li>
<li>The uncertainty in the index value is assumed to appear through the relative price change over each day. In our
computations, we confirmed the normal distributions of the relative price change, through the Shapiro-Wilk [Shapiro,
Wilk 1965] and Kolmogorov-Smirnov [Stephens 2012] tests. We also observed that the percentage price changes have
a mean of around 0% and a standard deviation of around 1%. However, to better represent the trends in our
data, for each ‘buying’ day we fit the mean and standard deviation of our normal distribution to the past
(historical) mean and standard deviation for period lengths of 250, 500 and 1250 trading days. These correspond to
learning periods of approximately 1, 2 and <br />5 years.</li>
<li>For each investment period we consider (1, 5, 10, 22, 125 and 250 trading days), we simulated 50 000 possible
prices in the future for each historical period length. We emphasize that these prices are only hypothetical and are
obtained by generating random numbers corresponding to a normal distribution with a mean and
a standard deviation that was fit to the chosen past period length. For comparison all results will be shown
from 2012 (to adjust for all past period lengths). </li>
<li>We then sorted the price changes over the investment period in ascending order. The VaR for a given
investment period and a given confidence interval is simply the percentile value of the price changes for that
investment period. For example, the VaR for an investment period of 22 trading days, with the confidence interval of
95% is the 2500th or the (1-0.95)*50000th value of the sorted price changes over 22 trading days. </li>
<li>To verify that the VaR obtained for the different investment periods follow the definition that the price changes
will be above (loss = negative price change) the VaR with a probability given by the confidence interval, we
performed backtesting. Backtesting is the process of comparing the actual price change over an investment period
with the hypothetical (simulated) price change at the VaR over the corresponding investment period.</li>
<li>Finally, all the different parameterizations of the model were evaluated using percentage crossings and the Kupiec
Proportion of Failures (POF) test [Kupiec 1995].</li>
</ul>
<h2>3. Simulation results </h2>
<p>This section deals with our Monte Carlo simulations for the VaR at different confidence intervals for the different
estimation periods. Backtesting results for the VaR at confidence intervals of 95% and 99% over estimation periods of
1, 5, 10, 22, 125 and 250 trading days are shown graphically. These chosen estimation periods correspond to investment
periods of approximately one day, one week, two weeks, one month, six months and one year respectively. Like most
investment risk measures, the price change is of more interest than the price itself, since, from the investor’s
perspective, profits and losses matter. For this reason, the figures plot theoretical VaR and actual price changes for
comparative purposes. </p>
<p>In Figure 1 we plot the daily moving averages for different historical periods for the two indices of interest. We
observe that longer time periods tend to produce smoother curves. However, longer time periods are less sensitive to
‘recent’ information, which can cause ‘lags’ in fitting the mean and standard deviation (see Figure 2). The latter
effect can be seen in Figure 2, where a sudden drop in the blue curve (mid-2012) is shifted to the right and
lessened in intensity in the two curves (mid-2013 and mid-2016 for the orange and green curves respectively).</p>
<p>Now we present the comparison curves between the estimated VaR and actual price changes. The actual price changes are
plotted in red, and the Monte Carlo results are shown for historical periods of 250, 500 and 1250 TD in the other
colors. We highlight that each point on the red curves corresponds to actual price changes, and the points on the
blue, orange and green curves correspond to price changes between real and estimated prices over the corresponding
prediction period. The estimations were obtained from averages and standard deviations computed over the historical
period.</p>
<p><span><img src="05-Pasieczna-web-resources/image/13531.png" alt="13531.png" /></span> </p>
<p><span><img src="05-Pasieczna-web-resources/image/Pasieczna_r1_fmt.jpeg" alt="Pasieczna_r1.tif" /></span> </p>
<p><span>Fig. 1.</span> Comparison of moving averages of relative price changes for different past period lengths
<br />for the WIG20 (top) and mWIG40 (below) indices</p>
<p>Source: own study.</p>
<p>For the sake of brevity, we restrict ourselves to showing the plots corresponding to prediction periods of 1, 10, 125
and 250 TD. These are chosen to represent prices changes and VaR curves over short, medium and long time-scales.</p>
<p>Figures 3, 5, 7, and 9 present our results for the VaR with 95 confidence intervals for the given indices with
estimation periods of 1, 10, 125 and 250 TD respectively. We show our VaR results for the VaR with 99% confidence
intervals respectively in Figures 4, 6, 8 and 10 for the chosen estimation periods.</p>
<p>Generally, we see that the simulated curves are below the actual price changes, indicating that our approach captures
investment risk. We observe that the historical period of 250 TD (blue) tends to be higher than that of 500 TD
(orange), which is above that of 1250 TD (green). This implies that larger historical periods tend to overestimate the
risk. It should be pointed out that our results are strictly valid within the time-period considered in the dataset.
Further study of other indices and different time-periods might help to understand this behavior in more detail. </p>
<p><span><img src="05-Pasieczna-web-resources/image/Pasieczna_r2_fmt.jpeg" alt="Pasieczna_r2.tif" /></span> </p>
<p><span>Fig. 2.</span> Comparison of moving standard deviations of relative price changes for different <br />past
period lengths for the WIG20 (top) and mWIG40 (below) indices</p>
<p>Source: own study.</p>
<p><span><img src="05-Pasieczna-web-resources/image/Pasieczna_r3_fmt.jpeg" alt="Pasieczna_r3.tif" /></span> </p>
<p><span>Fig. 3.</span> Comparison of price changes with VaR (95%) for different past period lengths over <br />an
estimation period of 1 trading day for the WIG20 (top) and mWIG40 (below) indices</p>
<p>Source: own study.</p>
<p><span><img src="05-Pasieczna-web-resources/image/Pasieczna_r4_fmt.jpeg" alt="Pasieczna_r4.tif" /></span> </p>
<p><span>Fig. 4.</span> Comparison of price changes with VaR (99%) for different past period lengths over <br />an
estimation period of 1 trading day for the WIG20 (top) and mWIG40 (below) indices</p>
<p>Source: own study.</p>
<p><span><img src="05-Pasieczna-web-resources/image/Pasieczna_r5_fmt.jpeg" alt="Pasieczna_r5.tif" /></span> </p>
<p><span>Fig. 5.</span> Comparison of price changes with VaR (95%) for different past period lengths over <br />an
estimation period of 10 trading days for the WIG20 (top) and mWIG40 (below) indices</p>
<p>Source: own study.</p>
<p><span><img src="05-Pasieczna-web-resources/image/Pasieczna_r6_fmt.jpeg" alt="Pasieczna_r6.tif" /></span> </p>
<p><span>Fig. 6.</span> Comparison of price changes with VaR (99%) for different past period lengths over <br />an
estimation period of 10 trading days for the WIG20 (top) and mWIG40 (below) indices</p>
<p>Source: own study.</p>
<p><span><img src="05-Pasieczna-web-resources/image/Pasieczna_r7_fmt.jpeg" alt="Pasieczna_r7.tif" /></span> </p>
<p><span>Fig. 7.</span> Comparison of price changes with VaR (95%) for different past period lengths over <br />an
estimation period of 125 trading days for the WIG20 (top) and mWIG40 (below) indices</p>
<p>Source: own study.</p>
<p><span><img src="05-Pasieczna-web-resources/image/Pasieczna_r8_fmt.jpeg" alt="Pasieczna_r8.tif" /></span> </p>
<p><span>Fig. 8.</span> Comparison of price changes with VaR (99%) for different past period lengths <br />over an
estimation period of 125 trading days for the WIG20 (top) and mWIG40 (below) indices</p>
<p>Source: own study.</p>
<p><span><img src="05-Pasieczna-web-resources/image/Pasieczna_r9_fmt.jpeg" alt="Pasieczna_r9.tif" /></span> </p>
<p><span>Fig. 9.</span> Comparison of price changes with VaR (95%) for different past period lengths over <br />an
estimation period of 250 trading days for the WIG20 (top) and mWIG40 (below) indices</p>
<p>Source: own study.</p>
<p><span><img src="05-Pasieczna-web-resources/image/Pasieczna_r10_fmt.jpeg" alt="Pasieczna_r10.tif" /></span> </p>
<p><span>Fig. 10.</span> Comparison of price changes with VaR (99%) for different past period lengths over <br />an
estimation period of 250 trading days for the WIG20 (top) and mWIG40 (below) indices</p>
<p>Source: own study.</p>
<p>In all the figures shown, we observe that the VaR measure provides a lower threshold for the real (actual) price
changes. For most of the estimation periods considered, the real price changes cross the two thresholds (95% and 99%)
less than the corresponding confidence interval set by VaR. This leads us to believe that the VaR is a reliable
measure of investment risk for the WIG20 and mWIG40 indices.</p>
<p>To obtain a more complete picture of our approach, it is important to compute the percentage of the real price
changes crossing the thresholds set by VaR. For our purposes we present the Kupiec Proportion of Failures test along
with the corresponding percentage crossings in parentheses. </p>
<p>The percentage crossings indicate that in the case of short historical periods (250 TD) used for obtaining the
average and standard deviation, there are more crossings than expected with the VaR confidence intervals. As this
period is increased to 500 and 1250 TD, the percentage crossings drop reaching 0 for many estimation periods. Thus,
our computational algorithm, which combines Monte Carlo simulations with the parameters determined by the historical
data, provides an independent VaR measure.</p>
<p><span><img src="05-Pasieczna-web-resources/image/Pasieczna_r11_fmt.jpeg" alt="Pasieczna_r11.tif" /></span> </p>
<p><span>Fig. 11.</span> Heatmap for Kupiec POF values for VaR (95%) and VaR (99%) for historical period <br />of 250
trading days for the WIG20 (top) and mWIG40 (below) indices (the percentage crossings are provided in parentheses)
</p>
<p>Source: own study.</p>
<p>On the basis of the Kupiec POF test, we observe that the Kupiec likelihood ratios of the models with the historical
period of 250 TD are relatively high, which when analyzed along with the percentage crossings, indicates that the
models perform poorly when the prediction periods are above 125 TD. The best Kupiec likelihood ratios (< 1) are
obtained for the VaR with 99% for historical period of 500 TD and estimation periods of 1, 5 and 10 TD for both
indices. The Kupiec likelihood ratios for all estimation periods with the historical period of 1250 TD are very high,
which combined with the very low percentage crossings, indicates that the risk is overestimated in this model.</p>
<p><span><img src="05-Pasieczna-web-resources/image/Pasieczna_r12_fmt.jpeg" alt="Pasieczna_r12.tif" /></span> </p>
<p><span>Fig. 12.</span> Heatmap for Kupiec POF values for VaR (95%) and VaR (99%) for historical period of 500 trading
days for the WIG20 (top) and mWIG40 (below) indices (the percentage crossings are provided in parentheses) </p>
<p>Source: own study.</p>
<p><span><img src="05-Pasieczna-web-resources/image/Pasieczna_r13_fmt.jpeg" alt="Pasieczna_r13.tif" /></span> </p>
<p><span>Fig. 13.</span> Heatmap for Kupiec POF values for VaR (95%) and VaR (99%) for historical period of 1250 trading
days for the WIG20 (top) and mWIG40 (below) indices (the percentage crossings are provided in parentheses) </p>
<p>Source: own study.</p>
<h2>4. Conclusions and perspectives</h2>
<p>In this work we have calculated the Value at Risk for different confidence intervals over different estimation
periods using the Monte Carlo method. The VaR of the WIG20 and mWIG40 indices were computed at 95% and 99% confidence
intervals over six estimation periods ranging from 1 to 250 trading days, with 50 000 Monte Carlo iterations. The
Monte Carlo parameters were obtained by fitting historical relative price change data of the indices of different
historical period lengths to a normal distribution. </p>
<p>Our results show that the model works best for a historical time period of 500 TD to fit the average and
standard deviation for prediction windows of up to 22 TD. This implies that the approach works for relatively short
prediction horizons compared to the historical time period. Counterintuitively to what one might expect, a longer
historical time horizon degrades the Kupiec POF due to the overestimation of the risk. Additionally, there is no
discernible pattern between the prediction window and the historical time window.</p>
<p>The program developed here is very general and can be easily adapted to study the Value at Risk at different
confidence intervals over different estimation periods for any price index, based on different historical time
periods. Additionally, one can easily modify the algorithm to obtain Monte Carlo simulations with any probability
distribution, which might better reflect the real price changes. While this approach was used to estimate VaR, the
general algorithm can also be extended for similar risk measurements. </p>
<p>In terms of perspectives, the study of different simulation time periods would help avoid over-fitting our model to
specific trends or cycles. It would be fruitful to study the VaR for more stock indices and portfolios. The use of
different probability distributions might help in establishing a stronger understanding, and eventually help in
developing better investment strategies. Additional use of exponential-moving averages instead of simple-moving
averages to emphasize recent events would be helpful, as the model adapts quicker to new information, while reducing
the dependence on long-past events.</p>
<h2>Bibliography</h2>
<p>Basel II, 2004, Basel II: International Convergence of Capital Measurement and Capital Standards: A Revised
Framework, <a href="https://www.bis.org/publ/bcbs107.htm">https://www.bis.org/publ/bcbs107.htm</a> (12.01.2018).</p>
<p>Detemple J.B., Garcia R., Rindisbacher M., 2003, A Monte Carlo method for optimal portfolios, <br />Journal of
Finance, vol. 58, no. 1, pp. 401-446.</p>
<p>Evans J.R., Olson D.L., 1998, Introduction to Simulation and Risk Analysis, Prentice-Hall, Inc., New Jersey, USA.</p>
<p>Glasserman P., 2003, Monte Carlo Methods in Financial Engineering, Springer Science+Business Media, New York, USA.
</p>
<p>Holton G.A., 2014, Value-at-Risk Theory and Practice, Second Edition (self-published), <a
href="https://www.value-at-risk.net">https://www.value-at-risk.net</a> (15.01.2018).</p>
<p>Kupiec P.H., 1995, Techniques for verifying the accuracy of risk measurement models, The Journal of Derivatives, vol.
3, no. 2, pp. 73-84.</p>
<p>Savvides S.C., 1994, Risk analysis in investment appraisal, Project Appraisal Journal, vol. 9, no. 1.</p>
<p>Shapiro S.S., Wilk M.B., 1965, An analysis of variance test for normality (complete samples), Biometrika, vol. 52,
no. 3-4, pp. 591-611.</p>
<p>Stephens M.A., 2012, EDF statistics for goodness of fit and some comparisons, Journal of the American Statistical
Association, vol. 69, no. 347, pp. 730-737.</p>
<p>WIG data <a href="https://stooq.pl">https://stooq.pl</a> (23.12.2017).</p>
<p>METODA SYMULACJI MONTE CARLO <br />W OBLICZANIU WARTOŚCI ZAGROŻONEJ RYZYKIEM (VAR): ZASTOSOWANIE DLA WIG20
I MWIG40 </p>
<p><span>Streszczenie: </span>W niniejszym artykule przedstawiono oszacowanie wartości zagrożonej ryzykiem VaR za
pomocą symulacji Monte Carlo, dla której stworzono program komputerowy. Podejście polega na uzyskaniu parametrów Monte
Carlo przez dopasowanie rzeczywistych danych historycznych z różnych okresów do rozkładów prawdopodobieństwa.
Zastosowano ten algorytm dla indeksów giełdowych WIG20 i mWIG40, dla dwóch przedziałów ufności – wynoszących 95%
i 99%, w sześciu okresach szacunkowych, które wynosiły od 1 do 250 dni pracujących. Aby uzyskać ocenę
wyników symulacji, analizowano procentowy udział niepowodzeń oraz test Kupca. Wyniki te wskazują na duży wpływ
rozpiętości zakresu danych historycznych, a także długości okresów szacunkowych na ocenę symulacji. Stwierdzono,
iż schemat obliczeniowy metody Monte Carlo, przy odpowiedniej parametryzacji, jest wiarygodną metodą określania
wartości zagrożonej ryzykiem VaR.</p>
<p><span>Słowa kluczowe:</span> Monte Carlo, wartość zagrożona ryzykiem, WIG20, mWIG40, Kupiec, symulacje.</p>
</div>