# Metric definitions

These are the bank's five governed metrics. Each has an id. Every metric is in integer minor units of one
currency, for one scope: one account, or one organization's accounts in one currency.

## MD-01 Gross card spend

MD-01 Gross card spend is the sum of amount_minor over posted purchase events whose posted_at falls in the
period, for the accounts in scope. Pending and void purchases are not included. It equals the sum of
purchased_minor over the card_spend_daily rows of those accounts whose spend_date falls in the period.

## MD-02 Refunded amount

MD-02 Refunded amount is the sum of amount_minor over posted refund events whose posted_at falls in the period,
for the accounts in scope, whatever the date of the original purchase. It equals the sum of refunded_minor over
the card_spend_daily rows of those accounts whose spend_date falls in the period.

## MD-03 Net card spend

MD-03 Net card spend is gross card spend (MD-01) minus refunded amount (MD-02) for the same scope and period. It
equals the sum of net_spend_minor over the card_spend_daily rows of those accounts whose spend_date falls in the
period. It can be negative in a period with more refunds than purchases.

## MD-04 Net external cash flow

MD-04 Net external cash flow is the sum of posted credits minus the sum of posted debits, excluding transfers, whose
posted_at falls in the period, for the accounts in scope. It includes purchases, refunds, deposits and withdrawals.
It is not deposits minus withdrawals. Internal transfers between accounts are excluded on both legs.

## MD-05 Closing ledger balance

MD-05 Closing ledger balance is a stock for one date: the account's opening_balance_minor plus every posted signed
movement through the end of that UTC date. It is the closing_minor of the account's account_daily row for that
date. For an organization in one currency it is the sum over its accounts on that single date. It is never summed
across dates, and pending or void events never change it.

## Periods and row identifiers

A period is half-open: the start date at 00:00 UTC is included and the end date at 00:00 UTC is excluded, so July
2026 is 2026-07-01 to 2026-08-01. Every row of account_daily has a row_id that starts with bal_, and every row of
card_spend_daily has a row_id that starts with spd_. Transactions, accounts, cards and categories are identified by
their own ids.
