pval_tau_min[out_key] = res.tau_min
    pval_tau_max[out_key] = res.tau_max
    pval_tau_star[out_key] = res.tau_star


header = f'''\
"""
Critical values produced by phillips-ouliaris-simulation.py

{counts}
"""

from math import inf

'''

formatted_code = header + "CV_PARAMETERS = " + format_dict(cv_params)
formatted_code += "\n\nCV_TAU_MIN = " + format_dict(cv_tau_min)
formatted_code += "\n\nPVAL_LARGE_P = " + format_dict(pval_large_p)
formatted_code += "\n\nPVAL_SMALL_P = " + format_dict(pval_small_p)
formatted_code += "\n\nPVAL_TAU_MAX = " + format_dict(pval_tau_max)
formatted_code += "\n\nPVAL_TAU_STAR = " + format_dict(pval_tau_star)
formatted_code += "\n\nPVAL_TAU_MIN = " + format_dict(pval_tau_min)

targets = {TargetVersion.PY36, TargetVersion.PY37, TargetVersion.PY38}
fm = FileMode(target_versions=targets)
formatted_code = format_file_contents(formatted_code, fast=False, mode=fm)

with open("../phillips_ouliaris.py", "w") as po:
    po.write(formatted_code)
Beispiel #2
0
            all_results.append(data["results"])
    results = np.hstack(all_results)
    cols = TIME_SERIES_LENGTHS.tolist() * len(data_files)
    results = pd.DataFrame(results, index=PERCENTILES / 100.0, columns=cols)

    cv_approx = estimate_cv_regression(results, critical_values)
    adf_z_cv_approx[trend] = [cv_approx[cv] for cv in critical_values]

    pvals = fit_pval_model(results[2000], small_order=4, use_log=True)
    adf_z_max[trend] = pvals.tau_max
    adf_z_min[trend] = pvals.tau_min
    adf_z_star[trend] = pvals.tau_star
    adf_z_small_p[trend] = pvals.small_p
    adf_z_large_p[trend] = pvals.large_p

formatted_code = "adf_z_min = " + format_dict(adf_z_min)
formatted_code += "\n\nadf_z_star = " + format_dict(adf_z_star)
formatted_code += "\n\nadf_z_max = " + format_dict(adf_z_max)
formatted_code += "\n\n# The small p parameters are for np.log(np.abs(stat))\n"
formatted_code += "adf_z_small_p = " + format_dict(adf_z_small_p)
formatted_code += "\n\nadf_z_large_p = " + format_dict(adf_z_large_p)
formatted_code += "\n\nadf_z_cv_approx = " + format_dict(adf_z_cv_approx)

with open("../dickey_fuller.py", "r") as cvs:
    lines = cvs.readlines()

retain = []
for line in lines:
    if "# Z values from" in line:
        break
    retain.append(line)
        for i in range(all_lhs.shape[1]):
            lhs = all_lhs[:, i, :].ravel()
            res = OLS(lhs, rhs).fit()
            params = res.params.copy()
            if res.pvalues[-1] > 0.05:
                params[-1] = 0.00
            out[cv].append(params)
        values = np.array(out[cv]).tolist()
        out[cv] = [[round(val, 5) for val in row] for row in values]

    final_cv[trend] = dict(out)

final_cv["n"] = final_cv["nc"]
del final_cv["nc"]
formatted_str = format_dict(final_cv)

header = """
import numpy as np

eg_num_variables = np.arange(1, 13)
"""

targets = {TargetVersion.PY36, TargetVersion.PY37, TargetVersion.PY38}
fm = FileMode(target_versions=targets)
formatted_code = header + "CV_PARAMETERS = " + formatted_str

# %%
large_p = {}
small_p = {}
tau_max = {}