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

Click For Summary
SUMMARY

This discussion focuses on estimating a GARCH (Generalized Autoregressive Conditional Heteroskedasticity) model for exchange rates using Python. The user implemented a custom GARCH model by defining functions for log-likelihood estimation and filtering, utilizing the SciPy library's minimize function. The output parameters obtained were [0.04881267, 0.17925725, 0.73315972], which the user questioned in terms of their validity compared to typical GARCH model values. The discussion highlights the need for clearer variable naming and documentation in the code for better understanding.

PREREQUISITES
  • Understanding of GARCH models and their applications in financial time series analysis.
  • Proficiency in Python programming, specifically with NumPy and SciPy libraries.
  • Familiarity with optimization techniques, particularly the use of the minimize function.
  • Basic knowledge of statistical concepts such as log-likelihood estimation.
NEXT STEPS
  • Research the theoretical foundations of GARCH models and their typical parameter values.
  • Learn how to implement GARCH models using the 'arch' library in Python for comparison.
  • Explore best practices for naming conventions and documentation in Python code.
  • Investigate methods for validating GARCH model outputs against known benchmarks.
USEFUL FOR

Data scientists, quantitative analysts, and financial engineers interested in modeling volatility in financial time series using GARCH models in Python.

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?
 

Similar threads

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