示例#1
0
def pacf_regression_method(samples, max_lag):
    pacf = numpy.ones(max_lag+1)
    for i in range(1, max_lag+1):
        model = arima.arma_estimate_parameters(samples, (i, 0))
        pacf[i] = model.params[i-1]
    return pacf
# %%

arima.adf_report(εt)

# %%

title = f"ECM Simulation, " + r"$\phi=$" + f"{numpy.array2string(arima_params['φ'], precision=2, separator=',')}, " + r"$\lambda=$" + f"{format(ecm_params['λ'], '2.2f')}, " + r"$\beta=$" + f"{format(ecm_params['β'], '2.2f')}, " + r"$\gamma=$" + f"{format(ecm_params['γ'], '2.2f')}, " + r"$\sigma=$" + f"{format(ecm_params['σ'], '2.2f')}"
plot_name = f"cointegration_ecm_simulation_acf_pacf{image_postfix}"
max_lag = 15
ylim = [-0.5, 1.1]
arima.acf_pcf_plot(title, εt, ylim, max_lag, plot_name)

# %%

model_fit = arima.arma_estimate_parameters(εt, (1, 0))
print(model_fit.summary())

# %%

arima_params = {"φ": numpy.array([0.5]), "δ": numpy.array([]), "d": 1}
ecm_params = {"δ": 0.0, "γ": 0.5, "λ": -1.0, "α": 0.0, "β": 0.5, "σ": 1.0}
n = 1000
image_postfix = f"_φ_{format(arima_params['φ'][0], '1.1f')}_β_{format(ecm_params['β'], '1.1f')}_λ_{format(ecm_params['λ'], '1.1f')}_γ_{format(ecm_params['γ'], '1.1f')}_σ_{format(ecm_params['σ'], '1.1f')}"

xt, yt = ecm_sample_generate(arima_params, ecm_params, n)

# %%

params, rsquard, err = ols_correlation_estimate(xt, yt)
model_fit = arima.arima_estimate_parameters(arima1, (1, 1, 0))
print(model_fit.summary())

# %%

arima.adf_report(arima1)

# %%

arima.adf_report(darima1)


# %%

model_fit = arima.arma_estimate_parameters(darima1, (1, 0))
print(model_fit.summary())

# %%

title = r"ARIMA(1,1,0) $\Delta x_t$ ACF-PACF Comparison: " + r"$\phi=$"+f"{numpy.array2string(φ1, precision=2, separator=',')}, " + r"$\delta=$"+f"{numpy.array2string(δ1, precision=2, separator=',')}"
plot_name = "aima_estimation_1_1_0_pacf_acf_Δx_comparison"
max_lag = 15
ylim = [-0.1, 1.1]
arima.acf_pcf_plot(title, darima1, ylim, max_lag, plot_name)

# %%

title = "ARIMA(1,1,0) Residual Distribution Comparison with Normal(0, 1)"
plot_name = "aima_estimation_1_1_0_residual_distribution"
pdf_samples(title, normal_pdf(0.0, 1.0), model_fit.resid, plot_name, xrange=None, ylimit=None)