"""bls-cpi-twelve-months-reconciled.py - the five CPI series from bls-cpi-components-python-no-key.py, month by month, 12-month change from the seasonally adjusted index against the change from the unadjusted index the BLS release quotes. Inputs : datasets/bls-cpi-twelve-months-reconciled.csv (FRED copies of the BLS indexes, SA and NSA, retrieved 2026-11-06 from fred.stlouisfed.org/graph/fredgraph.csv) datasets/bls-cpi-components-python-no-key.csv (the BLS API v1 file the article's script saved 2026-09-05) datasets/llm-time-series-forecasting-claims-vintages-CPIAUCSL.csv (every ALFRED vintage of CPIAUCSL since 2010, retrieved 2026-10-30; one column per vintage) Rules : 12-month change = index / index twelve calendar months earlier - 1, in percent, from the published three-decimal levels, rounded half up to one decimal as the release prints it. A missing month (October 2025, lapse in appropriations) leaves its own change and the change twelve months later blank. Window: November 2025 (the first month after the gap) to the last month in the file. Annual revision: for each year, the last vintage dated in January against the last vintage dated in February (the January CPI release carries the recalculated seasonal factors). Output : Markdown tables and the counts quoted in the article. Run : python code/bls-cpi-twelve-months-reconciled.py Needs : Python 3.13 standard library only. Makes no network request. """ import csv from decimal import ROUND_HALF_UP, Decimal FILE = "datasets/bls-cpi-twelve-months-reconciled.csv" BLS_FILE = "datasets/bls-cpi-components-python-no-key.csv" VINTAGES = "datasets/llm-time-series-forecasting-claims-vintages-CPIAUCSL.csv" START = "2025-11" ONE = Decimal("0.1") def back12(m): return f"{int(m[:4]) - 1}{m[4:]}" def change(levels, m): a, b = levels.get(m), levels.get(back12(m)) if not a or not b: return None return (Decimal(a) / Decimal(b) - 1) * 100 def r1(x): return None if x is None else x.quantize(ONE, ROUND_HALF_UP) def fmt(x): return "-" if x is None else f"{x:.1f}" rows = list(csv.DictReader(open(FILE, encoding="utf-8"))) comps = list(dict.fromkeys(r["component"] for r in rows)) sa = {c: {r["month"]: r["sa_index"] for r in rows if r["component"] == c} for c in comps} nsa = {c: {r["month"]: r["nsa_index"] for r in rows if r["component"] == c} for c in comps} bls_id = {r["component"]: r["bls_sa_id"] for r in rows} months = sorted(m for m in sa[comps[0]] if m >= START) last = months[-1] # 1. the two changes, side by side print(f"## 12-month change, seasonally adjusted / not adjusted, {START} to {last}\n") print("| month | " + " | ".join(comps) + " |") print("|---|" + "---|" * len(comps)) differ, cells, gaps = {c: [] for c in comps}, 0, {c: [] for c in comps} for m in months: out = [] for c in comps: a, b = r1(change(sa[c], m)), r1(change(nsa[c], m)) if a is None or b is None: out.append("no data") continue cells += 1 gaps[c].append(abs(change(sa[c], m) - change(nsa[c], m))) mark = "" if a != b: differ[c].append(m) mark = " *" out.append(f"{fmt(a)} / {fmt(b)}{mark}") print(f"| {m} | " + " | ".join(out) + " |") n = sum(len(v) for v in differ.values()) print(f"\n{n} of {cells} component-months differ at one decimal (* above).") for c in comps: big = max(gaps[c]) print(f"- {c}: {len(differ[c])} of {len(gaps[c])} differ ({', '.join(differ[c]) or 'none'}); " f"largest unrounded gap {big:.3f} pp") blank = [m for m in sorted(sa[comps[0]]) if not sa[comps[0]][m]] print(f"Missing index months in the file: {', '.join(blank)}; first month whose 12-month change will be blank for " f"the same reason: {int(blank[0][:4]) + 1}{blank[0][4:]}.") # 2. the release's method for July 2026 (the month whose release text the article quotes) print("\n## July 2026, computed the release's way (not seasonally adjusted)\n") for c in comps: print(f"- {c}: NSA {fmt(r1(change(nsa[c], '2026-07')))}, SA {fmt(r1(change(sa[c], '2026-07')))}") # 3. the FRED copy against the BLS API file saved 2026-09-05 bls = {} for r in csv.DictReader(open(BLS_FILE, encoding="utf-8")): bls.setdefault(r["series_id"], {})[r["date"][:7]] = r["value"] same = total = 0 for c in comps: b = bls[bls_id[c]] for m, v in b.items(): if m not in sa[c]: continue total += 1 fv = sa[c][m] if (v in ("", "nan") and not fv) or (v not in ("", "nan") and fv and Decimal(v) == Decimal(fv)): same += 1 span = sorted(m for m in bls[bls_id[comps[0]]] if m in sa[comps[0]]) print(f"\n## FRED (2026-11-06) against the BLS API file (2026-09-05)\n\n{same} of {total} component-months identical " f"({span[0]} to {span[-1]}, October 2025 blank in both).") # 4. what each February does to the seasonally adjusted history (all items) vr = list(csv.reader(open(VINTAGES, encoding="utf-8"))) names = [h.split("_")[1] for h in vr[0][1:]] col = {m[:7]: r[1:] for r in vr[1:] for m in [r[0]]} def lv(j): return {m: (v[j] if v[j] not in ("", ".") else None) for m, v in col.items()} print("\n## The February revision of CPIAUCSL, 2010 to 2026\n") print("| year | before (vintage) | after (vintage) | months rewritten | first | last | prior-year 12-month changes moved at one decimal | largest unrounded move (pp) |") print("|---|---|---|---|---|---|---|---|") moved_all = checked_all = 0 for y in range(2010, 2027): jan = [j for j, d in enumerate(names) if d[:4] == str(y) and d[4:6] == "01"] feb = [j for j, d in enumerate(names) if d[:4] == str(y) and d[4:6] == "02"] if not jan or not feb: continue A, B = lv(jan[-1]), lv(feb[-1]) rew = sorted(m for m in A if A[m] and B.get(m) and A[m] != B[m]) prior = [f"{y - 1}-{i:02d}" for i in range(1, 13)] pairs = [(change(A, m), change(B, m)) for m in prior] pairs = [(p, q) for p, q in pairs if p is not None and q is not None] moved = sum(1 for p, q in pairs if r1(p) != r1(q)) big = max(abs(q - p) for p, q in pairs) moved_all += moved checked_all += len(pairs) print(f"| {y} | {names[jan[-1]]} | {names[feb[-1]]} | {len(rew)} | {rew[0]} | {rew[-1]} | {moved} of {len(pairs)} | {big:.3f} |") print(f"\nAcross the {2026 - 2010 + 1} revisions: {moved_all} of {checked_all} prior-year 12-month changes moved at one decimal.") # 5. one month followed through every vintage: June 2022, the peak 12-month change in the article's ten-year file print("\n## June 2022 (seasonally adjusted all items), every vintage where the 12-month change moved\n") prev = None for j, d in enumerate(names): x = change(lv(j), "2022-06") if x is not None and x.quantize(Decimal("0.001")) != prev: prev = x.quantize(Decimal("0.001")) print(f"- vintage {d}: {prev} -> {fmt(r1(x))}") print(f"- unadjusted, today's file: {fmt(r1(change(nsa['all items'], '2022-06')))}")