def beta_ols_estimate_sample(npt, nsample):
    beta = numpy.zeros(nsample)
    for i in range(nsample):
        yt = brownian_motion(npt)
        xt = brownian_motion(npt)
        params, rsquard, err = arima.ols_estimate(xt, yt, False)
        beta[i] = params[1]
    return beta
Ejemplo n.º 2
0
ylab = r"$x_t$"
ensemble_plot(xt, [10.0, 100.0], title, ylab, plot_name)

# %%

title = f"ECM Ensemble, " + 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')}, size={m}"
plot_name = f"ecm_properties_ensemble_y_t{image_postfix}"
ylab = r"$y_t$"
yt = samples[1::2]
ensemble_plot(yt, [10.0, 60.0], title, ylab, plot_name)

# %%

β_estimate = numpy.zeros(m)
for i in range(m):
    params, rsquard, err = arima.ols_estimate(xt[i], yt[i], False)
    β_estimate[i] = params[1]

β_avg = numpy.mean(β_estimate)
β_std = numpy.std(β_estimate)

# %%

εt = yt - β_avg*xt

title = f"ECM Ensemble, " + 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')}, size={m}"
plot_name = f"ecm_properties_ensemble_ε_t{image_postfix}"
ylab = r"$\varepsilon_t$"
ensemble_plot(εt, [10.0, 3.0], title, ylab, plot_name)

# %%
Ejemplo n.º 3
0
    def f(x):
        return scipy.stats.norm.pdf(x, μ, σ)
    return f

# %%

arima_params = {"φ": numpy.array([0.5]), "δ": numpy.array([]), "d": 1}
ecm_params = {"δ": 0.0, "γ": 0.5, "λ": -0.5, "α": 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 = arima.ecm_sample_generate(arima_params, ecm_params, n)

# %%

params, rsquard, err = arima.ols_estimate(xt, yt)

# %%

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"ecm_parameter_estimation_β{image_postfix}"
regression_plot(xt, yt, params, err, rsquard, [0.85, 0.5], title, plot_name)

# %%

εt = yt - params[0] - params[1]*xt

# %%

arima.adf_report(εt)
# %%

xt = brownian_motion(npt)
yt = brownian_motion(npt)

title = f"Brownian Motion Series Comparison, n={npt}"
plot_name = "cointegration_spurious_correlation_distribution_time_series_example"
labels = [r"$x_t$", r"$y_t$"]
samples = numpy.array([xt, yt])

comparison_plot(title, samples, labels, plot_name)

# %%

params, rsquard, err = arima.ols_estimate(yt, xt)

# %%

title = f"Spurious Correlation of Independent Brownian Motion Time series, n={npt}"
plot_name = f"cointegration_spurious_correlation_distribution_spurious_correlation_regression"
regression_plot(yt, xt, params, err, rsquard, [0.7, 0.4], title, plot_name)


# %%

npt = 1000
nsample = 100000

β_estimate = beta_ols_estimate_sample(npt, nsample)