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