1. What is Value at Risk (VaR)?

Value at Risk (VaR) is a statistical measure that quantifies and focuses on the potential downside risk of an investment over a specific time horizon. It is widely used by financial institutions to estimate the amount of potential losses in their institutional investments.

 

2. How is Value at Risk (VaR) Calculated?

     (1) Import a CSV Data File in R:

library(quantmod)
library(PerformanceAnalytics)
Apple_CSV <- read.zoo("AAPL.csv",header = TRUE, sep =",",format="%m/%d/%Y")

 

     (2) Clean Imported Data and Calculate Daily Return of AAPL:

AAPL_Prices <- as.xts(x = Apple_CSV$Adj.Close)
AAPL_Returns <- dailyReturn(AAPL_Prices)
head(AAPL_Returns)
##            daily.returns
## 2015-01-02  0.000000e+00
## 2015-01-05 -2.817169e-02
## 2015-01-06  9.450198e-05
## 2015-01-07  1.402209e-02
## 2015-01-08  3.842243e-02
## 2015-01-09  1.072070e-03
tail(AAPL_Returns)
##            daily.returns
## 2019-12-23  0.0163183658
## 2019-12-24  0.0009506422
## 2019-12-26  0.0198403820
## 2019-12-27 -0.0003795103
## 2019-12-30  0.0059351588
## 2019-12-31  0.0073064655
summary(AAPL_Returns)
##      Index            daily.returns       
##  Min.   :2015-01-02   Min.   :-0.0996074  
##  1st Qu.:2016-04-04   1st Qu.:-0.0058529  
##  Median :2017-07-01   Median : 0.0008920  
##  Mean   :2017-07-01   Mean   : 0.0009755  
##  3rd Qu.:2018-09-30   3rd Qu.: 0.0089108  
##  Max.   :2019-12-31   Max.   : 0.0704214

 

     (4) Calculate Value at Risk (VaR) and Conditional Value at Risk (CVaR):

VaR(AAPL_Returns, p=0.95, method = "historical")
##     daily.returns
## VaR   -0.02499576
CVaR(AAPL_Returns, p=0.95, method = "historical")
##    daily.returns
## ES   -0.03617996

 

Thank You and See You Soon!