ARMA/GARCH estimation with standard errors

AI Thread Summary
The discussion centers on estimating parameters and standard errors for an ARMA/GARCH model using Python code. The user encounters issues when trying to compute the Hessian matrix, receiving errors such as "RuntimeWarning: overflow encountered in double_scalars" and resulting in a matrix filled with NaN values. The code includes functions for estimating parameters, filtering GARCH, and calculating log-likelihood. Key points of concern include the definition of the `minimize` function, the role of `nd` (presumably a numerical differentiation library), and the correct indexing of the Hessian matrix. The user is advised to ensure proper indexing and data types when accessing matrix elements, as this may contribute to the encountered errors.
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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Back
Top