Milestone 1: accounting core (§2.2 matrices + §5 calibration) — clean-room from the manual - #3
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_PShave 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 amanual_refto the §3 equations it rests on.transactions_residuals(state)andbalance_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
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).LENDM_ROW(10.96) omits theDIVN_ROWterm of §3.4.6 Eq. (383) — the manual tabulates overallLENDMas 5.44 where it says it "should equal 0 by definition". BecauseDISC_MFIis defined as minus the sum of the other discrepancies (Eq. (211)), the MFI and RoW transaction columns miss national-accounts net lending by ∓DIVN_ROWexactly. The tests assert that gap equalsDIVN_ROWso 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_refcitations 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