def test_recursion(self): """Test recursion.""" nobs = 10 ndim = 3 persistence = .99 beta = .85 volmean = .2 acorr = .05 bcorr = .9 rho = .5 param = np.array([acorr, bcorr, -.01]) const = np.eye(ndim) * (1 - acorr - bcorr) data, rho_series = DCC.simulate(nobs=nobs, ndim=ndim, volmean=volmean, persistence=persistence, beta=beta, acorr=acorr, bcorr=bcorr, rho=rho) data = data.values neg_data = data.copy() neg_data[neg_data > 0] = 0 qmat1 = np.zeros((nobs, ndim, ndim)) qmat2 = np.zeros((nobs, ndim, ndim)) qmat1[0] = const.copy() qmat2[0] = const.copy() corr_dcc1 = np.zeros((nobs, ndim, ndim)) corr_dcc2 = np.zeros((nobs, ndim, ndim)) dcc_recursion_python(qmat1, const, data, neg_data, param) dcc_recursion_numba(qmat2, const, data, neg_data, param) npt.assert_array_almost_equal(qmat1, qmat2) corr_dcc_python(corr_dcc1, qmat1) corr_dcc_numba(corr_dcc2, qmat2) npt.assert_array_almost_equal(corr_dcc1, corr_dcc2)
sns.set() nobs = 500 ndim = 3 persistence = .99 beta = .85 volmean = .2 acorr = .05 bcorr = .9 rho = .5 ret, rho_series = DCC.simulate(nobs=nobs, ndim=ndim, volmean=volmean, persistence=persistence, beta=beta, acorr=acorr, bcorr=bcorr, rho=rho) model = DCC(ret=ret) with take_time('Python'): result = model.fit(method='Nelder-Mead', numba=False) with take_time('Numba'): result = model.fit(method='Nelder-Mead', numba=True) print(model.data) model.data.plot_returns() model.data.plot_std_returns()
pd.set_option('float_format', '{:6.4f}'.format) np.set_printoptions(precision=4, suppress=True) sns.set() nobs = 500 ndim = 3 persistence = .99 beta = .85 volmean = .2 acorr = .05 bcorr = .9 rho = .5 ret, rho_series = DCC.simulate(nobs=nobs, ndim=ndim, volmean=volmean, persistence=persistence, beta=beta, acorr=acorr, bcorr=bcorr, rho=rho) model = DCC(ret=ret) with take_time('Python'): result = model.fit(method='Nelder-Mead', numba=False) with take_time('Numba'): result = model.fit(method='Nelder-Mead', numba=True) print(model.data) model.data.plot_returns() model.data.plot_std_returns() model.data.plot_innov()