Shipmind Labs

Name the movement line, and the roll-forward proves itself

· 8 min read

A closing balance computed as opening plus movement is reconciled by construction, and that is another way of saying it is not reconciled at all. One subtraction produced both sides, so they cannot disagree. The failures that matter sit next door. A movement line defined independently of the balance it is supposed to explain, and a year rolled up from quarters where opening, movement and closing each aggregate under a different rule.

We build financial models as data rather than spreadsheets, and the arithmetic of a single period has never been the hard part. The trouble is that the same model gets read at three granularities at once. A month is computed. A quarter and a year are aggregated. The reader treats all three as the same statement, and expects every one of them to show opening plus movement equal to closing. Computing twelve months correctly does nothing to make that true of the quarter.

In finmodel we made the identity something the model declares instead of something the author hopes for. A Carry names three lines: an opening balance, a closing balance, and (optionally) the movement between them. Naming the movement is what turns a roll-forward into a test that every period in the timeline has to pass.

Three numbers, three aggregation rules#

The carry chain runs over months only. Inside PeriodicModel.run, the first month takes its opening from the opening mapping you hand in, with Decimal(0) as the default, and every later month takes previous[carry.closing]. That chain is a straight line, and it is easy to trust.

Quarters and the year are not computed that way at all. They get rolled from the months, line by line, according to each line's Rollup. Declaring a carry fixes two of those rollups: the opening claims Rollup.FIRST, and a closing that is an input line claims Rollup.LAST. Everything else keeps the default, Rollup.SUM.

python
model.rollup_of("opening_cash")  # Rollup.FIRST
model.rollup_of("receipts")      # Rollup.SUM

So the yearly identity reads like this: January's opening, plus twelve movements summed, equals December's closing. Three different reductions over three different lines, tied together by nothing except an assertion. If a rollup is wrong, if a movement line is a balance in disguise, if a line is rounded at a scale that does not survive summation, then every month can be individually correct while the year is not. That is the case the proof exists for, and it is why we do not accept "the closing formula already adds the movement" as a reconciliation.

Declaring the carry#

The statement itself is ordinary. Input lines for what is supplied, computed lines for what is derived.

python
from decimal import Decimal

from finmodel import (
    Carry,
    ComputedLine,
    InputLine,
    PeriodicModel,
    Rounding,
    Statement,
)

cash = Statement(
    id="cash_flow",
    label="Cash flow",
    rounding=Rounding(2),
    children=[
        InputLine(id="opening_cash", label="Opening cash"),
        InputLine(id="receipts", label="Receipts"),
        InputLine(id="payments", label="Payments"),
        ComputedLine(
            id="net_cash_flow",
            label="Net cash flow",
            formula="receipts - payments",
        ),
        ComputedLine(
            id="closing_cash",
            label="Closing cash",
            formula="opening_cash + net_cash_flow",
        ),
    ],
)

model = PeriodicModel(
    cash,
    carries=[
        Carry(
            opening="opening_cash",
            closing="closing_cash",
            movement="net_cash_flow",
        )
    ],
)

That third argument is what the whole thing rests on. Without movement, you have a chain of balances. With it, the model has stated which line claims to explain the difference, and that claim becomes checkable.

__post_init__ does the checking it can do before any number exists, and refuses the carries that cannot mean anything:

The model says What construction answers
opening and closing are the same line balance 'cash' cannot open and close the same period
one line appears in two carries balance 'closing_cash' is carried twice
the opening is a computed line opening balance 'opening_cash' must be an input line
the movement names nothing unknown line 'net_cash'
a stated rollup fights the carry rolls up as 'first'

All of these are SpecError. The movement id resolves through statement.line, so a typo in a movement name fails at construction time rather than leaving a proof that quietly never runs.

What run will not be told#

An opening balance that is carried does not also get supplied. If a month's values contain carry.opening, run refuses rather than letting the given number win over the chain:

text
opening balance 'opening_cash' is carried between periods, not given for 2026-03

The mirror case, an opening handed in for a line that carries nothing, gets refused the same way, with the offending ids listed:

text
opening balances given for lines that carry none: receipts

Both are the same rule from two directions. There is exactly one source for an opening balance, and the model decides which.

The proof#

Once the months are evaluated and the quarters and the year are rolled, _prove builds one Proof per carry that states a movement, for every entry of timeline.periods. So each month, each quarter and the year get one, not a single annual sanity check.

Proof.ok is False when any of opening, movement or closing is NotApplicable, and otherwise it requires opening + movement == closing exactly, with no tolerance, over the amounts as the statement rounded them. The proof reads the numbers you see, not the fuller-precision intermediates behind them.

python
results = model.run(timeline, values, opening={"opening_cash": Decimal("1000.00")})

str(results.proofs("2026")[0])
# "closing_cash over 2026: 1000.00 + 7320.00 = 8320.00 (holds)"

Results.proofs(period) returns the proofs of one period, and with no argument it returns every proof in the timeline, in period order. That is what we attach to a review when a model changes: not an assurance that the roll-forward is fine, but the list of identities that were actually tested and the three numbers each of them tested.

A failed period raises; it does not render#

When an identity breaks, nothing comes back. IdentityError, a SpecError subclass carrying the failing proof, is raised before Results is constructed.

python
with pytest.raises(IdentityError) as error:
    model.run(timeline, values)

error.value.proof.period.id  # "2026-01"
error.value.proof.ok         # False

That is deliberate. A model whose January does not reconcile still produces a table that looks like a financial statement, and a table that looks right gets read as right. Handing back the first period that failed, with its opening, movement and closing attached, costs the caller one traceback and saves whoever reads the output from hunting the drift by eye across thirteen columns.

What it costs to run#

Strictness, and we have not found a way to buy it cheaper.

Rounding drift is a failure. A proof carries no tolerance. If a statement rounds its lines to two places and a movement line comes through a division, the sum of twelve rounded movements can miss the rounded closing by a cent, and the year will refuse. The remedy is to fix the model, rounding at the right place or stating the movement as a line that is itself rounded consistently, instead of widening a threshold. Drift we have consciously decided to accept belongs in a Check, which carries an explicit non-negative tolerance and exists precisely for two sides that may legitimately disagree a little. A carry identity does not qualify, since it is arithmetic.

A balance with no stated movement is proved by nothing. A Carry whose movement is None gets skipped by _prove entirely. It still chains the opening from the previous closing, it still claims the right rollups, and it still reports zero proofs. The absence of a proof is silent, which makes it a review item rather than an error. When a model declares a carry without a movement, we expect the author to say why the difference is not expressible as a line.

The opening must be an input line. You cannot carry into a computed row, so an opening balance has to be modelled explicitly even in a statement where it feels like a derived value. That is one more line in the spec and one more thing to label, in exchange for a balance whose source is a single declared edge instead of a formula someone has to read.

The trade we are making is narrow, and we think it is clear enough once stated: a roll-forward costs nothing and tells you nothing, while a named movement costs one field per balance and turns every period in the timeline into a test that either holds or stops the run with its three numbers in hand.

Was this useful?

Building something similar?

or email hello@shipmindlabs.com