# R-squared from conditional mean equation in GARCH models (rugarch package)

I was recently asked to report the r-squared statistics together with the estimations of GARCH models with exogenous regressors on the conditional mean equation. However, there is no function to get these statistics automatically using the rugarch package.

My question is straightforward: Can I use the residuals of the fitted model (uGARCHfit class object) to calculate the r-squared and the adjusted r-squared manually or should I use the estimated sigma from the fitted model to weight an lm object and extract the r-squared from there?

I did some research but I couldn't find anything in the vignette of the package.

Two exchanges on cross-validated touched the issue:

How to measure the goodness of fit of a GARCH model?

How to extract the adjusted r squared from uGARCHfit class data?

But they don't provide a definitive answer.

Here is a reproducible example of what I want to do:

library(rugarch)
library(zoo)
library(dplyr)
library(purrr)
library(tidyr)
library(fredr)

# Get and clean the data

fredr_set_key("your_key_here") # fredr package requires a key to download the data.

df = map_dfr(c('DEXBZUS', 'DCOILWTICO'), fredr) %>%
filter(date > '2010-01-01')

df1 = df %>%
spread(series_id, value) %>%
set_names('date', 'oil', 'brl') %>%
mutate_at(vars(-date), list(~ log(.) - lag(log(.)))) %>%
drop_na

oil = as.matrix(zoo(df1$$oil, df1$$date))
brl = as.matrix(zoo(df1$$brl, df1$$date))

# Estimate the model
m1_spec  = ugarchspec(variance.model = list(model = 'eGARCH',
garchOrder = c(1,1)),
mean.model = list(armaOrder = c(1,0),
external.regressors = oil),
distribution.model = 'norm')

m1_fit = ugarchfit(spec = m1_spec, data = brl,
solver.control = list(trace = 1))

# Calculate the r-squared statistics
r2 = 1 - (sum(residuals(m1_fit)^2) / sum((brl - mean(brl))^2))
r2a = 1 - ((1 - r2) * (length(brl) - 1) / (length(brl) - 3))
$$$$

• My answer in the thread How to measure the goodness of fit of a GARCH model? that you linked above focuses specifically on fitting the conditional variance, not the remaining aspects of the model (conditional mean, other distributional properties); perhaps I should clarify that there. If you focus on the conditional mean (which is one of the equations that constitute a GARCH model), the usual $R^2$ should be fine. Dec 31, 2019 at 8:10

## 1 Answer

Yes, you can use the residuals of the fitted model (uGARCHfit class object) to calculate the $$R^2$$ and the $$R^2_{adj.}$$ manually. Note: you need raw residuals, not standardized ones.

You do not use the estimated sigma from the fitted model to weight an lm` object and extract the $$R^2$$ from there; the classical definition of $$R^2$$ does not involve any weighting.

The last line of your code for calculating $$R^2$$ appears to be correct.