SPB Git
2.7 KB · 42 lines python
1#!/usr/bin/env python32"""Ch. 34, figure « valeur par scénario » : valeur DCF du cas 3 (DONNÉES SYNTHÉTIQUES) pour la grille rotation (5, 15, 25 %) ×3pourcentage de base (2 ; 3,1 ; 4 %), avec repères : valeur de base (2 208 566 $), capitalisation directe (2 037 503 $), indexation4seule et encadrement renforcé. Sortie : ch34-fig-valeur-scenarios.pdf."""5from __future__ import annotations6import sys, pathlib7sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))8import numpy as np9import matplotlib.pyplot as plt10from matplotlib.ticker import FuncFormatter11from traite import cas312from traite.style import setup, palette, savefig, LARGEUR, fmt_milliers13from cases import ch34_tal as c1415def main():16    setup()17    d = cas3.tout()18    g = c.grille_scenarios(d); s = c.scenarios_complementaires(d).set_index("scenario")19    rotations = sorted(g["rotation"].unique()); bases = sorted(g["base"].unique())20    fig, ax = plt.subplots(figsize=(LARGEUR, 3.7))21    w = 0.26; xs = np.arange(len(rotations))22    for j, b in enumerate(bases):23        vals = [g[(g["rotation"] == r) & (g["base"] == b)]["valeur"].iloc[0] / 1e6 for r in rotations]24        bars = ax.bar(xs + (j - 1) * w, vals, w, color=palette.cat[j], label=f"pourcentage de base {b*100:.1f} %".replace(".", ","))25        for bar, v in zip(bars, vals):26            ax.text(bar.get_x() + bar.get_width() / 2, v + 0.012, f"{v:.3f}".replace(".", ","), ha="center", va="bottom", fontsize=7, color=palette.ink)27    V0 = d["dcf"]["valeur"] / 1e6; Vcap = d["valeur_capitalisation"] / 1e628    v_idx = s.loc["Indexation seule (aucune relocation)", "valeur"] / 1e629    v_ren = s.loc["Encadrement renforcé (base 2 %, rotation 8 %, φ = 0,5, marché 3 %)", "valeur"] / 1e630    ax.axhline(V0, color=palette.ink2, lw=0.9, ls="--", label=f"valeur de base du dossier ({fmt_milliers(V0*1e6)} $)")31    ax.axhline(Vcap, color=palette.ink2, lw=0.9, ls=":", label=f"capitalisation directe au taux médian ({fmt_milliers(Vcap*1e6)} $)")32    ax.axhline(v_idx, color=palette.cat[3], lw=0.9, ls="-.", label=f"indexation seule, sans relocation ({fmt_milliers(v_idx*1e6)} $)")33    ax.axhline(v_ren, color=palette.cat[3], lw=0.9, ls="-", label=f"encadrement renforcé ({fmt_milliers(v_ren*1e6)} $)")34    ax.set_xticks(xs); ax.set_xticklabels([f"rotation {r*100:.0f} %\n({int(round(r*12))} logement{'s' if round(r*12) > 1 else ''}/an)" for r in rotations])35    ax.set_ylabel("Valeur DCF (millions de $)"); ax.set_ylim(1.6, 2.85)36    ax.yaxis.set_major_formatter(FuncFormatter(lambda v, q: f"{v:.1f}".replace(".", ",")))37    ax.legend(loc="upper left", fontsize=7, ncol=2)38    savefig(fig, "ch34/ch34-fig-valeur-scenarios.pdf")3940if __name__ == "__main__":41    main()42
Files · da8a4ee0304be0aa9c54ed0aad08d985fc4539fc
Menu

Theme