library(tidyquant)
library(tidyverse)
jago_stock <- tq_get("ARTO.JK",
get = "stock.prices",
from = "2022-09-01")
r_jago <- NULL
for (i in seq_len(length(jago_stock$close) - 1)) {
r_jago[i + 1] <- (jago_stock$close[i + 1] - jago_stock$close[i])/jago_stock$close[i]
}
alpha_cl <- qnorm(0.05)
VaR_jago_1_hari <- - (AVERAGE(r_jago) * 1 + alpha_cl * STDEV(r_jago) * sqrt(1)) * tail(jago_stock$close, 1)
VaR_jago_1_minggu <- - (AVERAGE(r_jago) * 5 + alpha_cl * STDEV(r_jago) * sqrt(5)) * tail(jago_stock$close, 1)
VaR_jago_1_tahun <- - (AVERAGE(r_jago) * 264 + alpha_cl * STDEV(r_jago) * sqrt(264)) * tail(jago_stock$close, 1)
VaR_jago_10_tahun <- - (AVERAGE(r_jago) * 2640 + alpha_cl * STDEV(r_jago) * sqrt(2640)) * tail(jago_stock$close, 1)
tibble(VaR_jago_1_hari, VaR_jago_1_minggu, VaR_jago_1_tahun, VaR_jago_10_tahun)
## # A tibble: 1 x 4
## VaR_jago_1_hari VaR_jago_1_minggu VaR_jago_1_tahun VaR_jago_10_tahun
## <dbl> <dbl> <dbl> <dbl>
## 1 127. 306. 3985. 26558.
kurtosis(r_jago) + 3
## [1] 9.723408
The “+ 3” is used because the function kurtosis() from
package PerformanceAnalytics inside the
tidyquant ecosystem is calculating excess kurtosis instead
of kurtosis.
set.seed(211)
generated_data <- rnorm(length(r_jago), AVERAGE(r_jago), STDEV(r_jago))
head(generated_data, 15)
## [1] -0.037477979 0.079988952 -0.033098516 -0.093276242 0.034561886
## [6] -0.045144600 0.021017303 -0.030722279 0.025421019 0.030928025
## [11] -0.006803987 0.026910756 -0.021332196 -0.001369025 -0.024155182
kurtosis(generated_data) + 3
## [1] 3.269707