Skip to content

frequency-conversion in macro-data initialization#85

Open
agurgone wants to merge 9 commits into
mainfrom
bug/macrodata-frequency
Open

frequency-conversion in macro-data initialization#85
agurgone wants to merge 9 commits into
mainfrom
bug/macrodata-frequency

Conversation

@agurgone

Copy link
Copy Markdown
Contributor

Summary

Depends on PR #83.

This PR fixes several frequency-conversion issues in macro-data initialization. The main problem was that some data sources were implicitly treated as quarterly even when the model was configured with a different time_unit. This could produce incorrectly scaled household cash flows, exogenous series, firm flows, and initial loan values.

Issue

The model configuration defines the number of model periods per year through time_unit, but several initialization paths still used hard-coded quarterly assumptions.

Examples included:

  • HFCS income and monthly cash-flow variables being divided by hard-coded quarterly factors.
  • HFCS monthly variables such as rent, mortgage payments, consumer loan payments, pension contributions, transfers, and insurance payments not being consistently converted into model-period values.
  • Exogenous quarterly source data being consumed without conversion to the configured model frequency.
  • Compustat quarterly firm flow variables not being adjusted for the configured period length.
  • Loan maturity defaults in data configuration being duplicated rather than sourced from the model defaults.
  • Initial credit-market totals summing the full loan stack rather than principal balances only.

These issues can materially distort initialization, especially when using a non-quarterly time_unit.

Changes

  • Added explicit yearly_factor = 12 / time_unit plumbing through macro-data readers and synthetic population initialization.
  • Rescaled HFCS monthly variables into model-period values.
  • Replaced hard-coded quarterly income scaling with configuration-driven scaling.
  • Added monthly HFCS variable mappings for housing, debt service, and other cash-flow variables.
  • Converted exogenous quarterly growth rates and level series to the configured model period.
  • Updated exogenous period lookup to use timestamps/model-period starts rather than quarter-string assumptions.
  • Updated annual exchange-rate handling to repeat values according to the configured number of model periods per year.
  • Updated Compustat firm/bank readers to respect the configured simulation quarter and time_unit.
  • Scaled active quarterly Compustat flow variables according to the configured period.
  • Added tests for Compustat period handling.
  • Sourced data loan maturity defaults from BankParameters instead of duplicating hard-coded values.
  • Clarified that configured maturities are model periods, not months.
  • Fixed initial credit-market time-series totals to use principal balances only.

Notes

The FRA data config still stores loan maturities in model periods. This PR does not convert config values from months at runtime; instead, it makes the expectation explicit and aligns defaults with the model configuration.

Validation

Ran targeted validation before committing:

  • ruff check on touched Python files
  • git diff --check
  • tests/test_macro_data/unit/test_data_wrapper.py
  • targeted macro-data/macromodel pytest suite covering:
    • exogenous readers
    • Compustat readers
    • configuration
    • synthetic population
    • synthetic firms/banks
    • central government
    • credit market
    • country/exogenous simulation compatibility

Result: targeted tests passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant