Repository navigation
puremacro 6.2.0
Fiscal rules & debt-sustainability analysis, state-dependent LP & weak-IV HAC diagnostics, sequence-space optimal policy, SVAR identification, GIV, and investment-research workflows.
Added
- Experimental investment-research kernels in
asset_pricing: lagged,
self-financing long-only backtests with cash, costs, eligibility and JSON replay;
Ledoit–Wolf covariance, bounded mean/minimum-variance allocation and frontier;
causal technical indicators, momentum policies and a block-bootstrap max test;
availability-dated fundamentals, financial ratios, FCFF/FCFE/dividend valuation
and sensitivity; Brock–Hommes affine-belief dynamics with explicit fitness timing.
No new runtime dependencies or bundled market data. Bilingual guides and
executed notebooks document numerical checks, timing and unsupported extensions. -
cumulative=Trueonlp_ivandlp_state_dep_ivestimates integral
multipliers directly: the outcome and the endogenous regressor become
window sums over0..h, the instrument stays dated att. Results carry
the flagis_cumulativeand "(cumulative)" method labels. Window sums need
a regular index, so an irregular date or period index raises an error.
(#217) -
python -m puremacro.examples.first_brief_fiscal [--lang es]writes a
bilingual fiscal policy brief on the Ramey-Zubairy historical data, with
the pagesdocs/first_brief_fiscal.mdanddocs/es/first_brief_fiscal.md.
It reports linear and slack/no-slack cumulative spending multipliers at 2
and 4 years, quotes weak cells by Anderson-Rubin sets, runs the
experiment without WWII under the RZ rule and reports a concentration
diagnostic. The page numbers come from a frozen record, refreshed with
tools/reference_validation/refresh_fiscal_brief.pyand checked by the tests. -
RZ_CONTROLSis public in the Ramey-Zubairy example;_CTLstays as an
alias. -
olea_pflueger_f,anderson_rubin_test, andmsw_bandsin
puremacro.inference.weak_ivacceptlags: int | None = Nonefor
Bartlett-HAC long-run covariance estimation (matchinglp_ivwhen
lags=h+1), andolea_pflueger_facceptscontrolsso rawxandzcan
be residualized inside the helper. (#217) -
instrument_influence(z, controls=None, weights=None)in
puremacro.inference.weak_iv(also re-exported frompuremacro.inference)
computes per-observation shares of residualized instrument variation
$\tilde{z}_t^2 / \sum_s \tilde{z}_s^2$ , effective sample size
$1 / \sum_t w_t^2$ , and max share / top indices to flag outlier-driven first
stages. (#217) -
lp_state_dep,lp_state_dep_iv, andlp_garch_stateaccept
state_lag: int = 0to shift the regime state column bystate_lagperiods
before evaluating transition weights$F(s_{t-\text{state_lag}})$ .
lp_state_dep_ivalso reports Sanderson–Windmeijer (2016) conditional
first-stage F statistics (cond_f_H,cond_f_L) and uses them for
first_stage_f_H/first_stage_f_Lwhentransition="logistic".
(#217) - Archived Arellano (2008) calibration: grid convergence established.
check_arellano_grids --calibration archivekeeps the author's exclusion
timing, Fortran default-real literals and midpoint-refined 200-node grid.
Under the public ladder's pre-registered tolerances and precision rule, 797 to
6,369 debt nodes and 321/641 income states pass both final refinements. The
standard design left one bound unclassified (debt/output, income direction);
it is kept in the record. On converged grids spread volatility is about
2.9 pp against the published 6.36, and the trade-balance–spread correlation
about 0.82 against 0.43. Spread volatility still falls along the income
direction: extrapolation places its limit 0.07–0.14 pp lower. Nothing is
recalibrated. Record:tests/fixtures/arellano_2008/archive_grid_convergence.json;
guide. -
puremacro.sovereign.FiscalRuleandsolve_fiscal_sovereign_default(rule=...):
debt ceilings, deficit limits, escape clauses and soft (penalty) rules,
priced by lenders. Ceilings, escapes and penalties use the certified
monotone search; deficit limits use the newpolicy_search="exhaustive"
(or"dense"). States a hard rule leaves without an admissible choice raise
ValueErrornaming them, or default for sure withinfeasible="default". - Predictions about the rules were registered before any rule solve
(tests/fixtures/sovereign_fiscal/rule_predictions_protocol.json) and
measured on a coarse 401 x 21 grid by
tools/reference_validation/check_fiscal_rule_predictions.py; the guide
reports each verdict, including the one that did not hold. - Debt-sustainability analysis (
puremacro.sovereign):
simulate_stochastic_dsa(reduced-form debt fan charts with a
FiscalReactionFunction),estimate_fiscal_reaction_functionand
fit_stochastic_dsa_from_data(Bohn-style reaction estimates feeding the
simulation), andsimulate_fiscal_dsa/compare_fiscal_rules_dsa
(transitions of solved fiscal models from high initial debt, with common
random numbers across rules).StochasticDSAResultand
FiscalReactionEstimateResultfollow the result-object conventions. The
structural trajectories are illustrative 401 × 21 calculations, not
grid-converged. -
calibrate_fiscal_sovereign_smm(SovereignSMMResult): simulated method of
moments for the fiscal sovereign model throughstructural.fit_structural,
withstructural.ags_sensitivity(AGSSensitivityResult) for
Andrews–Gentzkow–Shapiro sensitivity. Local inference is withheld, with a
warning, when the moment Jacobian is rank-deficient or a parameter sits on a
bound. - Sequence-space policy (
puremacro.dsge):ssj_ramsey,ssj_osrand
ssj_welfare_decomposition(linear-quadratic Ramsey and optimal simple rules
on supplied sequence-space Jacobians);solve_risky_steady_stateand
solve_precautionary_obc(Coeurdacier–Rey–Winant risky steady state and a
precautionary occasionally binding constraint). - Policy counterfactuals (
puremacro.lp):mckay_wolf_counterfactualand
barnichon_mesters_opp, from estimated policy-shock impulse responses. - SVAR identification (
puremacro.var):svar_heteroskedastic,
svar_non_gaussian,svar_proxyandsvar_sign_narrative(SVARResult),
andestimate_functional_var(FunctionalVARResult) for yield curves and
distributions. -
puremacro.inference.estimate_giv(GIVResult): granular instrumental
variables. -
puremacro.portfolio: covariance shrinkage, mean-variance and target-return
optimization, efficient frontiers, hierarchical risk parity, Black–Litterman,
macro-quadrant classification and an all-weather allocation, factor
attribution, rebalancing backtests with transaction costs and Monte Carlo
wealth glidepaths. - Bilingual guides for these additions and showcase notebook 76
(notebooks/76_bilingual_macro_showcase.pyand_es.py).
Changed
lp_state_depandlp_state_dep_ivtakeinteract={"all", "intercept", "none"}, default"all": the constant and every control (lags and
contemporaneous controls) are interacted with the regime weight, as in
Ramey–Zubairy (2018, eq. 2) and the direct projections of
Auerbach–Gorodnichenko (2013). With a threshold transition the point
estimates equal one regression per regime. Behaviour change: 6.1.0 and
earlier pooled the intercept and the control coefficients across regimes;
interact="none"reproduces those results (relative difference below
1e-9 on the bundled Ramey–Zubairy snapshot).lp_garch_stateinherits the
new default. (#217)- Both functions also return
diff_HL,se_diff_HLandp_diff_HL(HAC test
of β_H = β_L) and the effective regime sizesn_eff_H,n_eff_L. - The Ramey-Zubairy example: the headline is now at h = 7 and 15 (the 8- and
16-quarter integrals), which reproduce Table 1. The state layer is one-step
lp_state_dep_iv, with standard errors. Weak-IV diagnostics use the HAC
effective F and the HAC Anderson-Rubin set, so the example no longer uses
the non-HAC helpers ofinference.weak_iv. Teaching assertions that did not hold under HAC statistics were
replaced: the slack F does not collapse at long horizons (55.9 at h = 20),
and the robust set is wider than the conventional band in the no-slack
regime (1.28 times at h = 7), not in the slack regime (1.02). The figure is
regenerated. The linear and no-slack headlines, whose instrument is weak
(effective F 16.0 / 12.0 and 7.3 / 10.8), are reported with their
Anderson-Rubin 90% sets. Compatibility: scripts that read
run_rz_replication()'s output must be updated. Therobustdict's keys
are nowh,regime,beta,se,conv_lo,conv_hi,ar_lo,ar_hi,
ar_set_typeandf_eff;msw_lo,msw_hi,beta_2sls,se_2sls,
n_slack,ar_at_pointandar_at_zeroare gone.ar_horizonnow
defaults to 7, in the no-slack regime (it was 12, in the slack regime).
linearis now anLPResultindexed by h. New keys:state_dep(the
lp_state_dep_ivresult) andexpansion_iv(lp_ivon the no-slack
quarters, with Anderson-Rubin sets).
Fixed
- Pooled controls biased the regime coefficients. On the bundled
Ramey–Zubairy snapshot,lp_state_dep_iverased the slack/no-slack gap once
World War II is excluded (0.70/0.69 against 1.07/0.49 with everything
interacted) and returned explosive estimates on the post-1947 sample
(+2538 at 16 quarters). lp_state_dep_ivandlp_smooth_transition_irfno longer swallow estimation
errors: a horizon that cannot be estimated emits aRuntimeWarningnaming
the horizon and the exception, and its row is NaN.lp_smooth_transition_irf
also emits aDeprecationWarningdirecting callers to
lp_state_dep(..., transition="logistic").msw_bandsemits aRuntimeWarningand returns(nan, nan)when the
Anderson-Rubin confidence set is empty on the grid (instead of silently
returning the argmin point estimate), and warns when the accepted set touches
the grid boundary (unbounded/truncated) or is disconnected.
(#217)- Docstrings:
lp_state_dep_ivexplains how to obtain Ramey–Zubairy's
integral multiplier instead of claiming to estimate it directly; both
functions state that the state is used as dated (Ramey–Zubairy and
Auerbach–Gorodnichenko date it at t−1), that the high regime is the one with
high values of the state, and that the index must be contiguous (blank the
shock or instrument instead of dropping rows). The Ramey–Zubairy example no
longer says that pooling moves results "at the second decimal", and
docs/lp.md/docs/es/lp.mddocumentinteractand the new columns. - The Ramey-Zubairy example no longer reads a missing unemployment rate as
"no slack":slack_lstays NaN. - The SSJ guide example called
ssj_ramseywith keywords it does not accept;
it now usestarget_weightsandbaseline_paths. - The fiscal grid ladder's solution cache no longer tries to store the
non-arrayFiscalSovereignResult.rulefield. - Python 3.11 floor typing in
ssj_ramsey(Gate 8).
Internal
- CI runs the test suite in parallel. Run serially, the suite took about 122
of the 128 minutes of the longest leg while the runner's other cores sat
idle. Each leg now runs
pytest -n auto --dist loadfile --no-loadscope-reorder, with one BLAS
thread per worker and the slowest test files started first
(_HEAVY_FIRSTintests/conftest.py).pytest-xdistjoins thedev
extra; a plainpyteststill runs serially. - mypy, the release gate and the strict docs build run in their own
checks
job beside the test legs. A new commit on a pull request cancels that pull
request's CI run in progress; pushes to main and release runs are never
cancelled. - Under
pytest -n, workers hand the socket guard's blocked attempts to the
controller, so the end-of-run summary still lists them
(tests/test_parallel_runs.py). solve_sovereign_defaultnow calls a private Bellman core parameterized by
resources, a choice utility and an income-only flow. Results are
bit-identical to 6.0.1 (pinned against a verbatim copy of the 6.0.1 solver,
dense and monotone, short- and long-term debt). The independent
sovereign-extension record was regenerated: every check and number is
unchanged, only source hashes differ.- The monotone and exhaustive policy searches accept column and transition
penalties; without them every operation is unchanged. Income-column
batching in the monotone search passes the column penalty per batch.