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

Click For Summary
The discussion centers on programming a GARCH model for exchange rates using Python. The user shares their code, which includes functions for estimating parameters and calculating log-likelihood. They report output values of approximately 0.0488 for omega, 0.1793 for alpha, and 0.7332 for beta but express concern that these values are not typical for a GARCH model. Responses highlight the need for clearer code documentation and variable naming, as well as a lack of understanding of what constitutes "usual" values for GARCH parameters. The conversation emphasizes the importance of clarity in coding practices and understanding model expectations.
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!
 
Technology news on Phys.org
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?
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

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