Skip to content

Milestone 1: accounting core (§2.2 matrices + §5 calibration) — clean-room from the manual - #3

Merged
vahid-ahmadi merged 1 commit into
mainfrom
milestone-1-accounting-core
Aug 4, 2026
Merged

Milestone 1: accounting core (§2.2 matrices + §5 calibration) — clean-room from the manual#3
vahid-ahmadi merged 1 commit into
mainfrom
milestone-1-accounting-core

Conversation

@vahid-ahmadi

Copy link
Copy Markdown
Contributor

What this does

Implements milestone 1 of the DEFINE-UK clean-room reimplementation (REIMPLEMENTATION.md): the accounting core, built only from the published Model Manual v1.1 — the upstream R code was not read.

  • src/define_uk/model/calibration.py — manual §5 transcribed in full: Table 5 (parameters/exogenous variables, pp. 53–62) and Table 6 (initial values for endogenous variables, pp. 63–79), with documented symbol-normalization rules. SUBS_GVT/SUBS_PS have no §5 entry (scenario-only instruments) and are set to 0.0 with a TODO note.
  • src/define_uk/model/accounting.py — machine-readable §2.2 Table 1 (transactions flow matrix) and Table 2 (balance-sheet matrix): every cell is a linear combination of model variables, every row carries a manual_ref to the §3 equations it rests on. transactions_residuals(state) and balance_sheet_residuals(state) return per-row and per-column residuals, including the residual transaction (DISC) and residual financial instrument (RES) closures.
  • tests/test_accounting.py — the milestone gate: 27 identity tests on the §5 initial values (all rows sum to zero; columns hit net lending / FNW / NW; RES = FNW − FNWM; FNWM = FA − FL; economy-wide FNW = 0).

Gate result: PASS, with two honest caveats

  1. Tolerance is the manual's own precision, not 1e-6 relative. Table 6 prints 4 significant figures, so identities can only be verified up to accumulated rounding. Each test's tolerance is 2 × Σ 0.5·ulp₄(entry) over the entries involved (typically 0.01–3 £bn depending on stock sizes). Observed residuals are well inside that (e.g. largest balance-sheet column residual 1.3 vs tolerance 5.2).
  2. One inconsistency in the manual itself, pinned rather than hidden: Table 6's LENDM_ROW (10.96) omits the DIVN_ROW term of §3.4.6 Eq. (383) — the manual tabulates overall LENDM as 5.44 where it says it "should equal 0 by definition". Because DISC_MFI is defined as minus the sum of the other discrepancies (Eq. (211)), the MFI and RoW transaction columns miss national-accounts net lending by ∓DIVN_ROW exactly. The tests assert that gap equals DIVN_ROW so any drift fails loudly.

Also documented: Table 6's equation cross-references use a numbering that does not match the equation numbers printed in the §3 body (e.g. Table 6 cites RP_NFC as "Eq. (101)", the body prints Eq. (165)); all manual_ref citations here use the body numbering.

Not in scope (later milestones)

No behavioural equations, no solver wiring of these matrices, no oracle comparison — milestone 1 is the static accounting gate only.

Tests

76 passed, 1 skipped (the skip is the pre-existing oracle test; all previously green tests remain green).

🤖 Generated with Claude Code

Clean-room transcription (manual only, per REIMPLEMENTATION.md):
- model/calibration.py: §5 Table 5 (parameters) and Table 6 (initial
  values) transcribed in full, with the symbol-normalization rules and
  the manual's own quirks documented.
- model/accounting.py: §2.2 Table 1 transactions matrix and Table 2
  balance-sheet matrix as machine-readable linear cells with per-row
  manual references; transactions_residuals/balance_sheet_residuals.
- tests/test_accounting.py: milestone 1 gate — every row/column identity
  on the §5 initial values within the manual's 4-sig-fig printing
  precision; the manual's own DIVN_ROW/LENDM_ROW inconsistency (overall
  LENDM tabulated as 5.44 where 'should equal 0') pinned exactly.
- REIMPLEMENTATION.md milestone table + VALIDATION.md run record updated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vahid-ahmadi
vahid-ahmadi merged commit 4b3150e into main Aug 4, 2026
1 check 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