Skip to content

Commit

Permalink
adding simulation test for PerfForesightConsumerType
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenthall committed Feb 26, 2020
1 parent a30ff3d commit f778419
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion HARK/ConsumptionSaving/tests/test_PerfForesightConsumerType.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from HARK.ConsumptionSaving.ConsIndShockModel import PerfForesightConsumerType

import numpy as np
import unittest

class testPerfForesightConsumerType(unittest.TestCase):
Expand All @@ -25,3 +25,53 @@ def test_checkConditions(self):
self.assertTrue(self.agent_infinite.GICPF)
self.assertTrue(self.agent_infinite.RIC)
self.assertTrue(self.agent_infinite.FHWC)

def test_simulation(self):

self.agent_infinite.solve()

# Create parameter values necessary for simulation
SimulationParams = {
"AgentCount" : 10000, # Number of agents of this type
"T_sim" : 120, # Number of periods to simulate
"aNrmInitMean" : -6.0, # Mean of log initial assets
"aNrmInitStd" : 1.0, # Standard deviation of log initial assets
"pLvlInitMean" : 0.0, # Mean of log initial permanent income
"pLvlInitStd" : 0.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
}

self.agent_infinite(**SimulationParams) # This implicitly uses the assignParameters method of AgentType

# Create PFexample object
self.agent_infinite.track_vars = ['mNrmNow']
self.agent_infinite.initializeSim()
self.agent_infinite.simulate()

self.assertAlmostEqual(
np.mean(self.agent_infinite.mNrmNow_hist,axis=1)[40],
-23.008063500363942
)

self.assertAlmostEqual(
np.mean(self.agent_infinite.mNrmNow_hist,axis=1)[100],
-27.164608851546927
)

## Try now with the manipulation at time step 80

self.agent_infinite.initializeSim()
self.agent_infinite.simulate(80)
self.agent_infinite.aNrmNow += -5. # Adjust all simulated consumers' assets downward by 5
self.agent_infinite.simulate(40)

self.assertAlmostEqual(
np.mean(self.agent_infinite.mNrmNow_hist,axis=1)[40],
-23.008063500363942
)

self.assertAlmostEqual(
np.mean(self.agent_infinite.mNrmNow_hist,axis=1)[100],
-29.140261331951606
)

0 comments on commit f778419

Please sign in to comment.