spb/traite-evaluation-qc
Public
1#!/usr/bin/env python32"""Ch. 30, figure « flux » : RNE, CAPEX et flux net avant dette (barres) du cas 3 (DONNÉES SYNTHÉTIQUES), puis valeur3actuelle cumulée des flux et apport de la valeur terminale. Sortie : assets/figures/ch30/ch30-fig-flux.pdf."""4from __future__ import annotations5import sys, pathlib6sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))7import numpy as np, matplotlib.pyplot as plt8from matplotlib.ticker import FuncFormatter9from traite.style import setup, palette, savefig, LARGEUR, fmt_milliers10from cases import ch30_dcf as c1112def main():13 setup()14 r = c.base(); t = c.tableau_dcf(r); h = r["hyp"]; T = h["horizon_ans"]; d = r["dcf"]15 tt = t[t["annee"] <= T]16 fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(LARGEUR, 4.6), sharex=True, gridspec_kw={"height_ratios": [1.15, 1], "hspace": 0.12})17 x = tt["annee"].values; w = 0.2718 ax1.bar(x - w, tt["rne"] / 1000, w, color=palette.cat[0], label="RNE")19 ax1.bar(x, -tt["capex"] / 1000, w, color=palette.cat[1], label="CAPEX (sortie)")20 ax1.bar(x + w, tt["flux_avant_dette"] / 1000, w, color=palette.cat[2], label="Flux net avant dette")21 ax1.axhline(0, color=palette.ink2, lw=0.8)22 ax1.set_ylabel("Milliers de dollars")23 ax1.legend(loc="upper left", ncol=3)24 # bas : VA cumulée25 ax2.plot(x, tt["va_cumulee"] / 1000, marker="o", color=palette.cat[0], label="VA cumulée des flux")26 ax2.vlines(T, tt["va_cumulee"].iloc[-1] / 1000, d["valeur"] / 1000, color=palette.cat[3], lw=3, label="VA de la valeur terminale")27 ax2.scatter([T], [d["valeur"] / 1000], color=palette.cat[3], zorder=5)28 ax2.axhline(d["valeur"] / 1000, color=palette.ink2, lw=0.8, ls="--")29 ax2.annotate(f"$V_0$ = {fmt_milliers(d['valeur'])} \\$", xy=(1.2, d["valeur"] / 1000), va="bottom", fontsize=8, color=palette.ink)30 ax2.annotate(f"flux : {fmt_milliers(d['va_flux'])} \\$ ({d['va_flux']/d['valeur']*100:.0f} %)", xy=(5.3, 640), ha="left", va="bottom", fontsize=8)31 ax2.annotate(f"VT : {fmt_milliers(d['va_terminale'])} \\$ ({d['part_terminale']*100:.0f} %)", xy=(T - 0.1, (tt["va_cumulee"].iloc[-1] + d["valeur"]) / 2000), ha="right", va="center", fontsize=8)32 ax2.set_ylabel("Milliers de dollars"); ax2.set_xlabel("Année de projection")33 ax2.set_xticks(x); ax2.set_ylim(0, d["valeur"] / 1000 * 1.12)34 ax2.legend(loc="center left")35 for ax in (ax1, ax2): ax.yaxis.set_major_formatter(FuncFormatter(lambda v, p: fmt_milliers(v)))36 savefig(fig, "ch30/ch30-fig-flux.pdf")3738if __name__ == "__main__":39 main()40