Skip to content

Commit

Permalink
Merge pull request #1456 from econ-ark/Expand-SSJ-exposition
Browse files Browse the repository at this point in the history
Expand SSJ exposition
  • Loading branch information
mnwhite authored Jun 14, 2024
2 parents 1eed24e + 4e6f252 commit 2b345ca
Show file tree
Hide file tree
Showing 5 changed files with 782 additions and 349 deletions.
13 changes: 9 additions & 4 deletions HARK/ConsumptionSaving/ConsNewKeynesianModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,24 @@
# Default parameters to make aXtraGrid using make_assets_grid
default_aXtraGrid_params = {
"aXtraMin": 0.001, # Minimum end-of-period "assets above minimum" value
"aXtraMax": 20, # Maximum end-of-period "assets above minimum" value
"aXtraMax": 50, # Maximum end-of-period "assets above minimum" value
"aXtraNestFac": 3, # Exponential nesting factor for aXtraGrid
"aXtraCount": 48, # Number of points in the grid of "assets above minimum"
"aXtraCount": 100, # Number of points in the grid of "assets above minimum"
"aXtraExtra": None, # Additional other values to add in grid (optional)
}

# Make a dictionary to specify an idiosyncratic income shocks consumer type
init_newkeynesian = {
# BASIC HARK PARAMETERS REQUIRED TO SOLVE THE MODEL
"cycles": 1, # Finite, non-cyclic model
"cycles": 0, # Infinite horizon model
"T_cycle": 1, # Number of periods in the cycle for this agent type
"constructors": newkeynesian_constructor_dict, # See dictionary above
# PRIMITIVE RAW PARAMETERS REQUIRED TO SOLVE THE MODEL
"CRRA": 2.0, # Coefficient of relative risk aversion
"Rfree": 1.03, # Interest factor on retained assets
"DiscFac": 0.96, # Intertemporal discount factor
"LivPrb": [0.98], # Survival probability after each period
"PermGroFac": [1.01], # Permanent income growth factor
"PermGroFac": [1.0], # Permanent income growth factor
"BoroCnstArt": 0.0, # Artificial borrowing constraint
"vFuncBool": False, # Whether to calculate the value function during solution
"CubicBool": False, # Whether to use cubic spline interpolation when True
Expand All @@ -95,6 +95,11 @@
"PerfMITShk": False, # Do Perfect Foresight MIT Shock
# (Forces Newborns to follow solution path of the agent they replaced if True)
"neutral_measure": False, # Whether to use permanent income neutral measure (see Harmenberg 2021)
# ADDITIONAL PARAMETERS FOR GRID-BASED TRANSITION SIMULATION
"mMin": 0.001,
"mMax": 50,
"mCount": 200,
"mFac": 3,
}
init_newkeynesian.update(default_IncShkDstn_params)
init_newkeynesian.update(default_aXtraGrid_params)
Expand Down
62 changes: 9 additions & 53 deletions HARK/ConsumptionSaving/tests/test_ConsNewKeynesianModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,15 @@
from HARK.ConsumptionSaving.ConsNewKeynesianModel import NewKeynesianConsumerType
from HARK.tests import HARK_PRECISION

jacobian_test_dict = {
# Parameters shared with the perfect foresight model
"CRRA": 2, # Coefficient of relative risk aversion
"Rfree": 1.04**0.25, # Interest factor on assets
"DiscFac": 0.9735, # Intertemporal discount factor
"LivPrb": [0.99375], # Survival probability
"PermGroFac": [1.00], # Permanent income growth factor
# Parameters that specify the income distribution over the lifecycle
"PermShkStd": [
0.06
], # [(0.01*4/11)**0.5], # Standard deviation of log permanent shocks to income
"PermShkCount": 5, # Number of points in discrete approximation to permanent income shocks
"TranShkStd": [0.3], # Standard deviation of log transitory shocks to income
"TranShkCount": 5, # Number of points in discrete approximation to transitory income shocks
"UnempPrb": 0.07, # Probability of unemployment while working
"IncUnemp": 0.3, # Unemployment benefits replacement rate
"UnempPrbRet": 0.0005, # Probability of "unemployment" while retired
"IncUnempRet": 0.0, # "Unemployment" benefits when retired
"T_retire": 0, # Period of retirement (0 --> no retirement)
# Parameters for constructing the "assets above minimum" grid
"aXtraMin": 0.001, # Minimum end-of-period "assets above minimum" value
"aXtraMax": 20, # Maximum end-of-period "assets above minimum" value
"aXtraCount": 48, # Number of points in the base grid of "assets above minimum"
"aXtraNestFac": 3, # Exponential nesting factor when constructing "assets above minimum" grid
"aXtraExtra": None, # Additional values to add to aXtraGrid
# A few other parameters
"BoroCnstArt": 0.0, # Artificial borrowing constraint; imposed minimum level of end-of period assets
"vFuncBool": True, # Whether to calculate the value function during solution
"CubicBool": False, # Preference shocks currently only compatible with linear cFunc
"T_cycle": 1, # Number of periods in the cycle for this agent type
# Parameters only used in simulation
"AgentCount": 500, # Number of agents of this type
"T_sim": 100, # Number of periods to simulate
"aNrmInitMean": np.log(1.3) - (0.5**2) / 2, # Mean of log initial assets
"aNrmInitStd": 0.5, # Standard deviation of log initial assets
"pLvlInitMean": 0, # Mean of log initial permanent income
"pLvlInitStd": 0, # Standard deviation of log initial permanent income
"PermGroFacAgg": 1.0, # Aggregate permanent income growth factor
"T_age": None, # Age after which simulated agents are automatically killed
# Parameters for Transition Matrix Simulation
"mMin": 0.001,
"mMax": 20,
"mCount": 48,
"mFac": 3,
}


# %% Test Transition Matrix Methods

# Uses class default values


class test_Transition_Matrix_Methods(unittest.TestCase):
def test_calc_tran_matrix(self):
example1 = NewKeynesianConsumerType(**jacobian_test_dict)
example1 = NewKeynesianConsumerType()
example1.cycles = 0
example1.solve()

Expand All @@ -83,19 +39,19 @@ def test_calc_tran_matrix(self):
AggC = np.dot(gridc.flatten(), vecDstn) # Aggregate Consumption
AggA = np.dot(grida.flatten(), vecDstn) # Aggregate Assets

self.assertAlmostEqual(AggA[0], 1.19513, places=4)
self.assertAlmostEqual(AggC[0], 1.00417, places=4)
self.assertAlmostEqual(AggA[0], 0.82984, places=4)
self.assertAlmostEqual(AggC[0], 1.00780, places=4)


# %% Test Heterogenous Agent Jacobian Methods


class test_Jacobian_methods(unittest.TestCase):
def test_calc_jacobian(self):
Agent = NewKeynesianConsumerType(**jacobian_test_dict)
Agent = NewKeynesianConsumerType()
Agent.compute_steady_state()
CJAC_Perm, AJAC_Perm = Agent.calc_jacobian("PermShkStd", 50)

self.assertAlmostEqual(CJAC_Perm.T[30][29], -0.06120, places=HARK_PRECISION)
self.assertAlmostEqual(CJAC_Perm.T[30][30], 0.05307, places=HARK_PRECISION)
self.assertAlmostEqual(CJAC_Perm.T[30][31], 0.04674, places=HARK_PRECISION)
self.assertAlmostEqual(CJAC_Perm.T[30][29], -0.10503, places=HARK_PRECISION)
self.assertAlmostEqual(CJAC_Perm.T[30][30], 0.10316, places=HARK_PRECISION)
self.assertAlmostEqual(CJAC_Perm.T[30][31], 0.09059, places=HARK_PRECISION)
133 changes: 107 additions & 26 deletions examples/SSJ-Example/KS-HARK-presentation.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 2b345ca

Please sign in to comment.