Skip to content

puremacro 6.2.0

Choose a tag to compare

@jalonso1979 jalonso1979 released this 06 Nov 04:20
· 77 commits to main since this release

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=True on lp_iv and lp_state_dep_iv estimates integral
    multipliers directly: the outcome and the endogenous regressor become
    window sums over 0..h, the instrument stays dated at t. Results carry
    the flag is_cumulative and "(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 pages docs/first_brief_fiscal.md and docs/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.py and checked by the tests.
  • RZ_CONTROLS is public in the Ramey-Zubairy example; _CTL stays as an
    alias.
  • olea_pflueger_f, anderson_rubin_test, and msw_bands in
    puremacro.inference.weak_iv accept lags: int | None = None for
    Bartlett-HAC long-run covariance estimation (matching lp_iv when
    lags=h+1), and olea_pflueger_f accepts controls so raw x and z can
    be residualized inside the helper. (#217)
  • instrument_influence(z, controls=None, weights=None) in
    puremacro.inference.weak_iv (also re-exported from puremacro.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, and lp_garch_state accept
    state_lag: int = 0 to shift the regime state column by state_lag periods
    before evaluating transition weights $F(s_{t-\text{state_lag}})$.
    lp_state_dep_iv also 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_L when transition="logistic".
    (#217)
  • Archived Arellano (2008) calibration: grid convergence established.
    check_arellano_grids --calibration archive keeps 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.FiscalRule and solve_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 new policy_search="exhaustive"
    (or "dense"). States a hard rule leaves without an admissible choice raise
    ValueError naming them, or default for sure with infeasible="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_function and
    fit_stochastic_dsa_from_data (Bohn-style reaction estimates feeding the
    simulation), and simulate_fiscal_dsa / compare_fiscal_rules_dsa
    (transitions of solved fiscal models from high initial debt, with common
    random numbers across rules). StochasticDSAResult and
    FiscalReactionEstimateResult follow 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 through structural.fit_structural,
    with structural.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_osr and
    ssj_welfare_decomposition (linear-quadratic Ramsey and optimal simple rules
    on supplied sequence-space Jacobians); solve_risky_steady_state and
    solve_precautionary_obc (Coeurdacier–Rey–Winant risky steady state and a
    precautionary occasionally binding constraint).
  • Policy counterfactuals (puremacro.lp): mckay_wolf_counterfactual and
    barnichon_mesters_opp, from estimated policy-shock impulse responses.
  • SVAR identification (puremacro.var): svar_heteroskedastic,
    svar_non_gaussian, svar_proxy and svar_sign_narrative (SVARResult),
    and estimate_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.py and _es.py).

Changed

  • lp_state_dep and lp_state_dep_iv take interact={"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_state inherits the
    new default. (#217)
  • Both functions also return diff_HL, se_diff_HL and p_diff_HL (HAC test
    of β_H = β_L) and the effective regime sizes n_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 of inference.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. The robust dict's keys
    are now h, regime, beta, se, conv_lo, conv_hi, ar_lo, ar_hi,
    ar_set_type and f_eff; msw_lo, msw_hi, beta_2sls, se_2sls,
    n_slack, ar_at_point and ar_at_zero are gone. ar_horizon now
    defaults to 7, in the no-slack regime (it was 12, in the slack regime).
    linear is now an LPResult indexed by h. New keys: state_dep (the
    lp_state_dep_iv result) and expansion_iv (lp_iv on the no-slack
    quarters, with Anderson-Rubin sets).

Fixed

  • Pooled controls biased the regime coefficients. On the bundled
    Ramey–Zubairy snapshot, lp_state_dep_iv erased 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_iv and lp_smooth_transition_irf no longer swallow estimation
    errors: a horizon that cannot be estimated emits a RuntimeWarning naming
    the horizon and the exception, and its row is NaN. lp_smooth_transition_irf
    also emits a DeprecationWarning directing callers to
    lp_state_dep(..., transition="logistic").
  • msw_bands emits a RuntimeWarning and 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_iv explains 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.md document interact and the new columns.
  • The Ramey-Zubairy example no longer reads a missing unemployment rate as
    "no slack": slack_l stays NaN.
  • The SSJ guide example called ssj_ramsey with keywords it does not accept;
    it now uses target_weights and baseline_paths.
  • The fiscal grid ladder's solution cache no longer tries to store the
    non-array FiscalSovereignResult.rule field.
  • 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_FIRST in tests/conftest.py). pytest-xdist joins the dev
    extra; a plain pytest still 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_default now 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.