SPB Git
2.4 KB · 39 lines python
1#!/usr/bin/env python32"""Ch. 34, figure « rotation espérée » : (gauche) rapport espéré loyer contractuel / loyer de marché d'un logement partant de3q0 = 0,695 (logement 103 du cas 3, DONNÉES SYNTHÉTIQUES) pour une rotation de 5, 15 et 25 %, forme fermée (trait) et simulation4Monte-Carlo (points), avec la limite q_∞ ; (droite) probabilité que le locataire initial soit encore en place après t années.5Sortie : ch34-fig-rotation-esperee.pdf."""6from __future__ import annotations7import sys, pathlib8sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))9import numpy as np10import matplotlib.pyplot as plt11from matplotlib.ticker import FuncFormatter12from traite.style import setup, palette, savefig, LARGEUR13from cases import ch34_tal as c1415def main():16    setup()17    q0, gc, gm, T = 0.695, 0.031, 0.035, 1518    t = np.arange(0, T + 1)19    fig, (a1, a2) = plt.subplots(1, 2, figsize=(LARGEUR, 3.0), gridspec_kw={"width_ratios": [1.6, 1]})20    for rho, col in ((0.05, palette.cat[2]), (0.15, palette.cat[0]), (0.25, palette.cat[1])):21        q = c.ratio_espere(q0, rho, gc, gm, t); sim = c.simulation_ratio(q0, rho, gc, gm, T, n=20_000)22        qi = c.ratio_limite(rho, gc, gm)23        a1.plot(t, q, color=col, label=f"rotation {rho*100:.0f} % : forme fermée (q∞ = {qi:.3f})".replace(".", ","))24        a1.plot(t, sim, color=col, ls="none", marker="o", ms=3, mfc="white", mew=1.0)25        a1.axhline(qi, color=col, lw=0.7, ls=":")26    a1.plot(t, c.ratio_sans_relocation(q0, gc, gm, t), color=palette.ink2, ls="--", lw=1.0, label="sans relocation (indexation seule)")27    a1.plot([], [], color=palette.ink2, ls="none", marker="o", ms=3, mfc="white", label="simulation (20 000 trajectoires)")28    a1.set_xlabel("Années depuis l'évaluation"); a1.set_ylabel("Loyer contractuel / loyer de marché (espérance)")29    a1.set_ylim(0.45, 1.02); a1.set_xlim(0, T + 0.5); a1.legend(fontsize=7, loc="lower left")30    for rho, col in ((0.05, palette.cat[2]), (0.15, palette.cat[0]), (0.25, palette.cat[1])):31        a2.plot(t, (1 - rho) ** t, color=col, label=f"rotation {rho*100:.0f} %")32    a2.set_xlabel("Années depuis l'évaluation"); a2.set_ylabel("Locataire initial encore en place")33    a2.yaxis.set_major_formatter(FuncFormatter(lambda v, q: f"{v*100:.0f} %")); a2.set_ylim(0, 1.0); a2.legend(fontsize=7)34    fig.subplots_adjust(wspace=0.32)35    savefig(fig, "ch34/ch34-fig-rotation-esperee.pdf")3637if __name__ == "__main__":38    main()39
Files · 2eb2bf4e67f754808bae5090a9e53eab37149ddb
Menu

Theme