SPB Git
2.6 KB · 31 lines python
1#!/usr/bin/env python32"""Figure ch04 — taux d'intérêt 2000-2026 : taux hypothécaire conventionnel 5 ans affiché (V80691335, hebdomadaire, 2000→), rendement de3l'obligation du Canada 5 ans (BD.CDN.5YR.DQ.YLD, quotidien, 2000→) et cible du taux du financement à un jour (V39079, disponible à partir4d'avril 2009 dans l'extraction Valet). DONNÉES RÉELLES : Banque du Canada, API Valet (data/raw/bdc_valet). Sortie : assets/figures/ch04/ch04-fig-taux-2000-2026.pdf"""5import sys, pathlib6ROOT = pathlib.Path(__file__).resolve().parents[3]7sys.path.insert(0, str(ROOT / "analysis/python")); sys.path.insert(0, str(ROOT / "analysis/python/cases"))8import pandas as pd, matplotlib.pyplot as plt, matplotlib.dates as mdates9from traite.style import setup, palette, savefig, LARGEUR10import ch04_marches as cas1112def main():13    setup()14    b = cas.bdc()["series"]15    fig, ax = plt.subplots(figsize=(LARGEUR, 3.9))16    ax.plot(b["hyp5"].index, b["hyp5"].values, color=palette.cat[0], lw=1.6, label="Taux hypothécaire affiché, 5 ans (conventionnel)")17    obl = b["obl5"].resample("W").mean()18    ax.plot(obl.index, obl.values, color=palette.cat[1], lw=1.2, label="Obligation du Canada, 5 ans (moyenne hebdomadaire)")19    ax.step(b["directeur"].index, b["directeur"].values, color=palette.cat[2], lw=1.4, where="post", label="Taux directeur (cible du financement à un jour, dès 2009)")20    for t, lab, y in [("2008-09-15", "crise\nfinancière", 9.3), ("2020-03-11", "pandémie", 9.3), ("2022-03-02", "resserrement\n2022-2023", 9.3)]:21        ax.axvline(pd.Timestamp(t), color=palette.ink2, lw=0.6, ls=":"); ax.text(pd.Timestamp(t) + pd.Timedelta(days=40), y, lab, fontsize=7, color=palette.ink2, va="top")22    ax.set_ylabel("Taux (% annuel)"); ax.set_ylim(0, 9.6); ax.set_xlim(pd.Timestamp("2000-01-01"), pd.Timestamp("2027-01-01"))23    ax.xaxis.set_major_locator(mdates.YearLocator(2)); ax.xaxis.set_major_formatter(mdates.DateFormatter("%Y"))24    ax.legend(loc="upper center", bbox_to_anchor=(0.5, -0.1), ncol=1, fontsize=7.5)25    ax.annotate(f"{b['hyp5'].iloc[-1]:.2f} %".replace(".", ","), xy=(b["hyp5"].index[-1], b["hyp5"].iloc[-1]), xytext=(-40, 10), textcoords="offset points", fontsize=7.5, arrowprops=dict(arrowstyle="-", color=palette.ink2, lw=0.6))26    ax.annotate(f"{b['directeur'].iloc[-1]:.2f} %".replace(".", ","), xy=(b["directeur"].index[-1], b["directeur"].iloc[-1]), xytext=(-40, -14), textcoords="offset points", fontsize=7.5, arrowprops=dict(arrowstyle="-", color=palette.ink2, lw=0.6))27    out = savefig(fig, "ch04/ch04-fig-taux-2000-2026.pdf"); print("OK", out)2829if __name__ == "__main__":30    main()31
Files · 8dfc6ca7769188d087f58c82e02a063bfba99ae6
Menu

Theme