From 0e8f05fd8c126897af4c2a8d00ea9e2cb0bf7671 Mon Sep 17 00:00:00 2001 From: onnokleen Date: Tue, 12 May 2020 17:42:00 +0200 Subject: [PATCH] OPG error management --- CRAN-RELEASE | 2 ++ DESCRIPTION | 4 ++-- NEWS.md | 3 +++ R/fit_mfgarch.R | 6 +++--- man/df_financial.Rd | 6 ++++-- man/df_mfgarch.Rd | 6 ++++-- man/fit_mfgarch.Rd | 21 ++++++++++++++++----- man/simulate_mfgarch.Rd | 21 ++++++++++++++++++--- man/simulate_mfgarch_diffusion.Rd | 17 +++++++++++++++-- man/simulate_mfgarch_rv_dependent.Rd | 17 +++++++++++++++-- 10 files changed, 82 insertions(+), 21 deletions(-) create mode 100644 CRAN-RELEASE diff --git a/CRAN-RELEASE b/CRAN-RELEASE new file mode 100644 index 0000000..250de5d --- /dev/null +++ b/CRAN-RELEASE @@ -0,0 +1,2 @@ +This package was submitted to CRAN on 2019-12-04. +Once it is accepted, delete this file and tag the release (commit 9dfde37cd9). diff --git a/DESCRIPTION b/DESCRIPTION index 88933db..f594ec6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: mfGARCH Title: Mixed-Frequency GARCH Models -Version: 0.1.9 +Version: 0.2.0 Authors@R: person("Onno", "Kleen", email = "r@onnokleen.de", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-4731-4640")) Description: Estimating GARCH-MIDAS (MIxed-DAta-Sampling) models (Engle, Ghysels, Sohn, 2013, ) and related statistical inference, accompanying the paper "Two are better than one: volatility forecasting using multiplicative component GARCH models" by Conrad and Kleen (2018, ). The GARCH-MIDAS model decomposes the conditional variance of (daily) stock returns into a short- and long-term component, where the latter may depend on an exogenous covariate sampled at a lower frequency. Depends: @@ -8,7 +8,7 @@ Depends: License: MIT + file LICENSE Encoding: UTF-8 LazyData: true -RoxygenNote: 6.1.1 +RoxygenNote: 7.1.0 Imports: Rcpp, graphics, diff --git a/NEWS.md b/NEWS.md index 2dd0373..6f7eee7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +v0.2.0 +- Better error management for OPG standard errors + v0.1.9 - Compatibility with R 4.0.0 diff --git a/R/fit_mfgarch.R b/R/fit_mfgarch.R index 0a7e895..685d3e0 100644 --- a/R/fit_mfgarch.R +++ b/R/fit_mfgarch.R @@ -882,12 +882,12 @@ fit_mfgarch <- function(data, y, x = NULL, K = NULL, low.freq = "date", var.rati opg.std.err <- try({sqrt(diag(solve(crossprod(jacobian(func = function(theta) -lf(theta), x = par)))))}, silent = TRUE) - if (class(inv_hessian)[1] == "try-error") { + if (class(opg.std.err)[1] == "try-error") { warning("Inverting the OPG matrix failed. No OPG standard errors calculated.") opg.std.err <- NA + } else { + opg.std.err <- opg.std.err * sqrt((mean(df.fitted$residuals^4, na.rm = TRUE) - 1) / 2) } - # browser() - opg.std.err <- opg.std.err * sqrt((mean(df.fitted$residuals^4, na.rm = TRUE) - 1) / 2) if (class(inv_hessian)[1] == "try-error") { warning("Inverting the Hessian matrix failed. No robust standard errors calculated. Possible workaround: Multiply returns by 100.") diff --git a/man/df_financial.Rd b/man/df_financial.Rd index ac4e7f2..185cc93 100644 --- a/man/df_financial.Rd +++ b/man/df_financial.Rd @@ -4,14 +4,16 @@ \name{df_financial} \alias{df_financial} \title{Stock returns and financial conditions.} -\format{A data frame with 11,306 rows and 5 variables: +\format{ +A data frame with 11,306 rows and 5 variables: \describe{ \item{date}{date} \item{return}{daily S&P 500 log returns times 100} \item{rv}{5-minute realized variances} \item{week}{a dummy for each year/week combination} \item{nfci}{National Financial Conditions Index} -}} +} +} \source{ \url{https://github.com/onnokleen/mfGARCH/} diff --git a/man/df_mfgarch.Rd b/man/df_mfgarch.Rd index 38ba3c0..04cf080 100644 --- a/man/df_mfgarch.Rd +++ b/man/df_mfgarch.Rd @@ -4,7 +4,8 @@ \name{df_mfgarch} \alias{df_mfgarch} \title{Mixed-frequency data set.} -\format{A data frame with 11,938 rows and 11 variables: +\format{ +A data frame with 11,938 rows and 11 variables: \describe{ \item{date}{date} \item{return}{daily S&P 500 log returns times 100} @@ -17,7 +18,8 @@ \item{nai}{NAI} \item{nfci}{National Financial Conditions Index} \item{year_month}{a dummy for each year/month combination} -}} +} +} \source{ \url{https://github.com/onnokleen/mfGARCH/} diff --git a/man/fit_mfgarch.Rd b/man/fit_mfgarch.Rd index 8fbf03e..1d0d545 100644 --- a/man/fit_mfgarch.Rd +++ b/man/fit_mfgarch.Rd @@ -4,11 +4,22 @@ \alias{fit_mfgarch} \title{This function estimates a multiplicative mixed-frequency GARCH model. For the sake of numerical stability, it is best to multiply log returns by 100.} \usage{ -fit_mfgarch(data, y, x = NULL, K = NULL, low.freq = "date", - var.ratio.freq = NULL, gamma = TRUE, weighting = "beta.restricted", - x.two = NULL, K.two = NULL, low.freq.two = NULL, - weighting.two = NULL, multi.start = FALSE, control = list(par.start - = NULL)) +fit_mfgarch( + data, + y, + x = NULL, + K = NULL, + low.freq = "date", + var.ratio.freq = NULL, + gamma = TRUE, + weighting = "beta.restricted", + x.two = NULL, + K.two = NULL, + low.freq.two = NULL, + weighting.two = NULL, + multi.start = FALSE, + control = list(par.start = NULL) +) } \arguments{ \item{data}{data frame containing a column named date of type 'Date'.} diff --git a/man/simulate_mfgarch.Rd b/man/simulate_mfgarch.Rd index e587b38..d7c541e 100644 --- a/man/simulate_mfgarch.Rd +++ b/man/simulate_mfgarch.Rd @@ -4,9 +4,24 @@ \alias{simulate_mfgarch} \title{This function simulates a GARCH-MIDAS model. Innovations can follow a standard normal or student-t distribution.} \usage{ -simulate_mfgarch(n.days, mu, alpha, beta, gamma, m, theta, w1 = 1, w2, K, - psi, sigma.psi, low.freq = 1, n.intraday = 288, student.t = NULL, - corr = 0) +simulate_mfgarch( + n.days, + mu, + alpha, + beta, + gamma, + m, + theta, + w1 = 1, + w2, + K, + psi, + sigma.psi, + low.freq = 1, + n.intraday = 288, + student.t = NULL, + corr = 0 +) } \arguments{ \item{n.days}{number of days} diff --git a/man/simulate_mfgarch_diffusion.Rd b/man/simulate_mfgarch_diffusion.Rd index 8669c5f..1e13c12 100644 --- a/man/simulate_mfgarch_diffusion.Rd +++ b/man/simulate_mfgarch_diffusion.Rd @@ -4,8 +4,21 @@ \alias{simulate_mfgarch_diffusion} \title{This function simulates a GARCH-MIDAS model where the short-term GARCH component is replaced by its diffusion limit, see Andersen (1998)} \usage{ -simulate_mfgarch_diffusion(n.days, mu, alpha, beta, m, theta, w1 = 1, w2, - K, psi, sigma.psi, low.freq = 1, n.intraday = 288) +simulate_mfgarch_diffusion( + n.days, + mu, + alpha, + beta, + m, + theta, + w1 = 1, + w2, + K, + psi, + sigma.psi, + low.freq = 1, + n.intraday = 288 +) } \arguments{ \item{n.days}{number of days} diff --git a/man/simulate_mfgarch_rv_dependent.Rd b/man/simulate_mfgarch_rv_dependent.Rd index 925ac8b..0d6cefb 100644 --- a/man/simulate_mfgarch_rv_dependent.Rd +++ b/man/simulate_mfgarch_rv_dependent.Rd @@ -4,8 +4,21 @@ \alias{simulate_mfgarch_rv_dependent} \title{Simulate a GARCH-MIDAS similar to Wang/Ghysels with lagged RVol as covariate} \usage{ -simulate_mfgarch_rv_dependent(n.days, mu, alpha, beta, gamma, m, theta, - w1 = 1, w2, K, n.intraday = 288, low.freq = 1, rvol = FALSE) +simulate_mfgarch_rv_dependent( + n.days, + mu, + alpha, + beta, + gamma, + m, + theta, + w1 = 1, + w2, + K, + n.intraday = 288, + low.freq = 1, + rvol = FALSE +) } \arguments{ \item{n.days}{number of days}