def obj(params): p.params = spec.constrain_params(params) return -arma_innovations.arma_loglike( endog, ar_params=-p.reduced_ar_poly.coef[1:], ma_params=p.reduced_ma_poly.coef[1:], sigma2=p.sigma2)
def test_innovations_algo_filter_kalman_filter(ar_params, ma_params, sigma2): # Test the innovations algorithm and filter against the Kalman filter # for exact likelihood evaluation of an ARMA process endog = np.random.normal(size=100) # Innovations algorithm approach llf = arma_innovations.arma_loglike(endog, ar_params, ma_params, sigma2) llf_obs = arma_innovations.arma_loglikeobs(endog, ar_params, ma_params, sigma2) score = arma_innovations.arma_score(endog, ar_params, ma_params, sigma2) score_obs = arma_innovations.arma_scoreobs(endog, ar_params, ma_params, sigma2) # Kalman filter apparoach mod = SARIMAX(endog, order=(len(ar_params), 0, len(ma_params))) params = np.r_[ar_params, ma_params, sigma2] # Test that the two approaches are the same assert_allclose(llf, mod.loglike(params)) assert_allclose(llf_obs, mod.loglikeobs(params)) # Note: the tolerance on the two gets worse as more nobs are added assert_allclose(score, mod.score(params), atol=1e-5) assert_allclose(score_obs, mod.score_obs(params), atol=1e-5)