1

I am trying to fit a GARCH(1,1) model to a dataset with Gamma(a, 1/a) distribution, using maximum likelihood estimation. Therefore, the loglikelihood function im using is: LogL = - ln(Γ(nu)) + (nu - 1) * ln(x) - nu*(x/mu) - nu * ln(mu)

x = data, mu = GARCH(1,1). nu is the input of the gamma function.

I am trying to estimate simultaneously nu and the GARCH(1,1) parameters (omega, alpha, beta). The code I wrote is

import numpy as np
import pandas as pd
import scipy.optimize as opt
from scipy.special import gamma

df_aex = pd.read_excel('/Users/jr/Desktop/Data_complete.xlsx', sheet_name=0)
rv = df_aex["rv5"]
rv = np.array(rv*100)


#Objective function to minimize
def garch_filter(omega, alpha1, beta, rv):
    irv = len(rv)
    mu_t = np.zeros(irv)

    for i in range(irv):
        if i == 0:
            mu_t[i] = omega/(1 - alpha1 - beta)
        else:
            mu_t[i] = omega + (alpha1 * rv[i - 1]) + (beta * mu_t[i - 1])

    return mu_t


# Define function to calculate GARCH log likelihood
def gamma_loglike(vP, rv):
    omega = vP[0]
    alpha1 = vP[1]
    beta = vP[2]
    nu = vP[3]

    mu_t = garch_filter(omega, alpha1, beta, rv)

    LogL = - np.sum(- np.log(gamma(nu)) + (nu * np.log(nu)) + (nu - 1) * np.log(rv) - nu * np.divide(rv, mu_t) - nu*np.log(mu))

    return LogL

#Constraints
def constraint1(vP):
    return 1 - (vP[1] + vP[2])

cons1 = ({'type': 'ineq', 'fun': lambda x: np.array(x)})
cons2 = ({'type': 'ineq', 'fun': constraint1})
cons = [cons1, cons2]

#Initial guesses
vP0 = np.array([0.009, 0.10, 0.85, 0.5])

#Maximization
res = opt.minimize(gamma_loglike, vP0, args=rv,
                   bounds=((0.0001, None), (0.0001, 0.999), (0.0001, 0.999), (0.0001, None)), constraints=cons, options={'disp':True})

o_est = res.x[0]
a_est = res.x[1]
b_est = res.x[2]
nu_est = res.x[3]

print([o_est, a_est, b_est, nu_est])

I'm expecting output to be something like [0.01, 0.05, 0.7, 4] but my first value (omega) is around 40 which is way too high.

Someone that could help me with this problem?

zjos020
  • 11
  • 2

1 Answers1

0

My likelihood function was not quite right.. I have fixed it now.

So the code above can be used to write a maximum likelihood estimation model that estimates the GARCH(1,1) process and the degrees of freedom of the fitted gamma distribution.

zjos020
  • 11
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 03 '22 at 12:36
  • I think that `garch_filter` isn't correct. You have to take the square root of the right side of mu_t and square rv[i-1] and mu_t[i-1]. – Alien Nov 17 '22 at 17:43