"""fed-funds-vs-cpi-real-rates-deflators.py - the effective fed funds rate minus inflation measured four ways: headline CPI, core CPI, the PCE price index and core PCE, monthly from 1960, by decade. Input : datasets/fed-funds-vs-cpi-real-rates-deflators.csv, the FRED series FEDFUNDS (percent), CPIAUCSL and CPILFESL (BLS, index 1982-84=100, seasonally adjusted), PCEPI and PCEPILFE (BEA, index 2017=100, seasonally adjusted), retrieved 2026-11-27 through the public fredgraph CSV (kit/fedfunds_deflators.py saved the raw files). All five series pages carry "Public Domain: Citation Requested". Method: inflation = 100 * (P_t / P_{t-12} - 1) on a complete monthly calendar (a month with no value leaves a gap, never a shifted comparison); real rate = FEDFUNDS - inflation, in percentage points (ex post, realised inflation). The comparison sample is every month in which all four real rates exist, January 1960 to the latest common month. A month is "below zero" when the real rate is strictly negative. Run : python code/fed-funds-vs-cpi-real-rates-deflators.py Needs : Python 3.13, standard library only. """ import csv import statistics from collections import defaultdict CSV = "datasets/fed-funds-vs-cpi-real-rates-deflators.csv" DEFLATORS = {"CPI": "CPIAUCSL", "core CPI": "CPILFESL", "PCE": "PCEPI", "core PCE": "PCEPILFE"} def num(x): return float(x) if x not in ("", ".") else None def load(): with open(CSV, encoding="utf-8", newline="") as f: rows = list(csv.DictReader(f)) months = [r["date"][:7] for r in rows] data = {k: [num(r[k]) for r in rows] for k in rows[0] if k != "date"} return months, data def yoy(levels): return [None if i < 12 or levels[i] is None or levels[i - 12] is None else 100 * (levels[i] / levels[i - 12] - 1) for i in range(len(levels))] def runs_below(months, vals): out, start = [], None for i, v in enumerate(vals + [None]): if v is not None and v < 0: start = i if start is None else start elif start is not None: out.append((months[start], months[i - 1], i - start)) start = None return out def main(): months, data = load() ff = data["FEDFUNDS"] infl = {k: yoy(data[s]) for k, s in DEFLATORS.items()} real = {k: [None if f is None or p is None else f - p for f, p in zip(ff, infl[k])] for k in DEFLATORS} common = [i for i, m in enumerate(months) if m >= "1960-01" and all(real[k][i] is not None for k in DEFLATORS)] first, last = months[common[0]], months[common[-1]] missing = [months[i] for i in range(common[0], common[-1] + 1) if i not in set(common)] print(f"common sample {first} to {last}: {len(common)} months; months missing inside it: {missing}") by_dec = defaultdict(list) for i in common: by_dec[int(months[i][:4]) // 10 * 10].append(i) head = " | ".join(f"mean, {k}" for k in DEFLATORS) + " | " + " | ".join(f"below zero, {k}" for k in DEFLATORS) print(f"\n| decade | months | {head} | signs disagree |") print("|---|---" + "|---" * (2 * len(DEFLATORS) + 1) + "|") tot_dis = 0 for dec, ix in sorted(by_dec.items()): means = [statistics.fmean(real[k][i] for i in ix) for k in DEFLATORS] below = [sum(real[k][i] < 0 for i in ix) for k in DEFLATORS] dis = sum(1 for i in ix if len({real[k][i] < 0 for k in DEFLATORS}) > 1) tot_dis += dis print(f"| {dec}s | {len(ix)} | " + " | ".join(f"{m:.2f}" for m in means) + " | " + " | ".join(str(b) for b in below) + f" | {dis} |") means = [statistics.fmean(real[k][i] for i in common) for k in DEFLATORS] below = [sum(real[k][i] < 0 for i in common) for k in DEFLATORS] print(f"| all | {len(common)} | " + " | ".join(f"{m:.2f}" for m in means) + " | " + " | ".join(str(b) for b in below) + f" | {tot_dis} |") print("share below zero: " + ", ".join(f"{k} {100 * b / len(common):.1f}%" for k, b in zip(DEFLATORS, below))) gap = [infl["CPI"][i] - infl["PCE"][i] for i in common] print(f"\nheadline CPI minus PCE inflation: mean {statistics.fmean(gap):.2f} pp, median {statistics.median(gap):.2f}, " f"CPI higher in {sum(g > 0 for g in gap)} of {len(gap)} months") gapc = [infl["core CPI"][i] - infl["core PCE"][i] for i in common] print(f"core CPI minus core PCE inflation: mean {statistics.fmean(gapc):.2f} pp, " f"core CPI higher in {sum(g > 0 for g in gapc)} of {len(gapc)} months") hc = sum(1 for i in common if (real["CPI"][i] < 0) != (real["core PCE"][i] < 0)) hc_cpi_neg = sum(1 for i in common if real["CPI"][i] < 0 <= real["core PCE"][i]) print(f"headline CPI and core PCE disagree on the sign in {hc} months; CPI negative while core PCE is not: {hc_cpi_neg}") print("\nlongest stretch below zero, by deflator (common sample):") for k in DEFLATORS: vals = [real[k][i] if i in set(common) else None for i in range(len(months))] r = sorted(runs_below(months, vals), key=lambda x: (-x[2], x[0]))[0] print(f" {k}: {r[0]} to {r[1]}, {r[2]} months") print("\nlatest months:") for i in range(len(months) - 3, len(months)): parts = [f"FEDFUNDS {ff[i]:.2f}"] + [ f"{k} infl {infl[k][i]:.2f} real {real[k][i]:.2f}" if real[k][i] is not None else f"{k} n/a" for k in DEFLATORS] print(f" {months[i]}: " + "; ".join(parts)) for k in DEFLATORS: lastpos = max(i for i in range(len(months)) if real[k][i] is not None) turned = next(months[i] for i in range(len(months)) if months[i] >= "2022-04" and real[k][i] is not None and real[k][i] > 0) low = min((i for i in range(len(months)) if months[i] >= "2020-01" and real[k][i] is not None), key=lambda i: real[k][i]) print(f" {k}: 2020s low {real[k][low]:.2f} in {months[low]}; first positive month after it {turned}; " f"latest {months[lastpos]} real {real[k][lastpos]:.2f}") if __name__ == "__main__": main()