--- title: Vieillissement et bruitage de la base pour calcul keywords: fastai sidebar: home_sidebar nb_path: "notebooks/retraitement_erfs-fpr/modules/inflate_and_noise.ipynb" ---
{% raw %}
{% endraw %}

Imports

{% raw %}
import unittest

# Imports hors librairie
import pandas as pd
from matplotlib import pyplot as plt

from leximpact_prepare_data.toolbase import *

tc = unittest.TestCase()
{% endraw %} {% raw %}
{% endraw %} {% raw %}
erfs_05_ind = pd.read_hdf(
    config.get("DATA_OUT") + "03_erfs_rfr_ind" + config.get("YEAR_ERFS") + ".h5"
)
# config.get("DATA_OUT") + "05_erfs_calibrated_ff" + config.get("YEAR_ERFS") + "_to_" + config.get("YEAR_POTE") + ".h5")
erfs_05_ff = individus_to_foyers_fiscaux(erfs_05_ind)
erfs_05_ff.columns
{% endraw %}

Choix des paramètres de vieillissement

{% raw %}
year_start = int(config.get("YEAR_POTE"))

# Année de fin : année de production de la base pour calculs sur l'API
year_end = int(config.get("YEAR_COMPUTATION"))
year_end
{% endraw %}

1 - Données et agrégats (à updater lors du PLF/PLFSS)

1.1 - Salaires

{% raw %}
{% endraw %} {% raw %}
# On plot l'inflation des salaires pour voir si comment estimer les années inconnues
X = total_annuel_salaires.keys()
Y = total_annuel_salaires.values()
plt.figure(figsize=(16, 4))
plt.plot(X, Y, marker="o")
plt.xlabel("Années")
plt.ylabel("Traitements et salaires")
plt.title("Evolution du montant total des salaires")
plt.show()
{% endraw %}

[DEV] projection_salaires

{% raw %}

projection_salaires[source]

projection_salaires(yearf)

{% endraw %} {% raw %}
{% endraw %} {% raw %}
total_annuel_salaires_proj = projection_salaires(2025)

# Salaires
# On plot l'inflation des salaires pour voir si comment estimer les années inconnues
X = total_annuel_salaires_proj.keys()
Y = total_annuel_salaires_proj.values()
plt.figure(figsize=(16, 4))
plt.plot(X, Y, marker="o", color="red")
plt.xlabel("Années")
plt.ylabel("Traitements et salaires")
plt.title("Projection de l'évolution du montant total des salaires")
plt.show()
{% endraw %}

Courbe de l'inflation salariale

{% raw %}
annees_connues = list(total_annuel_salaires_proj.keys())
annees_connues.remove(annees_connues[0])  # On supprime l'année 1
inflation_sal_proj = {}
for year in annees_connues:
    inflation_sal_proj[year] = (
        total_annuel_salaires_proj[year]
        / total_annuel_salaires_proj[str(int(year) - 1)]
    )
# On plot l'inflation des salaires pour voir si comment estimer les années inconnues
X = inflation_sal_proj.keys()
Y = inflation_sal_proj.values()

plt.figure(figsize=(16, 4))
plt.plot(X, Y, marker="o")
plt.xlabel("Années")
plt.ylabel("Inflation salariale")
plt.title("Evolution de l'inflation salariale")
plt.show()
{% endraw %}

1.2 - Indice des prix à la consommation

{% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}
X1 = [int(i) for i in inflation_idc.keys()]
Y1 = inflation_idc.values()

X2 = [int(i) for i in inflation_insee.keys()]
Y2 = inflation_insee.values()

plt.figure(figsize=(16, 4))
plt.plot(X1, Y1, marker="o")
plt.plot(X2, Y2, marker="+")
plt.xlabel("Années")
plt.ylabel("Inflation des prix à la consommation")
plt.title("Evolution de l'inflation économique")
plt.legend(["IDC, hors tabac (Gouv)", "IDC, avec tabac (INSEE)"])
plt.show()
{% endraw %}

1.3 - Revalorisation des retraites

{% raw %}
{% endraw %} {% raw %}
X = revalorisation_retraite.keys()
Y = revalorisation_retraite.values()
plt.figure(figsize=(16, 4))
plt.plot(X, Y, marker="o")
plt.xlabel("Années")
plt.ylabel("Revalorisation des retraites")
plt.title("Évolution de la revalorisation des retraites")
plt.show()
{% endraw %}

1.4 - Revalorisation des indemnisations de chômage

{% raw %}
{% endraw %} {% raw %}
X = reval_chomage.keys()
Y = reval_chomage.values()
plt.figure(figsize=(16, 4))
plt.plot(X, Y, marker="o")
plt.xlabel("Années")
plt.ylabel("Revalorisation du chômage")
plt.title("Revalorisation du chômage")
plt.show()
{% endraw %}

1.5 - Calcul de l'inflation

[DEV] inflation_economique

{% raw %}

inflation_economique[source]

inflation_economique(inputfile, to_inflate, startp, endp)

On distingue différents types d'inflation:

- l'inflation observée des salaires
- l'inflation économique, dite inflation de l'indice des prix à la consommation (IDC)
- l'inflation des retraites, liée à l'augmentation des points de retraite
{% endraw %} {% raw %}
{% endraw %}

Agrégats

{% raw %}
to_inflate = ["salaire_de_base", "retraite_brute", "chomage_brut", "f4ba"]
erfs_inflated_ff = inflation_economique(erfs_05_ff, to_inflate, year_start, year_end)
erfs_inflated_ff.head()

print(
    "Total du salaire de base avant inflation : ", erfs_05_ff["salaire_de_base"].sum()
)
print(
    "Total du salaire de base après inflation : ",
    erfs_inflated_ff["salaire_de_base"].sum(),
)
print(
    "Soit une différence de : ",
    100
    * (erfs_inflated_ff["salaire_de_base"].sum() - erfs_05_ff["salaire_de_base"].sum())
    / erfs_05_ff["salaire_de_base"].sum(),
    "%",
)
{% endraw %}

2 - Calibration du nombre de foyers fiscaux

Données

{% raw %}
{% endraw %}

[DEV] projection_foyers

{% raw %}

projection_foyers[source]

projection_foyers(yearf)

{% endraw %} {% raw %}
{% endraw %}

Plot du nombre de foyers fiscaux

{% raw %}
nb_foyers_proj = projection_foyers(2025)
nb_foyers_proj
# Plot
X = nb_foyers_proj.keys()
Y = nb_foyers_proj.values()
plt.figure(figsize=(16, 4))
plt.plot(X, Y, marker="o")
plt.xlabel("Années")
plt.ylabel("Nb de foyers fiscaux")
plt.title("Evolution du nombre de foyers fiscaux")
plt.show()
{% endraw %}

[DEV] calib_initiale_ff - Calibration initiale du nombre de foyers fiscaux

{% raw %}

calib_initiale_ff[source]

calib_initiale_ff(erfs_ind, year_init)

{% endraw %} {% raw %}
{% endraw %}

[DEV] inflation_foyers

{% raw %}

inflation_foyers[source]

inflation_foyers(erfs_ind, year_start, year_end)

{% endraw %} {% raw %}
{% endraw %} {% raw %}
erfs_inflated_ff, erfs_ind = inflation_foyers(erfs_inflated_ff, year_start, year_end)

print(
    "Nombre de foyers fiscaux après inflation de ",
    year_start,
    " à ",
    year_end,
    " : ",
    erfs_inflated_ff["wprm"].sum(),
)

erfs_inflated_ff.head()
{% endraw %}

3 - Bruitage

[DEV] bruitage

{% raw %}

bruitage[source]

bruitage(erfs)

{% endraw %} {% raw %}
{% endraw %} {% raw %}
erfs_06_ff = bruitage(erfs_inflated_ff)
{% endraw %}

Export de la base de calcul

{% raw %}
outfile_path = (
    config.get("DATA_OUT")
    + "06_erfs_ff_"
    + config.get("YEAR_ERFS")
    + "_aged_"
    + config.get("YEAR_COMPUTATION")
    + "_dev.h5"
)
erfs_06_ff.to_hdf(outfile_path, key="input", mode="w")
{% endraw %}

4 - TESTS

Base pour test

{% raw %}
erfs_t = None
erfs_t = pd.DataFrame(
    [
        [1, 1, 0],
        [2, 1, 0],
        [3, 1, 0],
        [4, 1, 46],
        [5, 1, 99],
        [6, 1, 90],
        [7, 1, 250],
        [8, 1, 300],
        [9, 1, 1000],
        [10, 1, 21_000],
        [11, 1, 12_000],
        [12, 1, 100],
        [13, 1, 199],
        [14, 1, 180],
        [15, 1, 185],
        [16, 1, 198],
        [17, 1, 187],
        [18, 1, 26_000],
        [19, 1, 49_000],
    ],
    columns=["idfoy", "wprm", "rfr"],
)

erfs_t["loyer"] = 0.2 * erfs_t["rfr"]
erfs_t["chomage_brut"] = 0.6 * erfs_t["rfr"]
erfs_t["retraite_brute"] = 0.4 * erfs_t["rfr"]
erfs_t.columns
{% endraw %}

Test inflation economique

{% raw %}
erfs_t_eco = inflation_economique(
    erfs_t, ["rfr", "chomage_brut", "retraite_brute", "loyer"], 2018, 2018
)
tc.assertAlmostEqual(erfs_t_eco["rfr"].sum(), erfs_t["rfr"].sum())
tc.assertAlmostEqual(erfs_t_eco["loyer"].sum(), erfs_t["loyer"].sum())
tc.assertAlmostEqual(erfs_t_eco["retraite_brute"].sum(), erfs_t["retraite_brute"].sum())
tc.assertAlmostEqual(erfs_t_eco["chomage_brut"].sum(), erfs_t["chomage_brut"].sum())
{% endraw %}

Cas 1 : On change d'un an

{% raw %}
erfs_t_eco2 = inflation_economique(
    erfs_t, ["rfr", "chomage_brut", "retraite_brute", "loyer"], 2018, 2019
)
tc.assertAlmostEqual(erfs_t_eco2["rfr"].sum(), 1.0344118339117296 * erfs_t["rfr"].sum())
tc.assertAlmostEqual(erfs_t_eco2["loyer"].sum(), 1.016 * erfs_t["loyer"].sum())
tc.assertAlmostEqual(
    erfs_t_eco2["chomage_brut"].sum(), 1.007 * erfs_t["chomage_brut"].sum()
)
tc.assertAlmostEqual(
    erfs_t_eco2["retraite_brute"].sum(), 1.0 * erfs_t["retraite_brute"].sum()
)
{% endraw %}

Test infla FF

{% raw %}
print("Somme avant: ", erfs_t["wprm"].sum())
# Sans changer d'annee
erfs_t_ff, _ = inflation_foyers(erfs_t, 2018, 2018)
tc.assertAlmostEqual(erfs_t_ff["wprm"].sum(), 38_549_926)

# Décalage d'un an
erfs_t_ff2, _ = inflation_foyers(erfs_t, 2018, 2019)
tc.assertAlmostEqual(erfs_t_ff2["wprm"].sum(), 39_331_689)

# Projection
erfs_t_ff3, _ = inflation_foyers(erfs_t, 2019, 2023)
tc.assertGreater(erfs_t_ff3["wprm"].sum(), erfs_t["wprm"].sum())
{% endraw %}