Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed hardcoded updateAFunc parameters into proper parameters #244

Merged
merged 2 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions HARK/ConsumptionSaving/ConsAggShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,20 @@ def __init__(self,agents=[],tolerance=0.0001,act_T=1000,**kwds):
tolerance=tolerance,
act_T=act_T)
self.assignParameters(**kwds)
self.max_loops = 20
self.update()


# Use previously hardcoded values for AFunc updating if not passed
# as part of initialization dictionary. This is to prevent a last
# minute update to HARK before a release from having a breaking change.
if not hasattr(self,'DampingFac'):
self.DampingFac = 0.5
if not hasattr(self,'max_loops'):
self.max_loops = 20
if not hasattr(self,'T_discard'):
self.T_discard = 200
if not hasattr(self,'verbose'):
self.verbose = True


def millRule(self,aLvlNow,pLvlNow):
'''
Expand Down Expand Up @@ -998,11 +1009,11 @@ def reset(self):

Parameters
----------
none
None

Returns
-------
none
None
'''
self.Shk_idx = 0
Market.reset(self)
Expand All @@ -1015,11 +1026,11 @@ def makeAggShkHist(self):

Parameters
----------
none
None

Returns
-------
none
None
'''
sim_periods = self.act_T
Events = np.arange(self.AggShkDstn[0].size) # just a list of integers
Expand Down Expand Up @@ -1085,18 +1096,18 @@ def calcAFunc(self,MaggNow,AaggNow):
Parameters
----------
MaggNow : [float]
List of the history of the simulated aggregate market resources for an economy.
List of the history of the simulated aggregate market resources for an economy.
AaggNow : [float]
List of the history of the simulated aggregate savings for an economy.
List of the history of the simulated aggregate savings for an economy.

Returns
-------
(unnamed) : CapDynamicRule
Object containing a new savings rule
'''
verbose = True
discard_periods = 200 # Throw out the first T periods to allow the simulation to approach the SS
update_weight = 0.80 # Proportional weight to put on new function vs old function parameters
verbose = self.verbose
discard_periods = self.T_discard # Throw out the first T periods to allow the simulation to approach the SS
update_weight = 1. - self.DampingFac # Proportional weight to put on new function vs old function parameters
total_periods = len(MaggNow)

# Regress the log savings against log market resources
Expand Down Expand Up @@ -1576,9 +1587,9 @@ def calcAFunc(self,MaggNow,AaggNow):
(unnamed) : CapDynamicRule
Object containing new saving rules for each Markov state.
'''
verbose = True
discard_periods = 200 # Throw out the first T periods to allow the simulation to approach the SS
update_weight = 0.8 # Proportional weight to put on new function vs old function parameters
verbose = self.verbose
discard_periods = self.T_discard # Throw out the first T periods to allow the simulation to approach the SS
update_weight = 1. - self.DampingFac # Proportional weight to put on new function vs old function parameters
total_periods = len(MaggNow)

# Trim the histories of M_t and A_t and convert them to logs
Expand Down Expand Up @@ -1762,7 +1773,7 @@ def main():
solve_agg_shocks_market = True # Solve for the equilibrium aggregate saving rule in a CobbDouglasEconomy

solve_markov_micro = False # Solve an AggShockMarkovConsumerType's microeconomic problem
solve_markov_market = False # Solve for the equilibrium aggregate saving rule in a CobbDouglasMarkovEconomy
solve_markov_market = True # Solve for the equilibrium aggregate saving rule in a CobbDouglasMarkovEconomy
solve_krusell_smith = True # Solve a simple Krusell-Smith-style two state, two shock model
solve_poly_state = False # Solve a CobbDouglasEconomy with many states, potentially utilizing the "state jumper"

Expand Down Expand Up @@ -1827,6 +1838,7 @@ def main():

# Make a Cobb-Douglas economy for the agents
MrkvEconomyExample = CobbDouglasMarkovEconomy(agents = [AggShockMrkvExample],**Params.init_mrkv_cobb_douglas)
MrkvEconomyExample.DampingFac = 0.2 # Turn down damping
MrkvEconomyExample.makeAggShkHist() # Simulate a history of aggregate shocks
AggShockMrkvExample.getEconomyData(MrkvEconomyExample) # Have the consumers inherit relevant objects from the economy

Expand Down Expand Up @@ -1856,7 +1868,7 @@ def main():
t_end = clock()
print('Solving the "macroeconomic" aggregate shocks model took ' + str(t_end - t_start) + ' seconds.')

print('Aggregate savings as a function of aggregate market resources (for each macro state):')
print('Consumption function at each aggregate market resources-to-labor ratio gridpoint (for each macro state):')
m_grid = np.linspace(0,10,200)
AggShockMrkvExample.unpackcFunc()
for i in range(2):
Expand Down
10 changes: 9 additions & 1 deletion HARK/ConsumptionSaving/ConsumerParameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@
CRRAPF = CRRA # Coefficient of relative risk aversion of perfect foresight calibration
intercept_prev = 0.0 # Intercept of aggregate savings function
slope_prev = 1.0 # Slope of aggregate savings function
verbose_cobb_douglas = True # Whether to print solution progress to screen while solving
T_discard = 200 # Number of simulated "burn in" periods to discard when updating AFunc
DampingFac = 0.5 # Damping factor when updating AFunc; puts DampingFac weight on old params, rest on new
max_loops = 20 # Maximum number of AFunc updating loops to allow

# Make a dictionary to specify an aggregate shocks consumer
init_agg_shocks = copy(init_idiosyncratic_shocks)
Expand All @@ -205,7 +209,11 @@
'AggregateL':1.0,
'act_T':1200,
'intercept_prev': intercept_prev,
'slope_prev': slope_prev
'slope_prev': slope_prev,
'verbose': verbose_cobb_douglas,
'T_discard': T_discard,
'DampingFac': DampingFac,
'max_loops': max_loops
}

# -----------------------------------------------------------------------------
Expand Down