# -*- coding: utf-8 -*-
# ---
# jupyter:
#   jupytext:
#     cell_metadata_filter: title,-all
#     formats: ipynb,py:percent
#     text_representation:
#       extension: .py
#       format_name: percent
#       format_version: '1.3'
#       jupytext_version: 1.14.5
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# %%
"""
Created on Sun Jan  3 10:50:02 2021

@author: Mateo
"""

from HARK.Calibration.Income.IncomeTools import (
    parse_income_spec,
    find_profile,
    Cagetti_income,
    CGM_income,
)

import numpy as np
import matplotlib.pyplot as plt

# What year to use as the base monetary year?
# (pick 1992 as it is used by both of the papers we are comparing)
adjust_infl_to = 1992

# %% Cocco, Gomes, Maenhout (2005) calibration
age_min = 21
age_max = 100

ages = np.arange(age_min, age_max + 1)

plt.figure()
for spec in CGM_income.items():
    label = spec[0]

    params = parse_income_spec(
        age_min=age_min, age_max=age_max, adjust_infl_to=adjust_infl_to, **spec[1]
    )
    MeanY = find_profile(params["PermGroFac"], params["P0"])

    plt.plot(ages, MeanY, label=label)

plt.title(
    "Mean paths of permanent income calibrations in\n"
    + "Cocco, Gomes & Maenhout (2005)"
)
plt.xlabel("Age")
plt.ylabel(
    "Mean Permanent Income,\n" + "Thousands of {} U.S. dollars".format(adjust_infl_to)
)
plt.legend()
plt.show()

# %% Cagetti (2003) calibration

age_min = 25
age_max = 91
# Cagetti has a year trend in his specification, so we have to say on what
# year agents enter the model.
start_year = 1980

ages = np.arange(age_min, age_max + 1)

plt.figure()
for spec in Cagetti_income.items():
    label = spec[0]

    params = parse_income_spec(
        age_min=age_min,
        age_max=age_max,
        adjust_infl_to=adjust_infl_to,
        start_year=start_year,
        **spec[1]
    )
    MeanY = find_profile(params["PermGroFac"], params["P0"])

    plt.plot(ages, MeanY, label=label)

plt.title("Mean paths of permanent income calibrations in\n" + "Cagetti (2003)")
plt.xlabel("Age")
plt.ylabel(
    "Mean Permanent Income,\n" + "Thousands of {} U.S. dollars".format(adjust_infl_to)
)
plt.legend()
plt.show()
