How to estimate a GARCH model in python (without standard function)?

Cyn
Messages
7
Reaction score
0
Hi,

I want to program an GARCH model for exchange rates. To do this, I calculated the residuals. Next, I did the following (in python)

Code:
def main():
    vP0 = (0.1, 0.05, 0.92)
    a = minimize(garch_loglike, vP0, eps, bounds = ((0.0001, None), (0.0001, None), (0.0001, None)), options={'disp':True})
    print(a.x)

def garch_filter(omega, alpha, beta, eps):
    iT = len(eps)
    sigma_2 = np.zeros(iT)
    
    for i in range(iT):
        if i==0:
            sigma_2[i] = omega/(1-alpha-beta)
        else:
            sigma_2[i] = omega + alpha*eps[i-1]**2 + beta*sigma_2[i-1]
    return sigma_2def garch_loglike(vP, eps):
    iT = len(eps)
    omega = vP[0]
    alpha = vP[1]
    beta = vP[2]
    
    sigma_2 = garch_filter(omega, alpha, beta, eps)
    
    logL = -np.sum(-np.log(sigma_2) - eps**2/sigma_2)
    
    return logL

I get the following output:
[ 0.04881267 0.17925725 0.73315972]

Can anyone say if this is correct? Because I don't get the "usual" values for a GARCH model.

Thank you in advance!
 
Cyn said:
Hi,

I want to program an GARCH model for exchange rates. To do this, I calculated the residuals. Next, I did the following (in python)

Code:
def main():
    vP0 = (0.1, 0.05, 0.92)
    a = minimize(garch_loglike, vP0, eps, bounds = ((0.0001, None), (0.0001, None), (0.0001, None)), options={'disp':True})
    print(a.x)

def garch_filter(omega, alpha, beta, eps):
    iT = len(eps)
    sigma_2 = np.zeros(iT)
   
    for i in range(iT):
        if i==0:
            sigma_2[i] = omega/(1-alpha-beta)
        else:
            sigma_2[i] = omega + alpha*eps[i-1]**2 + beta*sigma_2[i-1]
    return sigma_2def garch_loglike(vP, eps):
    iT = len(eps)
    omega = vP[0]
    alpha = vP[1]
    beta = vP[2]
   
    sigma_2 = garch_filter(omega, alpha, beta, eps)
   
    logL = -np.sum(-np.log(sigma_2) - eps**2/sigma_2)
   
    return logL

I get the following output:
[ 0.04881267 0.17925725 0.73315972]

Can anyone say if this is correct? Because I don't get the "usual" values for a GARCH model.
It would be difficult to say whether your results are correct for several reasons.
  1. I doubt that anyone here even knows what the GARCH model is about. I had to look it up on wikipedia to find out that the acronym stands for generalized autoregressive conditional heteroskedasticity, which still doesn't tell me much.
  2. Your code doesn't shed much light on anything. There's not a single comment anywhere in it.
  3. Your variable names also aren't informative. They are slightly better than variable names I've seen in Fortran code, which are complete gibberish, but I have no idea what alpha, beta, omega, and so on are supposed to represent.
  4. You have a list named vP0 initialized to some random-appearing constants, with no explanation of what any of them represent.
  5. What are the "usual" values for a GARCH model?
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K