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?