This document shows the operations made to analyse the stock price risk of NVidia (NVDA) using Value at Risk (VaR) (Three different methodologies) and Expected Shortfall (CVaR).

Libraries and fundamental data

library(quantmod)
library(PerformanceAnalytics)
library(ggplot2)
library(dplyr)
library(zoo)
library(quarks)
library(rugarch)
##Data
#Stock data of Nvidia + closing prices
getSymbols("NVDA", from = "2021-01-01", to = "2026-05-01")
## [1] "NVDA"
stock_prices = Cl(NVDA)

#Calculate log returns and clean up
returns = na.omit(CalculateReturns(stock_prices, method = "log"))
returns_clean = as.numeric(returns)

#summary(returns_clean)     #Displays returns, hidden away to avoid clutter

Value at Risk

We utilize three distinct methodologies: Historical, Parametrc Method, and Monte-Carlo Simulation.

Which gives us the following results:

## [1] "VaR Comparison Results:"
##                  method      Var_95
## 1 Historical Simulation -0.04837900
## 2     Parametric Method -0.05078457
## 3           Monte Carlo -0.05070649

The VaR for Parametric and Monte Carlo methods are so close to each other they are functionally identical at ~5.08%. They seem to overestimate the severity of losses compared to the Historical Method; its value sitting at ~4.89%.

Visualization of Data

Below can be found visualizations of the calculated data. The VaR threshold value in Plot 2 is the one obtained from the Parametric/Monte Carlo methods, as we believe it safest (at the initial stage) to assume the worst case scenarios.

## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

VaR value for the Historical Method is lower than for both Monte Carlo and Parametric Methods, indicating that Nvidia’s stock historically lost less value than mathematical models would suggest.

The convergence of the Monte Carlo Simulation and Parametric Method can be explained by virtue of them using very similar methods to obtain the result; that being the calculation of mean value, standard deviation and then assume returns follow a normal distribution.

Historical Method’s difference from the other methods stems from not following normal distribution; the stock was less volatile than the standard deviation suggests. The losses were smaller than models expect.

Backtesting

To test the accuracy of our models, we shall conduct a backtest, counting the number of exceptions, and a Kupiec Test.

First, we calculate the number of exceptions:

##                 Metric Value
## 1   Total Observations  1336
## 2  Expected Exceptions  66.8
## 3    Actual Exceptions    67
## 4   Exception Rate (%)  5.01
## 5 VaR Confidence Level   95%

Then, we perform the Kupiec Test:

## [1] "Kupiec Proportion of Failures Test:"
## 
##  Exact binomial test
## 
## data:  exceptions and total_obs
## number of successes = 67, number of trials = 1336, p-value = 0.95
## alternative hypothesis: true probability of success is not equal to 0.05
## 95 percent confidence interval:
##  0.03907353 0.06325387
## sample estimates:
## probability of success 
##              0.0501497

And finally visualize the Kupiec Test:

The result of the test indicate that in the last 5 years, the 5% of worst cases that VaR and CVaR are referring to (i.e. 5% of cases where Nvidia’s stock loses more than e.g. 5.08% of its value) happened 5.05% of the time (67 times). This means the model passed the Kupiec Test and is thus accurate.

Conditional Value at Risk

CVaR values tell a more interesting story, though.

## [1] "Conditional VaR (Expected Shortfall) Results:"
##                  Method     CVaR_95
## 1 Historical Simulation -0.06895066
## 2 Parametric (Gaussian) -0.06420359
## 3           Monte Carlo -0.06422956

The CVaR for Parametric and Monte Carlo methods are, once again, functionally identical at ~6.42%, and underestimate the losses compared to the Historical Method at ~6.89%. This means that when the 5% of cases where losses happen, NVidia’s stock, on average, loses 6.89% of its value.

Historical Method’s CVaR is higher than the other two. As such, the stock’s price, in reality, is calmer than mathematical models expect most of the time, but when the value of the stock actually crashes (which CVaR captures), it does so much harder than models can predict. In other words, standard models overestimate daily fluctuations, but underestmiate exposure to a crash.

Based on our analysis, we adopt the Historical Method results of VaR = 4.89% and CVaR = 6.89% for our primary risk metrics, as we believe it tells the story best; it more accurately reflects the fat-tail risk and magnitude of losses.