Created
September 2, 2023 13:09
-
-
Save jtrecenti/565356a16312dbf5f09236e796333e93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rugarch) | |
start_date <- '2018-01-01' | |
# esses são ativos de fundos imobiliários que eu ja tive | |
# e queria saber fiz um péssimo investimento | |
# ou apenas ruim. | |
ativos <- c( | |
"HGRE11.SA", | |
"BTLG11.SA", | |
"HGRU11.SA", | |
"VGIR11.SA", | |
"MGFF11.SA" | |
) | |
da <- yfR::yf_get( | |
ativos, | |
first_date = start_date, | |
type_return = "log", | |
freq_data = "daily", | |
do_complete_data = TRUE | |
) | |
data_corte <- da |> | |
dplyr::group_by(ticker) |> | |
dplyr::filter(ref_date == min(ref_date)) |> | |
dplyr::ungroup() |> | |
with(max(ref_date)) | |
da_train <- da |> | |
dplyr::filter(ref_date > data_corte) | |
ret <- da_train |> | |
dplyr::filter(ticker == "BTLG11.SA") |> | |
dplyr::pull(ret_closing_prices) | |
parms <- list( | |
m = 1, n = 1, | |
p = 0, q = 0, | |
dist = "std" | |
) | |
garch_model <- ugarchspec( | |
variance.model = list( | |
model = "fGARCH", | |
submodel = "GARCH", | |
garchOrder = c(parms$m, parms$n) | |
), | |
mean.model = list( | |
armaOrder = c(parms$p, parms$q), | |
include.mean = TRUE | |
), | |
distribution.model = parms$dist | |
) | |
fit <- ugarchfit(garch_model, data = ret) | |
fit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment