Quantitative Risk Management

Monte Carlo Simulation Approach to Finding the Value at Risk

Getting the Data

library(tidyquant)
library(tidyverse)

jago_stock <- tq_get("ARTO.JK",
                    get = "stock.prices",
                    from = "2022-09-01")

Calculating the Loss/Profit

lp_jago <- NULL

for (i in seq_len(length(jago_stock$close) - 1)) {
  lp_jago[i + 1] <- - (jago_stock$close[i + 1] - jago_stock$close[i])
}

Plotting the Density Plot of the L/P Data

ggplot(as_tibble(lp_jago)) +
  geom_density(aes(x = lp_jago))
## Warning: Removed 1 rows containing non-finite values (`stat_density()`).

Fitting the Normal Distribution

Showing the Histogram of the Fitted Distribution

set.seed(211)
fitted_df <- tibble(lp_norm = rnorm(length(lp_jago), AVERAGE(lp_jago), STDEV(lp_jago)), lp_jago)
fitted_df <- fitted_df |> 
  pivot_longer(cols = 1:2,
               names_to = "dist",
               values_to = "lp")
ggplot(fitted_df, aes(x = lp, colour = dist)) +
  geom_density()
## Warning: Removed 1 rows containing non-finite values (`stat_density()`).

Simulating the L/P Data using Normal Distribution

Getting the Simulated Data and Making the Histogram

set.seed(211)
simulated_norm <- rnorm(10000, AVERAGE(lp_jago), STDEV(lp_jago))
ggplot(as_tibble(simulated_norm)) +
  geom_density(aes(x = simulated_norm))

Calculating the Value at Risk with Confidence Level of 95% and Holding Period of 1 Day

var_jago <- quantile(simulated_norm, probs = 0.95)
var_jago
##      95% 
## 304.7276