for j in range(ImmunityT): MrkvArray[ j + 1, j ] = ( 1.0 ) # When immune, have 100% chance of transition to state with one fewer immunity periods remaining # %% init_unemployment_immunity = copy(init_idiosyncratic_shocks) init_unemployment_immunity["MrkvArray"] = [MrkvArray] ImmunityExample = MarkovConsumerType(**init_unemployment_immunity) ImmunityExample.assignParameters( Rfree=np.array(np.array(StateCount * [1.03])), # Interest factor same in all states PermGroFac=[ np.array(StateCount * [1.01]) ], # Permanent growth factor same in all states LivPrb=[np.array(StateCount * [0.98])], # Same survival probability in all states BoroCnstArt=None, # No artificial borrowing constraint cycles=0, ) # Infinite horizon ImmunityExample.IncomeDstn = [IncomeDstn] # %% # Solve the unemployment immunity problem and display the consumption functions start_time = process_time() ImmunityExample.solve() end_time = process_time() print( 'Solving an "unemployment immunity" consumer took ' + mystr(end_time - start_time) + " seconds."
# Here, we bring in an agent making a consumption/savings decision every period, subject to transitory and permanent income shocks, AND a Markov shock # %% from HARK.ConsumptionSaving.ConsMarkovModel import MarkovConsumerType ChinaExample = MarkovConsumerType(**init_China_parameters) # %% [markdown] # Currently, Markov states can differ in their interest factor, permanent growth factor, survival probability, and income distribution. Each of these needs to be specifically set. # # Do that here, except shock distribution, which will be done later (because we want to examine the consequences of different shock distributions). # %% GrowthFastAnn = 1.06 # Six percent annual growth GrowthSlowAnn = 1.00 # Stagnation ChinaExample.assignParameters(PermGroFac = [np.array([GrowthSlowAnn,GrowthFastAnn ** (.25)])], #needs to be a list, with 0th element of shape of shape (StateCount,) Rfree = np.array(StateCount*[init_China_parameters['Rfree']]), #needs to be an array, of shape (StateCount,) LivPrb = [np.array(StateCount*[init_China_parameters['LivPrb']][0])], #needs to be a list, with 0th element of shape of shape (StateCount,) cycles = 0) ChinaExample.track_vars = ['aNrmNow','cNrmNow','pLvlNow'] # Names of variables to be tracked # %% [markdown] # Now, add in ex-ante heterogeneity in consumers' discount factors. # # The cstwMPC parameters do not define a single discount factor; instead, there is ex-ante heterogeneity in the discount factor. To prepare to create this ex-ante heterogeneity, first create the desired number of consumer types: # # %% num_consumer_types = 7 # declare the number of types we want ChineseConsumerTypes = [] # initialize an empty list for nn in range(num_consumer_types):
# # Here, we bring in an agent making a consumption/savings decision every period, subject to transitory and permanent income shocks, AND a Markov shock # %% from HARK.ConsumptionSaving.ConsMarkovModel import MarkovConsumerType ChinaExample = MarkovConsumerType(**init_China_parameters) # %% [markdown] # Currently, Markov states can differ in their interest factor, permanent growth factor, survival probability, and income distribution. Each of these needs to be specifically set. # # Do that here, except shock distribution, which will be done later (because we want to examine the consequences of different shock distributions). # %% GrowthFastAnn = 1.06 # Six percent annual growth GrowthSlowAnn = 1.00 # Stagnation ChinaExample.assignParameters(PermGroFac = [np.array([GrowthSlow.,GrowthFast ** (.25)])], #needs to be a list, with 0th element of shape of shape (StateCount,) Rfree = np.array(StateCount*[init_China_parameters['Rfree']]), #needs to be an array, of shape (StateCount,) LivPrb = [np.array(StateCount*[init_China_parameters['LivPrb']][0])], #needs to be a list, with 0th element of shape of shape (StateCount,) cycles = 0) ChinaExample.track_vars = ['aNrmNow','cNrmNow','pLvlNow'] # Names of variables to be tracked # %% [markdown] # Now, add in ex-ante heterogeneity in consumers' discount factors. # # The cstwMPC parameters do not define a single discount factor; instead, there is ex-ante heterogeneity in the discount factor. To prepare to create this ex-ante heterogeneity, first create the desired number of consumer types: # # %% num_consumer_types = 7 # declare the number of types we want ChineseConsumerTypes = [] # initialize an empty list