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

In summary: What values do you think you should be getting? Why do you think you should be getting those values?In summary, the conversation is about programming a GARCH model for exchange rates. The person has calculated the residuals and is using python to do the next steps. They have provided a code with functions for garch_filter and garch_loglike, but there are no comments or explanations for the variables and values used. They are unsure if the output they received is correct and are asking for clarification.
  • #1
Cyn
8
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
  • #2
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?
 

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

1. What is a GARCH model?

A GARCH (Generalized Autoregressive Conditional Heteroskedasticity) model is a statistical model used for analyzing and forecasting the volatility of a time series. It takes into account the autocorrelation and heteroskedasticity (unequal variances) of the data, making it more suitable for modeling financial data that often exhibit these characteristics.

2. Why would I want to estimate a GARCH model in python?

GARCH models are commonly used in finance and economics for forecasting volatility, risk management, and portfolio optimization. Python is a popular programming language for data analysis and has many useful libraries for time series analysis, making it a good tool for estimating GARCH models.

3. What are the steps for estimating a GARCH model in python?

The steps for estimating a GARCH model in python without using a standard function are as follows:

  • 1. Choose a suitable GARCH model (e.g. GARCH(1,1), EGARCH, etc.)
  • 2. Preprocess the data to remove any trends or seasonal patterns.
  • 3. Use a grid search or maximum likelihood estimation to find the optimal parameters for the chosen GARCH model.
  • 4. Fit the model to the data and evaluate the results.

4. Are there any limitations to estimating a GARCH model in python without a standard function?

Yes, there are a few limitations to consider when estimating a GARCH model in python without a standard function:

  • 1. It may be more time-consuming and require more coding compared to using a standard function.
  • 2. The accuracy of the results may be affected by the choice of optimization method and starting values for the parameters.
  • 3. It may be more difficult to handle complex GARCH models with multiple components or non-linear specifications.

5. Can I use a GARCH model for forecasting?

Yes, GARCH models are commonly used for forecasting volatility. However, it is important to note that GARCH models are not meant to be used as a standalone forecasting tool and should be combined with other forecasting methods for more accurate results.

Similar threads

Replies
1
Views
1K
Replies
3
Views
1K
Back
Top