SPB Git

Repository Public Research preview

10_export_for_cpp.py 1.3 KB 26 lines python

1"""Export estimation panels as plain text for the C++ placebo/power program (src/cpp/placebo.cpp)."""2import numpy as np3import pandas as pd45from config import DER67INP, OUT = DER / "perm_inputs", DER / "cpp_inputs"8OUT.mkdir(exist_ok=True)9CTL = ["r_brent", "d_vix", "r_usd", "d_y2"]10for ten in ["1M", "3M", "1Y"]:11    d0 = pd.read_parquet(INP / f"daily_{ten}.parquet")12    for y in ["d_cr25", "d_cr10"]:13        for shock, other in (("u_pol", "u_phy"), ("u_phy", "u_pol")):14            d = d0.dropna(subset=[y, shock, other] + CTL).copy()15            d["ui"] = pd.factorize(d.ccy)[0]16            dates = np.sort(d.date.unique()); d["ti"] = np.searchsorted(dates, d.date.values)17            u = d.groupby("ti")[shock].first().reindex(range(len(dates))).values18            cols = [other] + CTL                                    # the other climate shock is a fixed control19            M = np.column_stack([d.ui, d.ti, d[y], d.F] + [d[c] * d.F for c in cols])20            f = OUT / f"{ten}_{y}_{shock}.txt"21            with open(f, "w") as h:22                h.write(f"{d.ui.max()+1} {len(dates)} {len(d)} {len(cols)}\n")23                h.write(" ".join(f"{v:.10g}" for v in u) + "\n")24                np.savetxt(h, M, fmt=["%d", "%d"] + ["%.10g"] * (2 + len(cols)))25            print(f.name, len(d))26
Files main
Menu

Theme