| name | run-regression |
| description | Stage 2. Run a CAPM (and optionally 3-factor) regression on the fetched data. Write coefficients to state. Triggers when state.stage == "fetched". |
Run regression
Pre
Read state/state.json. Confirm state.stage == "fetched" and
state.artifacts.data_path exists.
Act
Load data/returns.csv. For each permno (or for the equal-weighted portfolio
if only one cross-section), run:
ret_excess = ret - rf
ret_excess ~ mkt_rf (CAPM)
Use statsmodels.OLS with HAC (Newey-West, 3 lags) standard errors.
Capture: alpha, beta, alpha_se, beta_se, n_obs, r2, converged.
Verify
converged == True
n_obs >= 24
abs(alpha) < 0.10 (sanity bound on monthly alpha)
0 < beta < 3 (sanity bound)
If any check fails: halt with reason.
Post
state.artifacts.regression = {alpha, beta, alpha_se, beta_se,
n_obs, r2, t_alpha, t_beta}
state.stage = "regressed"
state.last_action = {...}
Run python scripts/verify_state.py.