calibration.py

All source files · Download calibration.py

"""Reproducible demographic accounting for the Chapter 19 income scenario.

The ABS primary-income balance is a scenario scale, not a measurement of
VoTa's future cash tax base. See the source metadata and chapter assumptions.
This module does not generate documents or figures.
"""

import csv
import json
from dataclasses import dataclass
from pathlib import Path

DATA = Path(__file__).with_name("data")


def ubi_weight(age, f_start=0.5, a_ramp=13, a_adult=18):
    if age < 0:
        raise ValueError("Age cannot be negative")
    if age < a_ramp:
        return f_start
    if age < a_adult:
        return f_start + (1 - f_start) * (age - a_ramp) / (a_adult - a_ramp)
    return 1.0


@dataclass(frozen=True)
class Calibration:
    population: int
    total_weight: float
    aggregate_income: float
    ubi_rate: float = 0.30
    svc_rate: float = 0.22
    consumption_fraction: float = 1.0

    def __post_init__(self):
        if self.population <= 0 or self.total_weight <= 0 or self.aggregate_income < 0:
            raise ValueError("Invalid population, weights or income")
        if not 0 <= self.ubi_rate + self.svc_rate < 1:
            raise ValueError("Combined tax rate must be below one")
        if self.ubi_rate < 0 or self.svc_rate < 0 or not 0 <= self.consumption_fraction <= 1:
            raise ValueError("Invalid rates or consumption fraction")

    @property
    def mean_income(self):
        return self.aggregate_income / self.population

    @property
    def income_per_weight(self):
        return self.aggregate_income / self.total_weight

    @property
    def total_consumption(self):
        q = self.consumption_fraction
        return q * self.aggregate_income / (1 - q * self.ubi_rate)

    @property
    def ubi_pool(self):
        return self.ubi_rate * self.total_consumption

    @property
    def adult_ubi(self):
        return self.ubi_pool / self.total_weight

    @property
    def disposable_adult_ubi(self):
        return (1 - self.ubi_rate - self.svc_rate) * self.adult_ubi

    @property
    def services_pool(self):
        return self.svc_rate * self.total_consumption


def load_population():
    with (DATA / "australia-age-population-2025.csv").open() as stream:
        return {int(row["age"]): int(row["persons"]) for row in csv.DictReader(stream)}


def australian_calibration(consumption_fraction=1.0):
    data = json.loads((DATA / "australia-calibration-2025.json").read_text())
    population = load_population()
    return Calibration(
        population=sum(population.values()),
        total_weight=sum(n * ubi_weight(a) for a, n in population.items()),
        aggregate_income=data["primary_income_receivable_aud"] - data["primary_income_payable_aud"],
        consumption_fraction=consumption_fraction,
    )


if __name__ == "__main__":
    c = australian_calibration()
    for name in ("population", "total_weight", "aggregate_income", "mean_income",
                 "income_per_weight", "adult_ubi", "disposable_adult_ubi",
                 "ubi_pool", "services_pool"):
        print(f"{name}: {getattr(c, name):,.2f}")