Getting the Data
library(tidyquant)
library(tidyverse)
library(forecast)
library(quarks)
jago_stock <- tq_get("ARTO.JK",
get = "stock.prices",
from = "2022-09-01")
Calculating Volatility
var_sample <- VAR(r_jago)
ewma_jago <- ewma(r_jago[-1], lambda = 0.94)
ewma_jago
## [1] 0.0021264915 0.0020011059 0.0018946482 0.0017809693 0.0017840907
## [6] 0.0016825572 0.0015870115 0.0015138386 0.0015662459 0.0016024745
## [11] 0.0015120555 0.0015485829 0.0015134562 0.0014333870 0.0013811672
## [16] 0.0013147438 0.0012793921 0.0012055021 0.0011688650 0.0010987331
## [21] 0.0011430132 0.0010877984 0.0010363046 0.0010176175 0.0009868596
## [26] 0.0009477745 0.0009289495 0.0009720674 0.0011702522 0.0012229858
## [31] 0.0014349812 0.0016382342 0.0018227648 0.0018459872 0.0027113837
## [36] 0.0025794126 0.0024259338 0.0022918455 0.0021543347 0.0023040003
## [41] 0.0022014533 0.0021471261 0.0022207744 0.0022317032 0.0021000967
## [46] 0.0019740909 0.0018814715 0.0021574800 0.0020870854 0.0019817754
## [51] 0.0020924363 0.0056349254 0.0053014875 0.0050394612 0.0049482398
## [56] 0.0047291054 0.0044618877 0.0044830541 0.0044737661 0.0042106301
## [61] 0.0039795552 0.0037533842 0.0037090347 0.0035301386 0.0033456078
## [66] 0.0031630980 0.0032567915 0.0032739690 0.0031159863 0.0029469512
## [71] 0.0029068731 0.0030148313 0.0030886582 0.0066080219 0.0062242657
## [76] 0.0058522657 0.0055026002 0.0053486193 0.0052071455 0.0049061003
## [81] 0.0046117343 0.0043509802 0.0043168366 0.0040816899 0.0038536419
## [86] 0.0036229076 0.0036203041 0.0034382056 0.0032687959 0.0030769773
## [91] 0.0031728759 0.0032299572 0.0030771697 0.0028932151 0.0029651754
## [96] 0.0041567592 0.0040391896 0.0038071580 0.0035887829 0.0034050603
## [101] 0.0032506827 0.0030556418 0.0028746324 0.0031007355 0.0029998835
## [106] 0.0031124844 0.0029912062 0.0028123125 0.0026459029 0.0034782947
## [111] 0.0032770044 0.0030808370 0.0030125544 0.0028397740 0.0027555761
## [116] 0.0028817016 0.0029634441 0.0028038482 0.0026544795 0.0026816887
## [121] 0.0025371256 0.0023876007 0.0022443446 0.0023836065 0.0024422284
## [126] 0.0023391859 0.0022325800 0.0021143606 0.0022960654 0.0023705706
## [131] 0.0023022052 0.0021672465 0.0022632018 0.0021416109 0.0022191079
## [136] 0.0021521370 0.0020544755 0.0021957944 0.0022415646 0.0022245427
## [141] 0.0021733747 0.0021625513 0.0026105779 0.0024637214 0.0024218229
## [146] 0.0023053685 0.0026496622 0.0025272623 0.0024230451 0.0023278639
## [151] 0.0022849647 0.0021478668 0.0020568093 0.0020229216 0.0020462370
## [156] 0.0019625755 0.0018734245 0.0017801517 0.0017179707 0.0016476464
## [161] 0.0016600488 0.0015608209 0.0015519701 0.0015092615 0.0014398656
## [166] 0.0013649413 0.0013040074 0.0012712177 0.0012535383 0.0011884458
## [171] 0.0011215221 0.0013763919 0.0013092920 0.0012397308 0.0011817392
## [176] 0.0011203681 0.0012019038 0.0012057164 0.0011762031 0.0011203944
## [181] 0.0013284045 0.0012662326 0.0013535856 0.0012887628 0.0013639686
## [186] 0.0013291705 0.0012821233 0.0020388063 0.0023503250 0.0022187393
## [191] 0.0021152446 0.0019908599 0.0020736975 0.0019492757 0.0018576522
## [196] 0.0017792997 0.0023534501 0.0022128218 0.0022272790 0.0022368799
## [201] 0.0021119260 0.0020065703 0.0021628108 0.0020936857 0.0019814305
## [206] 0.0018895419 0.0018129761 0.0017048022 0.0016025141 0.0015213848
## [211] 0.0014306840 0.0013448430 0.0014539962 0.0013667564 0.0012873825
## [216] 0.0012516908 0.0011827526 0.0011124586 0.0010517919 0.0009886843
## [221] 0.0009955877 0.0009422293 0.0014694801 0.0013847289 0.0013050117
## [226] 0.0012480709 0.0013231867 0.0013798499 0.0013112601 0.0012472329
## [231] 0.0011759492 0.0011193775 0.0010846648 0.0010411070 0.0010358848
## [236] 0.0009746841 0.0009199823 0.0008647834 0.0008743364 0.0008229007
## [241] 0.0007776588 0.0008360395 0.0008041834 0.0007658791 0.0007925162
## [246] 0.0007754011 0.0007288770 0.0008686267 0.0008176533 0.0009319211
## [251] 0.0009415751 0.0008894637 0.0008457914 0.0008657764 0.0008244965
## [256] 0.0008346810 0.0007891767 0.0007709359 0.0007258972 0.0006871695
## [261] 0.0007454459 0.0008088537 0.0007617785 0.0007219536 0.0006786363
## [266] 0.0006436852 0.0006065345 0.0005734839 0.0005405824 0.0005542108
## [271] 0.0005789463 0.0007157901 0.0011037533 0.0020457586 0.0019248047
## [276] 0.0020645149 0.0019487565 0.0018339073 0.0017284896 0.0016378327
## [281] 0.0016125752 0.0015816865 0.0014873676 0.0014449988 0.0013607486
## [286] 0.0013178036 0.0013819730 0.0021346705 0.0023959421 0.0022557542
## [291] 0.0021594552 0.0024509289 0.0023052735 0.0023380382 0.0023555469
## [296] 0.0031065400 0.0029201476
var_sample
## [1] 0.002126492
Volatility Plot
ggplot(aes(x = jago_stock$date[-1], y = ewma_jago), data = tibble(ewma_jago)) +
geom_line() +
geom_hline(yintercept = var_sample, linetype = 'dashed', color = 'red') +
xlab("Date") +
ylab("Volatility using EWMA")
