← See Stata 19's new features
Highlights
Historical VaR
Normal-based VaR
Model-based VaR
ARIMA models
EWMA models
ARCH models
See more in financial statistics features
Calculate value at risk (VaR) for assets and portfolios with the new finvalrisk command. Determine the risk of investments using their historical performance, fitting a normal distribution to their returns, or specifying complex time-series models. This feature is a part of StataNow™.
How much we stand to lose from an investment is just as interesting a question as how much we stand to win. For risk-averse investors, potential losses may even carry more weight than potential profits in their decision making.
VaR is an intuitive approach to thinking about potential losses. It typically looks at low-probability, worst-case scenarios over a period of interest and answers the question: how much value could the investment lose?
The answer can be as simple as “the value we have observed this investment lose in the past under such worst-case scenarios” or as complex as fitting a statistical model to the data and forecasting the potential loss.
Stata's new finvalrisk command can estimate VaR percentiles from the historical return distribution, from a normal approximation to this distribution, and from a time-series model of the expected returns.
-> Gambling borrowed cash: How bad could it be?
-> Betting it all on AFH
-> Historical returns and normal approximation
-> An ARMA model for expected returns
-> Modeling volatility
-> Modeling both expectation and variance of returns
Every day, inexperienced investors find what they think is a great opportunity in the stock market and fall for the oldest temptation: they go to the bank and borrow money to buy stocks. After all, their cousin who is good at math told them that the company is a winner! What could possibly go wrong?
Think about their situation for a moment. They bought a risky asset with money that they do not actually have. If the asset grows in value, they are in luck: they sell, pay the bank back, and keep the difference. If the asset stays at its current value, they can at least sell it at the original price and pay back the full amount. But if the asset loses value, they will sell it at a lower price than they paid for it, which means that they will be paying the bank for that loss out of their own pocket.
Gamblers like these will be content to see any gains, even small ones, but they really do not want to see losses. They may not even have the cash to cover them. A VaR analysis can reveal how much trouble they may be getting themselves into.
We have end-of-month stock prices for 25 fictional companies. We list the first five prices for five of the stocks:
. webuse finex (Fictional stock price data) . list aaa-das in 1/5
| aaa afh ard cph das | |
| 1. | 10.00786 10.0088 10.00906 10.00645 10.00926 |
| 2. | 9.967269 10.03054 10.30584 10.15102 10.31771 |
| 3. | 9.889415 10.24619 10.2917 10.03707 10.30525 |
| 4. | 10.02855 10.1483 10.55885 10.2759 10.35527 |
| 5. | 10.02861 10.49291 10.18976 10.1349 10.31676 |
The stock price of Apex Film Holdings (AFH) has been growing steadily over the past year.
. tsline afh in -12/l
But our newbie investor heard that AFH is about to acquire a very popular movie franchise. News of that big acquisition should push AFH's stock price up quickly over a short period of time, so the investor takes out a loan of $10,000 from the bank and buys AFH stock.
VaR analysis is carried out on returns data rather than price data, so let's compute the returns of AFH to get started.
. quietly finreturns afh, simple(r_afh) multiply(100)
These are simple returns multiplied by 100, so an example value of 1.5 means that the stock price grew by 1.5% in a month.
We first look at this asset's past performance.
. summarize r_afh, detail
| AFH |
| Percentiles Smallest 1% -5.519961 -10.59864 5% -3.629369 -7.559971 10% -2.248412 -7.178934 Obs 779 25% -.7257008 -6.951355 Sum of wgt. 779 50% .7337448 Mean .6601578 Largest Std. dev. 2.400168 75% 2.220452 7.148532 90% 3.613799 7.453087 Variance 5.760808 95% 4.442117 8.208542 Skewness -.2865115 99% 6.612686 8.662755 Kurtosis 4.045699 |
AFH has had an average monthly return of 0.66%, which is the reported mean of this return series. We also see that AFH loses 5.52% or more of its value in a month 1% of the time (the 1st percentile), loses 0.73% or more of its value in a month 25% of the time (the 25th percentile), and gains 6.61% or more of its value in a month 1% of the time (the 99th percentile).
. histogram r_afh, title("Histogram of AFH returns") xline(-5.52 -0.72 6.61)
text(.19 -5 "1%") text(.19 -0.06 "25%") text(.19 7.3 "99%")
(bin=27, start=-10.59864, width=.71338499)
We say that the 25% VaR is 0.73%. The investor has a 25% probability of losing 0.0073 x $10,000 = $73 or more within a month. Similarly, the 1% VaR is 5.52%, so the investor has a 1% chance of losing 0.0552 x $10,000 = $552.
By default, the finvalrisk command computes these simple risk projections based on the empirical distribution of returns and computes a return based on a normal approximation to the return distribution. We specify the VaR percentiles of interest in the percentiles() option:
. finvalrisk r_afh, percentiles(1 25) Value-at-risk percentiles Number of obs = 779 Sample: 1955m2 thru 2019m12
| Empirical Normal | ||
| 1% | ||
| AFH | -5.519961 -4.923469 | |
| 25% | ||
| AFH | -.7257008 -.9587312 | |
Maybe our investor has some knowledge of time-series modeling and decides to base the estimation of VaR percentiles on a model of the returns rather than on the raw historical series. If the model is well specified, it will recover an expected return series clean of noise, that is, clean of fortuitous months where the return was unusually low or high because of events that do not represent the typical behavior of AFH returns.
Stata's lag-order selection tool for Autoregressive moving average (ARMA) models suggests that an ARMA(0,1) could be appropriate based on having the minimum BIC and HQIC:
. arimasoc r_afh Fitting models (9): ......... done Lag-order selection criteria Sample: 1955m2 thru 2019m12 Number of obs = 779
| Model | LL df AIC BIC HQIC | |
| ARMA(0,0) | -1786.898 2 3577.795 3587.111 3581.378 | |
| ARMA(0,1) | -1782.691 3 3571.383 3585.357 3576.758 | |
| ARMA(0,2) | -1782.362 4 3572.724 3591.356 3579.891 | |
| ARMA(1,0) | -1782.944 3 3571.888 3585.863 3577.263 | |
| ARMA(1,1) | -1782.017 4 3572.033 3590.665 3579.2 | |
| ARMA(1,2) | -1780.594 5 3571.188 3594.478 3580.146 | |
| ARMA(2,0) | -1782.619 4 3573.238 3591.87 3580.405 | |
| ARMA(2,1) | -1780.679 5 3571.358 3594.648 3580.316 | |
| ARMA(2,2) | -1780.435 6 3572.87 3600.818 3583.619 | |
And when we fit this model with the arima command, it indeed looks like a good fit:
. arima r_afh, ma(1) nolog
ARIMA regression
Sample: 1955m2 thru 2019m12 Number of obs = 779
Wald chi2(1) = 11.13
Log likelihood = -1782.691 Prob > chi2 = 0.0008
| OPG | ||
| r_afh | Coefficient std. err. z P>|z| [95% conf. interval] | |
| r_afh | ||
| _cons | .6601114 .0960543 6.87 0.000 .4718484 .8483743 | |
| ARMA | ||
| ma | ||
| L1. | .1074348 .0321978 3.34 0.001 .0443283 .1705413 | |
| /sigma | 2.385659 .0508852 46.88 0.000 2.285926 2.485392 | |
To obtain VaR percentile estimates based on this model, we type
. finvalrisk r_afh, percentiles(1 25) model(arima, ma(1)) Fitting ARIMA models ... Value-at-risk percentiles Model: ARIMA Error family: Normal Number of obs = 779 Sample: 1955m2 thru 2019m12
| ARIMA ARIMA | ||
| Empirical Normal historical one step | ||
| 1% | ||
| AFH | -5.519961 -4.923469 -4.889843 -4.849744 | |
| 25% | ||
| AFH | -.7257008 -.9587312 -.9490443 -.9089738 | |
The ARIMA historical column in this output gives estimated percentiles for the sample. We can compare these directly with the empirical and normal percentiles we had seen before. The ARIMA-based 1% VaR of 4.89% is slightly better news than the empirical- and normal-based estimates. The estimated 25% VaR of 0.95% is also smaller than the empirical- and normal-based results.
The ARIMA one step column provides a forecast for the risk we can expect next month, that is, the month after the end of the return series. Our forecast says that the investor has a 1% probability of losing 4.85% or more in January 2020 and a 25% probability of losing 0.91% or more.
The residuals from estimating expected returns could also be interesting. In particular, the behavior of their variance over time can tell us whether we are in a period of turmoil (high volatility) or calm (low volatility) and how long these periods tend to last.
With the model(ewma) option, we can estimate VaR percentiles based on a simple model for the variance of AFH returns.
. finvalrisk r_afh, percentiles(1 25) model(ewma 0.95) Fitting EWMA models ... Value-at-risk percentiles Model: EWMA Error family: Normal Shape parameter = 0.95 Number of obs = 779 Sample: 1955m2 thru 2019m12
| EWMA EWMA | ||
| Empirical Normal historical one step | ||
| 1% | ||
| AFH | -5.519961 -4.923469 -5.03399 -4.000597 | |
| 25% | ||
| AFH | -.7257008 -.9587312 -.9536346 -.6540177 | |
EWMA stands for exponentially weighted moving-average model. The 0.95 in our specification is a parameter for the model we have fit to the variance.
The losses we now forecast for next month at both the 1% and the 25% probabilities are lower than our ARMA-based forecast. This could indicate that our ARMA forecast is biased towards pessimism because we are in a period of rather high volatility. The EWMA-based forecast accounts for the current volatility.
We have plenty of data to estimate a more complex specification, so why not model both the expected returns and their volatility simultaneously? We can do this with autoregressive conditional heteroskedasticity (ARCH) models:
. arch r_afh, ma(1) arch(1) garch(1) nolog
ARCH family regression -- MA disturbances
Sample: 1955m2 thru 2019m12 Number of obs = 779
Wald chi2(1) = 6.25
Log likelihood = -1770.892 Prob > chi2 = 0.0124
| OPG | ||
| r_afh | Coefficient std. err. z P>|z| [95% conf. interval] | |
| r_afh | ||
| _cons | .7420881 .0901726 8.23 0.000 .5653531 .918823 | |
| ARMA | ||
| ma | ||
| L1. | .1020971 .0408531 2.50 0.012 .0220266 .1821676 | |
| ARCH | ||
| arch | ||
| L1. | .0985945 .0280868 3.51 0.000 .0435453 .1536436 | |
| garch | ||
| L1. | .7707499 .0741664 10.39 0.000 .6253863 .9161135 | |
| _cons | .7516883 .3087694 2.43 0.015 .1465114 1.356865 | |
We can ask for this or any other specification of Stata's arch command within finvalrisk:
. finvalrisk r_afh, percentiles(1 25) model(arch, ma(1) arch(1) garch(1)) Fitting ARCH models ... Value-at-risk percentiles Model: ARCH Error family: Normal Number of obs = 779 Sample: 1955m2 thru 2019m12
| ARCH ARCH | ||
| Empirical Normal historical one step | ||
| 1% | ||
| AFH | -5.519961 -4.923469 -4.780788 -4.223384 | |
| 25% | ||
| AFH | -.7257008 -.9587312 -.8646021 -.6755917 | |
This ARCH-based, one-step forecast is more pessimistic than the EWMA forecast but more optimistic than the ARMA-based forecast above.
Looking at all of these results, the gambler concludes that there is at least a 25% probability of losing money the following month. But they also know that the monthly loss is unlikely to be large under typical circumstances, so perhaps they will be willing to place the bet, hoping the tip they heard about AFH comes true.
Read more about value-at-risk statistics in [FIN] finvalrisk in the Stata Financial Statistics Reference Manual.
Learn more about Stata's financial statistics features.
View all the new features in Stata 19 and, in particular, new in financial statistics.