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

#### Cyn

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_2

def garch_loglike(vP, eps):
iT = len(eps)
omega = vP
alpha = vP
beta = vP

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!

Related Programming and Computer Science News on Phys.org

#### Mark44

Mentor
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_2

def garch_loglike(vP, eps):
iT = len(eps)
omega = vP
alpha = vP
beta = vP

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?

### Want to reply to this thread?

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

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving