# Revenue forecast from its drivers

How well does a monthly revenue forecast built from its drivers (trips, the share of shared rides, miles per trip, fare
per mile, charges per trip) hold up against a forecast of revenue directly, and which driver caused each month's miss?
This study answers that on real public data: the City of Chicago's ride-hail trip records, read as monthly totals
through the city's open data portal.

- Revenue is fares plus additional charges (what riders paid before tips), summed over every operator. The driver
  identity closes to the cent in every month.
- Three forecasts at every monthly origin, one to three months ahead: each driver forecast and multiplied back, revenue
  forecast directly with the same model family (additive exponential smoothing with a seasonal pattern), and a naive
  baseline (last year's same month times recent growth).
- Errors are scored by regime (the recovery and the settled years, never pooled), with block-bootstrap intervals and
  paired differences between methods.
- A plan-versus-actual bridge splits every month's miss into trips, shared-ride mix, trip length, fare per mile and
  charges per trip. The pieces sum exactly; that is bookkeeping, not evidence.
- A declared sweep of the fit window.

The page is `index.html`; every number on it comes from `results/results.json` or `results/figures.json`.

A second part, `active-drivers.html`, asks the same question one step further back: does a plan built from active
drivers (new drivers each month, how earlier cohorts stay active, and trips per active driver) forecast trips and
revenue as well as the trip-driver forecast? It reads the City of Chicago's ride-hail drivers data as counts by month
and start month, with every listed or active count from 1 to 9 merged away (three merged age rows show 0 in
`data/drivers-cohorts.csv`; see [Data sources](DATA_SOURCES.md)). Its design was declared before scoring
([DESIGN-drivers.md](DESIGN-drivers.md)); every number on that page comes from `results/drivers-results.json` or
`results/drivers-figures.json`.

A third part, `sales-capacity.html`, plans backwards from a target on explicitly synthetic data: does a sales headcount
plan built as target divided by quota produce enough pipeline and closed new ARR, how often is the target met, and which
planning assumptions decide it? Every input is a labelled assumption in `protocol-capacity.json`, declared with
[DESIGN-capacity.md](DESIGN-capacity.md) before any planning or simulation code existed; every number on that page comes
from `results/capacity-results.json`, `results/capacity-figures.json` or the protocol. The method carries; the numbers
do not.

A fourth part, `patient-flow.html`, puts a channel between demand and recorded sales, again on explicitly synthetic
data: for a made-up specialty therapy, does a patient-flow forecast (identified, diagnosed, referred, started,
persisting) reconcile through channel stock and a supply limit with a trend of shipments, and where do the two disagree
first? Every input is a labelled assumption in `protocol-patientflow.json`, declared with
[DESIGN-patientflow.md](DESIGN-patientflow.md) before any forecasting code existed; every number on that page comes from
`results/patientflow-results.json`, `results/patientflow-figures.json` or the protocol.

A fifth part, `consumer-kpi-tree.html`, builds a KPI tree from sign-ups to revenue and margin on explicitly synthetic
data, a made-up home-workout app: one written definition per KPI, every link labelled identity, predictive association
or causal effect, early indicators tested out of sample on rolling origins, and what one point of activation is worth
against one point of monthly retention and how long each takes to show. Every input is a labelled assumption in
`protocol-kpitree.json`, declared with [DESIGN-kpitree.md](DESIGN-kpitree.md) before any lever or fit was run. A second
world comes from an independent author who never saw the method or the first world. Its file,
`revfc/kpitree_heldout_world.py`, is not in the public download, so that part cannot be re-run from the download alone.

The first results are in `results/kpitree-results.json` and the declared run, on all 60 worlds and 6 sweep seeds, in
`results/kpitree-full-results.json`. A follow-up, declared after the first results and before its runs in
[DESIGN-kpitree-v2.md](DESIGN-kpitree-v2.md) and [DESIGN-kpitree-v2a.md](DESIGN-kpitree-v2a.md), adds a lasting point of
retention, each lever in both worlds, and bootstrap intervals and clustered clocks in
`results/kpitree-v2-results.json`. A forecast-path follow-up, declared after those results and before any of it was computed in
[DESIGN-kpitree-v3.md](DESIGN-kpitree-v3.md), runs no lever: it puts both estimates on a forecast path made only from months before
the change, scales the clocks to a 10% holdout, re-reads the noise band without the months after the price rise, and adds readings off
the same runs, in `results/kpitree-v3-results.json` and `results/kpitree-v3-worlds.csv`. A measured-lift follow-up, declared after the
forecast path's results and before any of it was computed in [DESIGN-kpitree-v4.md](DESIGN-kpitree-v4.md), prices the retention change the way
the page advises, the arithmetic's value of a point times the lift the first world's half holdout measured, and scores it beside the
scaled test, in `results/kpitree-v4-results.json` and `results/kpitree-v4-worlds.csv`; it repeats the holdout runs only to read their
tables, and its scoring can be recomputed from that per-world file alone. Every number on the page comes from those files,
`results/kpitree-figures.json` or the protocols.

## Reproduce

Needs Python 3.12 and [uv](https://docs.astral.sh/uv/). The portal responses are in `data/raw/`, so nothing is
downloaded.

```
uv sync
uv run python -I revfc/clean.py        # data/raw -> data/monthly.csv, one row per month with no gaps or repeats
uv run python -I revfc/backtest.py     # results/results.json and results/forecasts.csv
uv run python -I revfc/figures.py      # results/figures.json (units and counts for the page)
uv run python -I revfc/report.py       # index.html and results/page-numbers.json
uv run python -I tools/check_numbers.py
uv run python -I revfc/drivers_backtest.py      # second part: results/drivers-results.json and drivers-forecasts.csv
uv run python -I revfc/drivers_figures.py       # results/drivers-figures.json
uv run python -I revfc/drivers_report.py        # active-drivers.html and results/drivers-page-numbers.json
uv run python -I tools/check_drivers_numbers.py
uv run python -I revfc/capacity.py              # third part (synthetic): results/capacity-results.json and capacity-years.csv
uv run python -I revfc/capacity_figures.py      # results/capacity-figures.json
uv run python -I revfc/capacity_report.py       # sales-capacity.html and results/capacity-page-numbers.json
uv run python -I tools/check_capacity_numbers.py
uv run python -I revfc/patientflow.py           # fourth part (synthetic): results/patientflow-results.json, -months.csv, -worlds.csv
uv run python -I revfc/patientflow_figures.py   # results/patientflow-figures.json
uv run python -I revfc/patientflow_report.py    # patient-flow.html and results/patientflow-page-numbers.json
uv run python -I tools/check_patientflow_numbers.py
uv run python -I revfc/kpitree.py run <empty folder> --worlds 60 --sweep-seeds 6 # fifth part (synthetic); the held-out part needs a file the download leaves out
uv run python -I revfc/kpitree.py aggregate <that folder> --worlds 60 --stem kpitree-full # results/kpitree-full-results.json, -worlds.csv
uv run python -I revfc/kpitree_v2.py run <that folder>         # the follow-up declared after the first results
uv run python -I revfc/kpitree_v2.py aggregate <that folder>   # results/kpitree-v2-results.json, -worlds.csv, -lift.csv
uv run python -I revfc/kpitree_v3.py run <that folder>         # the forecast-path follow-up's base tables
uv run python -I revfc/kpitree_v3.py aggregate <that folder>   # results/kpitree-v3-results.json, -worlds.csv
uv run python -I revfc/kpitree_v4.py run <that folder>         # the measured-lift follow-up's holdout tables
uv run python -I revfc/kpitree_v4.py aggregate <that folder>   # results/kpitree-v4-results.json, -worlds.csv
uv run python -I revfc/kpitree_figures.py      # results/kpitree-figures.json
uv run python -I revfc/kpitree_report.py       # consumer-kpi-tree.html and results/kpitree-page-numbers.json
uv run python -I tools/check_kpitree_numbers.py
uv run python -I -m pytest -q
```

The backtest is deterministic; a re-run reproduces `results/results.json` byte for byte, and a test checks it.
To fetch the aggregates again from the portal (network), into a fresh empty folder:

```
uv run python -I revfc/fetch.py <empty folder> 2018-11 2026-08 --workers 4
```

The drivers counts come from the portal the same way, into a folder outside the study (the raw responses hold small
cells), and are then cleaned into the committed tables:

```
uv run python -I revfc/fetch_drivers.py <empty folder outside the study> 2018-11 2026-08
uv run python -I revfc/clean_drivers.py <that folder>
```

## Files

- `revfc/fetch.py`, `revfc/clean.py`: portal queries and the monthly table.
- `revfc/model.py`: drivers, the identity, the models and the bridge.
- `revfc/backtest.py`: rolling-origin backtest, scores, intervals, bridge and sweep.
- `revfc/figures.py`, `revfc/report.py`: the page and its claims map.
- `revfc/fetch_drivers.py`, `revfc/clean_drivers.py`: the drivers counts and the committed cohort tables.
- `revfc/drivers_backtest.py`, `revfc/drivers_figures.py`, `revfc/drivers_report.py`: the second part.
- `revfc/capacity.py`, `revfc/capacity_figures.py`, `revfc/capacity_report.py`: the third part (synthetic sales plan).
- `revfc/patientflow.py`, `revfc/patientflow_figures.py`, `revfc/patientflow_report.py`: the fourth part (synthetic
  patient flow, channel stock and supply).
- `revfc/kpitree_world.py`, `revfc/kpitree_planner.py`, `revfc/kpitree.py`, `revfc/kpitree_figures.py`,
  `revfc/kpitree_report.py`: the fifth part (the synthetic app, what a planner can compute, the runs, the page).
- `revfc/kpitree_v2_world.py`, `revfc/kpitree_v2_planner.py`, `revfc/kpitree_v2.py`: the fifth part's follow-up declared after the first results: instruments added to the frozen worlds in memory, the bootstrap and clustered estimators, the runs.
- `revfc/kpitree_v3.py`: the fifth part's forecast-path follow-up: the forecast path, the 10% holdout by scaling, the band's re-reading and the readings off the same runs.
- `revfc/kpitree_v4.py`: the fifth part's measured-lift follow-up: the retention change priced with the lift a holdout measured, beside the scaled test.
- `revfc/kpitree_heldout_world.py`: the second world of the fifth part, as its author wrote it. Not in the public download.
- `tests/`: identity, bridge, known answers, data fingerprints, small cells and the frozen results of every part.
- [Data sources](DATA_SOURCES.md), [notice](NOTICE.txt).

Some files are packed in marketplace-revenue-forecast-data-1.zip; unzip it here to restore the full export, which the manifest lists file by file.
