# Stocks and flows

> Cash, debt, ARR and retained earnings are stocks rolled forward by flows. How a balance works in Layerz and how to break a circular reference.

Finance has two kinds of numbers. A **flow** happens over a period: revenue, a salary, a loan repayment. A **stock** is a level at a point in time: the cash in the bank, the debt outstanding, the ARR, the headcount. Stocks move only through flows:

```
Closing(t) = Opening(t) + Flows in (t) - Flows out (t)
Opening(t) = Closing(t-1)
```

## The balance role

A `balance` is a stock rolled forward. It holds an `opening_balance` and takes its movements from the flows attached under it as callups:

1. create the balance (`Cash`, opening 1,200,000);
2. compute each flow as its own line, signed (`Operating cash flow`, `Capex` negative, `Equity raised`);
3. attach each flow under the balance as a `callup`.

The balance then rolls by itself, period after period, at the finest grain of the model. A balance with no flow attached stays flat at its opening forever, which is almost always a modelling mistake.

## Breaking circularity with lags

A flow often depends on the stock it feeds: interest on debt, churn on ARR, a cash yield. Reading the stock of the same period would be a circular reference. Read the previous period instead, with a lag suffix:

```
Interest = Debt_M-1 * Rate / 12
Churned ARR = ARR_M-1 * Churn rate
```

`_M-1`, `_Q-1` and `_Y-1` read one month, one quarter or one year back. At the first period, a lag reads the balance's opening value. A line may also read its own past: `Counter = Counter_M-1 + 1`.

## How stocks fold over time

A yearly view of a stock shows its closing value, never the sum of twelve months. Layerz infers this: a balance, and any formula that copies, lags, adds or subtracts stocks, folds as a `stock`. A stock times a rate (headcount times salary, debt times rate) is a flow and sums. See [Model and time](/docs/concepts/model-and-time).

## Balances per element

A balance can carry a list: one roll-forward per element (a debt tranche, a product's ARR, a cohort). Every list-typed flow under it must share the same list. See [Lists](/docs/concepts/lists).
