Source code for naginterfaces.library.examples.tsa.uni_garch_asym1_ex

#!/usr/bin/env python3
"``naginterface.library.tsa.uni_garch_asym1`` Python Example."

# NAG Copyright 2017-2019.

# pylint: disable=invalid-name,too-many-locals

from naginterfaces.library import tsa

[docs]def main(): """ Example for :func:`naginterfaces.library.tsa.uni_garch_asym1`. Type-I AGARCH parameter estimation and forecasting. >>> main() naginterfaces.library.tsa.uni_garch_asym1 Python Example Results. Fit a GARCH(1,1) model with Student's t-distributed residuals. Parameter Standard estimates errors alpha_0 0.00 0.06 alpha_1 0.11 0.13 beta_1 0.66 0.23 gamma -0.62 0.62 df 6.25 4.70 b_0 3.85 24.11 b_1 1.48 1.82 b_2 2.15 10.16 Volatility forecast = 0.09 """ print('naginterfaces.library.tsa.uni_garch_asym1 Python Example Results.') print('Fit a GARCH(1,1) model with Student\'s t-distributed residuals.') # The observations and the exogenous vectors: yt, x = get_data() # The details of the model to fit: dist = 'T' ip = 1 iq = 1 isym = 1 # Include the mean term mn = 1 # The control parameters: copts = [True, True] maxit = 200 tol = 0.00001 # The initial parameter estimates for theta: theta = [ 0.05, # alpha_0 0.10, # alpha_1 0.15, # beta_1 -0.10, # gamma 2.60, # df 1.50, # b_0 0., # b_1, not required 0., # b_2, not required ] # Pre-observed conditional variance not required: hp = 0. g_estim = tsa.uni_garch_asym1_estim( dist, yt, x, ip, iq, mn, isym, theta, hp, copts, maxit, tol, ) # The forecast horizon: nt = 4 fht = tsa.uni_garch_asym1_forecast( nt, ip, iq, g_estim.theta[:iq+ip+1], g_estim.theta[iq+ip+1], g_estim.ht, g_estim.et, ) print(' Parameter Standard') print(' estimates errors') for i in range(iq+1): print( 'alpha_{:d} {:16.2f}{:16.2f}'.format( i, g_estim.theta[i], g_estim.se[i] ) ) for i in range(ip): print( ' beta_{:d} {:16.2f}{:16.2f}'.format( i+1, g_estim.theta[iq+1+i], g_estim.se[iq+1+i] ) ) print( ' gamma {:16.2f}{:16.2f}'.format( g_estim.theta[iq+ip+1], g_estim.se[iq+ip+1] ) ) print( ' df {:16.2f}{:16.2f}'.format( g_estim.theta[iq+ip+2], g_estim.se[iq+ip+2] ) ) for i in range(len(x[0])+1): print( ' b_{:d} {:16.2f}{:16.2f}'.format( i, g_estim.theta[iq+ip+3+i], g_estim.se[iq+ip+3+i] ) ) print('Volatility forecast = {:12.2f}'.format(fht[-1]))
def get_data(): """ The observations and the exogenous vectors. """ # The observations: yt = [ 9.04, 9.49, 9.12, 9.23, 9.35, 9.09, 9.75, 9.23, 8.76, 9.17, 9.20, 9.64, 8.74, 9.23, 9.42, 9.70, 9.55, 10.00, 9.18, 9.77, 9.80, 9.56, 9.28, 9.68, 9.51, 9.51, 8.97, 9.30, 9.52, 9.41, 9.53, 9.75, 9.72, 9.38, 9.28, 9.42, 9.74, 9.75, 9.60, 9.90, 9.06, 9.92, 9.21, 9.57, 9.42, 8.65, 8.85, 9.61, 10.77, 10.19, 10.47, 10.10, 10.21, 9.96, 9.66, 9.79, 10.30, 9.68, 10.08, 10.38, 9.69, 9.02, 9.89, 10.46, 10.47, 9.99, 9.76, 9.78, 9.62, 10.43, 10.42, 9.95, 9.95, 9.70, 10.24, 9.78, 9.98, 8.73, 10.23, 9.10, 10.27, 9.85, 10.44, 10.30, 10.08, 10.20, 10.14, 9.89, 9.90, 11.33, 9.71, 9.40, 9.97, 10.92, 9.76, 10.16, 10.43, 9.60, 10.29, 10.03, ] # The exogenous vectors: x = [ [0.12, 2.40], [0.12, 2.40], [0.13, 2.40], [0.14, 2.40], [0.14, 2.40], [0.15, 2.40], [0.16, 2.40], [0.16, 2.40], [0.17, 2.40], [0.18, 2.41], [0.19, 2.41], [0.19, 2.41], [0.20, 2.41], [0.21, 2.41], [0.21, 2.41], [0.22, 2.41], [0.23, 2.41], [0.23, 2.41], [0.24, 2.41], [0.25, 2.42], [0.25, 2.42], [0.26, 2.42], [0.26, 2.42], [0.27, 2.42], [0.28, 2.42], [0.28, 2.42], [0.29, 2.42], [0.30, 2.42], [0.30, 2.42], [0.31, 2.43], [0.32, 2.43], [0.32, 2.43], [0.33, 2.43], [0.33, 2.43], [0.34, 2.43], [0.35, 2.43], [0.35, 2.43], [0.36, 2.43], [0.37, 2.43], [0.37, 2.44], [0.38, 2.44], [0.38, 2.44], [0.39, 2.44], [0.39, 2.44], [0.40, 2.44], [0.41, 2.44], [0.41, 2.44], [0.42, 2.44], [0.42, 2.44], [0.43, 2.45], [0.43, 2.45], [0.44, 2.45], [0.45, 2.45], [0.45, 2.45], [0.46, 2.45], [0.46, 2.45], [0.47, 2.45], [0.47, 2.45], [0.48, 2.45], [0.48, 2.46], [0.49, 2.46], [0.49, 2.46], [0.50, 2.46], [0.50, 2.46], [0.51, 2.46], [0.51, 2.46], [0.52, 2.46], [0.52, 2.46], [0.53, 2.46], [0.53, 2.47], [0.54, 2.47], [0.54, 2.47], [0.54, 2.47], [0.55, 2.47], [0.55, 2.47], [0.56, 2.47], [0.56, 2.47], [0.57, 2.47], [0.57, 2.47], [0.57, 2.48], [0.58, 2.48], [0.58, 2.48], [0.59, 2.48], [0.59, 2.48], [0.59, 2.48], [0.60, 2.48], [0.60, 2.48], [0.61, 2.48], [0.61, 2.48], [0.61, 2.49], [0.62, 2.49], [0.62, 2.49], [0.62, 2.49], [0.63, 2.49], [0.63, 2.49], [0.63, 2.49], [0.64, 2.49], [0.64, 2.49], [0.64, 2.49], [0.64, 2.50], ] return yt, x if __name__ == '__main__': import doctest import sys sys.exit( doctest.testmod( None, verbose=True, report=False, optionflags=doctest.REPORT_NDIFF, ).failed )