"""How the Treasury derived the curve, and when it changed how. The par yield curve is not a measurement, it is the output of a procedure, and the procedure changed on 6 December 2021: the monotone convex method replaced the quasi-cubic hermite spline. The Treasury says so on its methodology page and publishes a comparison of what the two produce. That matters because a rate from 2015 and a rate from 2022 are not the same kind of number, and neither is recomputed under the other's method. The published values stand as published; `methodology_id` on every curve row says which procedure produced it, and this registry says what each one was. """ from __future__ import annotations from datetime import date from pathlib import Path import polars as pl METHODOLOGY_URL = ( "https://home.treasury.gov/policy-issues/financing-the-government/interest-rate-statistics/" "treasury-yield-curve-methodology" ) SCHEMA = { "methodology_id": pl.String, "effective_from": pl.Date, "effective_to": pl.Date, "name": pl.String, "description": pl.String, "source_url": pl.String, } # `effective_to` is the last day produced under that method. The Treasury's # wording is "replaced ... as of December 6, 2021", so 6 December is the first # monotone convex curve and 3 December, the trading day before it, the last # spline one. METHODOLOGIES = [ { "methodology_id": "quasi_cubic_hermite_spline", "effective_from": date(1990, 1, 2), "effective_to": date(2021, 12, 3), "name": "Quasi-cubic hermite spline", "description": ( "The par yield curve was derived with a quasi-cubic hermite spline fitted to " "indicative bid-side quotations for the most recently auctioned securities, " "obtained by the Federal Reserve Bank of New York at or near 3:30 PM Eastern. " "The Treasury has archived the full description of this method. Its start date " "here is the first day of the published daily series, not the date the method " "was adopted, which the Treasury does not state." ), "source_url": METHODOLOGY_URL, }, { "methodology_id": "monotone_convex", "effective_from": date(2021, 12, 6), "effective_to": None, "name": "Monotone convex", "description": ( "Inputs are indicative, bid-side market price quotations -- not transactions -- " "for the most recently auctioned securities, obtained by the Federal Reserve " "Bank of New York at or near 3:30 PM Eastern. The prices are converted to yields " "and used to bootstrap the instantaneous forward curve by a monotone convex " "method. The Treasury states that this replaced the quasi-cubic hermite spline " "as of December 6, 2021." ), "source_url": METHODOLOGY_URL, }, ] def registry() -> pl.DataFrame: return pl.DataFrame(METHODOLOGIES, schema=SCHEMA).sort("effective_from") def methodology_for(day: date) -> str | None: """Which procedure produced the curve published for this day.""" for entry in METHODOLOGIES: if day < entry["effective_from"]: continue if entry["effective_to"] is None or day <= entry["effective_to"]: return entry["methodology_id"] return None def write_registry(metadata_dir: Path) -> int: metadata_dir.mkdir(parents=True, exist_ok=True) table = registry() table.write_parquet(metadata_dir / "yield_curve_methodology.parquet", compression="zstd") return table.height __all__ = [ "METHODOLOGIES", "METHODOLOGY_URL", "SCHEMA", "methodology_for", "registry", "write_registry", ]