! parameters.f90 -- model parameters and experiment flags.
! The flags at the top select the policy configuration and sensitivity
! experiment; see the README for the mapping to the paper's tables.

MODULE PARAMETERS

IMPLICIT NONE

INTEGER, PARAMETER  ::  DP          = SELECTED_REAL_KIND(P=13)

! CONTROLS
INTEGER :: tranguess = 1    ! 1: use transition guess (1)
INTEGER :: itersave = 1     ! 1: Save results after each iteration | 0: sets to 0 on server automatically
INTEGER :: policy = 1       ! 1: run COVID-19 mitigation policy (initial response)
INTEGER :: policy2 = 1      ! 1: second round (CAA and ARPA)
INTEGER :: lockdown = 1     ! 1: lockdown
INTEGER :: taxtype = 0      ! 1: tauc only (baseline)  | 2: taus only | 3: Pigouvian  | 4: tax only
                            ! 0: no taxes (calibration)

INTEGER :: readvguess = 1   ! 1: use steady state value function guess
INTEGER :: readcalguess = 0 ! 0: baseline   | 1: calibration guess (1)
INTEGER :: calibed = 1      ! 1: already calibrated (baseline) | 0: to calibrate
INTEGER :: ubarcal = 0      ! 0: baseline   | 1: Calibrate ubar if unknown
INTEGER :: tvbetaecal = 0   ! 0: baseline   | 1: calibrate time-varying beta
INTEGER :: welfguess = 1    ! 1: use welfare guess (1)
INTEGER :: sswrite = 0      ! 0: baseline   | 1: update vss/vhati (during/following calibration)

! SENSITIVITY
INTEGER :: vsltype = 1      ! 1: low vsl (baseline) | 2: high vsl (sensitivity) 
INTEGER :: highgam = 0      ! 0: 0.51 (baseline)    | 1: 0.61 (sensitivity)
INTEGER :: capcon = 1       ! 1: hospital capacity constraint (baseline)    | 0: turn off (sensitivity)
INTEGER :: highrepnum = 0   ! 0: R0 = 2.2 (baseline)    | 1: R0 = 2.5 (sensitivity)
INTEGER :: transmission = 0 ! 0: Endogenous (baseline)  | 1: Exogenous 
INTEGER :: bequestmode = 1  ! 1: to 15 percent of newborns (baseline) | 2: dead household replaced by new one
INTEGER :: highsubsidy = 0  ! 0: 0.3-1.3 (baseline) | 2: 1.35-2.35

REAL(DP)    ::                  &
    hoscap      = 0.010_dp,     &   ! hospital capicity constraint (baseline: 0.010_dp)
    inf_init    = 0.0050_dp,    &   ! initial infected (baseline: 0.0050_dp)
	sick_eta_loss	= 0.5_dp,  	&   ! efficiency loss for infected (baseline: 0.5_dp | sensitivity: 0.3_dp)
	sick_util_loss	= 0.0_dp,  	&   ! utility loss for infected (fraction of average flow value of life, baseline: 0.0_dp)
    non_util_loss   = 0.050_dp, &   ! utility loss for nonwork (fraction of average flow value of life, baseline = 0.05_dp)
    sswfhfractot = 0.000_dp,    &   ! fraction of total labor WFH pre-pandemic (0.144_dp)
    sswfhfrac   = 0.0_dp            ! fraction of WFH-available time spent working from home pre-pandemic (0.432648379855651_dp)

! OTHER CONTROLS
INTEGER :: unuloss = 1      ! 1: Utility loss if nonwork (baseline)
INTEGER :: highpers = 1     ! 1: highly persistent income process (baseline)
INTEGER :: wfh = 2          ! 2: only susceptible and infected WFH (baseline) | 1: Work from home | 
INTEGER :: tvbetae = 1      ! 1: time-varying beta (baseline) | 0: constant beta_e

INTEGER, PARAMETER :: N_cfh = 20 ! 1: No consumption from home | > 1 number of grid points if CFH possible (5)

! SENSITIVITY
REAL(DP), PARAMETER :: yrs_cov = 2.0_dp ! baseline: 2 | sensitivity: 1
INTEGER :: tvac = 20        ! 20: December 18-31, 2021


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!! BASELINE CALIBRATION !!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  
REAL(DP) ::                             &
    beta_ann    = 0.9737061431_dp,      &!discount factor
    phi         = 20.5473416617_dp,     &!disutility of labor
    sick_phi	= 20.5473416617_dp,     &!disutility of labor for infected (22.639_dp)
    ss          = 1.0172854976_dp,      &
    tau         = 0.0749485246_dp,      &
    initk       = 2306.298413845_dp,    &
    gam         = 0.51_dp,              &!inside consumption share (baseline: 0.51_dp)
	sick_gam	= 0.51_dp,              &!inside consumption share for infected (baseline: 0.51_dp)
    rhat1       = 0.0029568523_dp,      &
    rhat2       = 0.002957_dp,          &
    rhat        = 0.0028910796_dp

! EPIDEMIOLOGY MODULE
REAL(DP) , PARAMETER    ::      &
    days        = 14.0_dp,      &   ! number of days in a period
    expdur      = 18.0_dp           ! average illness duration (days)
REAL(DP) ::                     &
    repnum      = 2.2_dp            ! basic reproduction number

REAL(DP), PARAMETER :: pix = MIN(1.0_dp,days/expdur)

INTEGER, PARAMETER ::                      &
    jmin        = 1,            &   ! beginning of life (25)
    jret        = 3,            &   ! period of mandatory retirement (65)
	jmax        = 3                 ! last age of life (65+)

! MITIGATION POLICIES
REAL(DP)    ::                  &
    tauc_init   = 0.0000000_dp, &   ! tax on consumption (baseline: 0.2487381_dp) (wfh:0.171169315_dp) (0.1852904_dp) (0.12766462_dp)
    taus_init   = 0.0000000_dp, &   ! tax on earnings (0.4934031_dp) (0.12766462_dp) 
    sui_cbar    = 0.70_dp,      &   ! transfer if labor less than hcut (units of consumption per capita) (0.25_dp)
    hcut        = 0.00_dp,      &   ! threshold for hours to qualify for supplemental income (0.20_dp)
    hloc        = 0.132_dp,     &   ! outside hours cap (0.20_dp)
	suidur 		= 120.0_dp,     &   ! duration of full mitigation (before gradual phase-out)
    sui_curv    = 3.0_dp,       &   ! speed at which policy winds down (baseline: 2.0_dp)
	locdur 		= 042.0_dp,     &   ! duration of lockdown (before gradual phase-out)
    loc_curv    = 2.0_dp            ! speed at which lockdown winds down (baseline: 2.0_dp)
	! 600/($44271*7/365) = 0.7
    ! 10 hrs/ week ==> 10/112 = 0.0893
    ! 15 hrs/ week ==> 15/112 = 0.1339

REAL(DP), DIMENSION(jmax), PARAMETER    :: &
    deathrate   = (/ 0.0008_dp, 0.0085_dp,  0.0847_dp   /), & ! unconstrained case fatality rate
    vaccrate    = (/ 0.0500_dp, 0.1000_dp,  0.1000_dp   /)  ! vaccine probability

REAL(DP), DIMENSION(jmax)   :: &
    capdr       =    2.0_dp*deathrate   ! capicity-constrained case fatality rate

INTEGER, PARAMETER  ::          &
    N_death    = 26                 ! periods of US death data starting from March 27-April 9

REAL(DP), DIMENSION(N_death) :: & 
    deaths_data =           &
        (/ 0.0000904_dp,    &
		0.0001428_dp,       &
		0.0001207_dp,       &
		0.0000892_dp,       &
		0.0000606_dp,       &
		0.0000442_dp,       &
		0.0000356_dp,       &
		0.0000459_dp,       &
		0.0000637_dp,       &
		0.0000656_dp,       &
		0.0000624_dp,       &
		0.0000508_dp,       &
		0.0000510_dp,       &
		0.0000463_dp,       &
		0.0000496_dp,       &
		0.0000592_dp,       &
		0.0000808_dp,       &
		0.0001155_dp,       &
		0.0001659_dp,       &
		0.0001675_dp,       &
		0.0001991_dp,       &
		0.0002060_dp,       &
		0.0001864_dp,       &
		0.0001327_dp,       &
		0.0001018_dp,       &
		0.0000678_dp/)

  !  deaths_data = (/ 0.0000765_dp,  &
		!0.0001311_dp,  &
		!0.0001185_dp,  &
		!0.0000866_dp,  &
		!0.0000600_dp,  &
		!0.0000447_dp,  &
		!0.0000351_dp,  &
		!0.0000408_dp,  &
		!0.0000627_dp,  &
		!0.0000682_dp,  &
		!0.0000636_dp,  &
		!0.0000515_dp,  &
		!0.0000503_dp,  &
		!0.0000447_dp/)
    
INTEGER, PARAMETER  ::          &
	N_sui		= 22,			&
	N_curv		= 4,			&
	N_hloc		= 4,			&
	N_suidur	= 11
    
! Other parameters
REAL(DP), PARAMETER ::          &
    sigma       = 2.00_dp,      &   ! risk aversion
    alpha       = 0.36_dp,      &   ! capital share
    rho_ann     = 0.94_dp,      &   ! autocorrelation of log income shocks (annual)
    sigma_ann   = 0.19_dp,      &   ! standard deviation of innovations (annual)
    delta_ann   = 0.05_dp,      &   ! capital depriciation rate (annual)
    nu          = 2.00_dp,      &
    hikfrac     = 0.15_dp

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!! CONSTANT PARAMETERS !!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

INTEGER, PARAMETER ::           & 
    ncalib      = 5,            &
    N_k 		= 120,     		&   ! grid points for wealth (120) a*z=multiple of 5
    N_kfine     = 2000,    		&   ! fine grid points for wealth (2000)
    N_h         = 3,            &   ! health states (S,I,R)
	N_z 		= 7,     		&   ! grid points for persistent income shocks (7)
    N_s         = 200,          &   ! grid points for savings rate (200)
    N_l         = 040,          &   ! grid points for labor supply (40)
    N_ceq       = 100,          &
    ncapt       = CEILING(MAX(2.0_dp,yrs_cov)*365.0_dp/days), &
    ncaptdist   = FLOOR(20.0_dp*365.0_dp/days),  &
    vfitmax     = 05000,         &  ! 05000
    mufitmax    = 10000,         &
    mxiter      = 10000,         &
    mxtriter    = 200
          
INTEGER :: runmode = 0          ! always initialize to 0

REAL(DP), PARAMETER ::          &
    kmax        = 8000.0_dp,    &   ! upper bound on wealth grid
    kfinemax    = 6000.0_dp,    &   ! upper bound on wealth fine grid
    kmin        = 0.000_dp,     &   ! lower bound on wealth grid
    smin        = 0.000_dp,     &   ! lower bound on savings rate
    smax        = 0.9999_dp,    &   ! upper bound on savings rate
    lmin        = 0.000_dp,     &   ! lower bound on labor supply
    lmid        = 0.460_dp,     &
    lmax        = 0.800_dp,     &   ! upper bound on labor supply
	ceqmax      = 0.200_dp,     &   ! upper bound on remaining cons. equivalent
	ceqmin      = -0.99_dp,     &   ! lower bound on remaining cons. equivalent
    cfhmin      = 0.51_dp,      &   ! lower bound on fraction of cons. at home
    cfhmax      = 0.95_dp           ! upper bound on fraction of cons. at home

REAL(DP), PARAMETER ::          &
    grdpwr_hi   = 4.00_dp,      &   ! curvature > 1
    grdpwr_lo   = 2.00_dp,      &   ! curvature > 1
    onedp       = 1.00_dp,      &   ! 1.0
    zerodp      = 0.00_dp           ! 0.0
                
REAL(DP), PARAMETER ::          &
    infty       = 1.0d15,       &   ! large positive value
    critv       = 1.0d-8,       &   ! save criteria 1.0d-8 (1d-6 for initial calibration)
    crits       = 1.0d-10,      &   ! save criteria 1.0d-10
    criti       = 1.0d-5,       &
    critc       = 5.0d-5,       &
    critb       = 5.0d-5,       &
    crith       = 5.0d-6,       &
    crit2       = 1.0d-4,       &
	eps   		= 1.0d-12,      &   ! epsilon
    updater     = 0.20_dp,      &
    updatei     = 0.20_dp,      &
    updatet     = 0.20_dp,      &
    updateb     = 0.20_dp,      &
    updatecal   = 0.25_dp

END MODULE PARAMETERS