ARMA/GARCH estimation with standard errors

Click For Summary
SUMMARY

The discussion focuses on estimating parameters and standard errors for an ARMA/GARCH model using Python. The user employs the minimize function from an unspecified library to optimize the log-likelihood function garch_loglike, but encounters issues with the Hessian matrix, resulting in RuntimeWarning: overflow encountered in double_scalars and NaN outputs. Key functions include garch_filter, eps1, and garch_loglike, which are essential for the model's estimation process.

PREREQUISITES
  • Understanding of ARMA and GARCH models
  • Proficiency in Python programming
  • Familiarity with optimization techniques in Python, particularly minimize
  • Knowledge of numerical libraries such as NumPy and SciPy
NEXT STEPS
  • Investigate the implementation of the minimize function in SciPy
  • Learn about the calculation and interpretation of the Hessian matrix in optimization
  • Explore error handling in Python to manage runtime warnings effectively
  • Study the mathematical foundations of ARMA/GARCH models for better parameter estimation
USEFUL FOR

Data scientists, quantitative analysts, and researchers involved in time series analysis and financial modeling will benefit from this discussion.

Cyn
Messages
7
Reaction score
0
I want to estimate the parameters and standard errors of the following ARMA/GARCH model:

##y_t=a+b y_{t−6}+cy_{t−8}+dϵ_{t−1}+ϵ_t##​
##σ^2_t=ω+αϵ^2_{t−1}+βσ^2_{t−1}##​
The code I use is:
Code:
def main():
    x0 = (0.01,0.01,0.01,0.01,0.01, 0.01, 0.01)
    b = minimize(garch_loglike, x0, R_bel, bounds = ((None,None),(None,None),(None,None),(None,None),(0.0001, None), (0.0001, None), (0.0001, None)), options={'disp':True})
    print(b.x)
    value = garch_loglike(b.x, R_bel)
    print("Log likelihood value:", -value)

    a = nd.Hessian(garch_loglike)
    print(a(b.x, R_bel))
def garch_filter(omega, alpha, beta1, eps, R):
    iT = len(R)-8
    sigma_2 = np.zeros(iT)

    for i in range(iT):
        if i==0:
            sigma_2[i] = omega + alpha*eps[i-1]**2 + beta1*np.var(eps)
        else:
            sigma_2[i] = omega + alpha*eps[i-1]**2 + beta1*sigma_2[i-1]
    return sigma_2

def eps1(a, b, c, d, R):
    eps = np.zeros(len(R)-8)
    for t in range(len(R)-8):
        if t ==0:
            eps[t] = R[1]-R[0]
        else:
            eps[t] = R[t+8]-a - b*R[t+2] - c*R[t] -d*eps[t-1]
    return eps

def garch_loglike(vP, R):
    iT = len(R)
    a = vP[0]
    b=vP[1]
    c=vP[2]
    d=vP[3]
    omega = vP[4]
    alpha = vP[5]
    beta1 = vP[6]

    eps = eps1(a,b,c,d,R)
    sigma_2 = garch_filter(omega, alpha, beta1, eps, R)

    logL = -(-len(eps)/2 * np.log(2*math.pi) -0.5 *np.sum(np.log(sigma_2) + eps**2/sigma_2))
    return logL

Here, my data is R_bel. I get parameter estimates, but I do not get the hessian. I thought that with the hessian I could calculate the standard errors. But I get errors such as: RuntimeWarning: overflow encountered in double_scalars. And as output, I get a matrix with nan. How can I solve this problem?

Thank in advance!

[moderator; latex fixed]
 
Last edited by a moderator:
Technology news on Phys.org
Cyn said:
I want to estimate the parameters and standard errors of the following ARMA/GARCH model:

##y_t=a+b y_{t−6}+cy_{t−8}+dϵ_{t−1}+ϵ_t##​
##σ^2_t=ω+αϵ^2_{t−1}+βσ^2_{t−1}##​
The code I use is:
Code:
def main():
    x0 = (0.01,0.01,0.01,0.01,0.01, 0.01, 0.01)
    b = minimize(garch_loglike, x0, R_bel, bounds = ((None,None),(None,None),(None,None),(None,None),(0.0001, None), (0.0001, None), (0.0001, None)), options={'disp':True})
    print(b.x)
    value = garch_loglike(b.x, R_bel)
    print("Log likelihood value:", -value)

    a = nd.Hessian(garch_loglike)
    print(a(b.x, R_bel))
def garch_filter(omega, alpha, beta1, eps, R):
    iT = len(R)-8
    sigma_2 = np.zeros(iT)

    for i in range(iT):
        if i==0:
            sigma_2[i] = omega + alpha*eps[i-1]**2 + beta1*np.var(eps)
        else:
            sigma_2[i] = omega + alpha*eps[i-1]**2 + beta1*sigma_2[i-1]
    return sigma_2

def eps1(a, b, c, d, R):
    eps = np.zeros(len(R)-8)
    for t in range(len(R)-8):
        if t ==0:
            eps[t] = R[1]-R[0]
        else:
            eps[t] = R[t+8]-a - b*R[t+2] - c*R[t] -d*eps[t-1]
    return eps

def garch_loglike(vP, R):
    iT = len(R)
    a = vP[0]
    b=vP[1]
    c=vP[2]
    d=vP[3]
    omega = vP[4]
    alpha = vP[5]
    beta1 = vP[6]

    eps = eps1(a,b,c,d,R)
    sigma_2 = garch_filter(omega, alpha, beta1, eps, R)

    logL = -(-len(eps)/2 * np.log(2*math.pi) -0.5 *np.sum(np.log(sigma_2) + eps**2/sigma_2))
    return logL

Here, my data is R_bel. I get parameter estimates, but I do not get the hessian. I thought that with the hessian I could calculate the standard errors. But I get errors such as: RuntimeWarning: overflow encountered in double_scalars. And as output, I get a matrix with nan. How can I solve this problem?

Thank in advance!

[moderator; latex fixed]

There's not enough information here for us, or at least me, to be able to help.
How is the minimize function defined?
What is nd? In sum of your following code I see np, which I assume is a numpy class/module.
What does nd.Hessian() return? Presumably it returns a Hessian matrix.
One line of your code is a = nd.Hessian(garch_loglike). In the next line you have print (a(b.x, R_bel)) - this might be the cause of your error, due to two problems:
If a is a two-dimensional matrix, you need to use a pair of brackets - [] -for each index, as in a[2][3].
Second, the indexes in the matrix must be integer values. It's not likely that b.x and R_bel are integers.
 

Similar threads

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