This is a case study of risk measurement in financial sector - single asset.

Firstly, prepare the required library to perform the analysis.

install.packages("PerformanceAnalytics", repos = "http://cran.us.r-project.org")
install.packages("dplyr", repos = "http://cran.us.r-project.org")
install.packages("tidyquant", repos = "http://cran.us.r-project.org")
install.packages("quantmod", repos = "http://cran.us.r-project.org")
install.packages("tseries", repos = "http://cran.us.r-project.org")
install.packages("tidyverse", repos = "http://cran.us.r-project.org")
library(PerformanceAnalytics)
library(dplyr)
library(tidyquant)
library(quantmod)
library(tseries)
library(tidyverse)

Secondly, call all the stocks that we are going to analyze.

symbol_name2 <- c("AAPL", "GOOG", "TLKM.JK", "ADHI.JK", "BBRI.JK", "GOTO.JK")

Next, determine the analysis period and choose the value we are going to download (adjusted closing price of stock).

price2 <- getSymbols(symbol_name2, from = "2020-03-01", to = "2022-08-31")%>%
  map(~Ad(get(.))) %>%
  reduce(merge) %>%
  'colnames<-'(symbol_name2)

Lastly, now we can get the value of the return using the logarithm calculation method and value at risk (VaR).

return_a <- CalculateReturns(price2, method="log")

return2_a <- return_a[-1,]

hist_var_2 <- VaR(return2_a, p=0.95, method="historical")

hist_var_2
##            AAPL        GOOG     TLKM.JK     ADHI.JK     BBRI.JK     GOTO.JK
## VaR -0.03431681 -0.03491096 -0.02889448 -0.05793737 -0.03788694 -0.06831565

Analysis: In the last pandemic period, TLKM became a stock with least risk. Its VaR is only -2.88%; this means the risk of loss in the more than 2 years is -2.88%. While AAPL and GOOG are in the VaR -3.4% of VaR, another tech stock from Indonesia, GOTO, has the most severe risk among the analyzed stocks. Its VaR is -6.8%. The risk GOTO has is higher than another Indonesian tech company, TLKM.