-
-
Notifications
You must be signed in to change notification settings - Fork 199
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
Add proper Krusell-Smith model #762
Conversation
CDC really wants to be able to solve KS, so I wrote a solver just for that model. Completely untested, and needs an AgentType and Market to go with it. First 2/3 of the solution code can be done in pre-computational step.
Walked Mridul through KS model math and solver and began writing AgentType subclass for it. Still need to do the obnoxious arithmetic of the good-bad bad bad-good idiosyncratic transitions.
Made tiny example file, solveKrusellSmith seems to work as intended. Need to make a special Market subclass for it.
Had to force idiosyncratic shocks to exactly match specified probabilities, but it works. Need to clean up model file and do a bit of work to speed up the process.
Default KS model parameters now more closely match version in their paper, but it also takes a shockingly long time to solve. Moved dictionaries into model file, will move example code next.
Also deleted figure-producing progress code lines.
These should pass and don't add much to test time.
I have ell tilde in my class notes as 0.3271, if that helps |
This does help, as I had hand-calibrated it to 0.325 to fit the KS results.
I was worried that they used 1/3 or 0.33 and there was still an error in
the code.
Given that all the other calibrated numbers are very rough and the entire
model has no scale, do you know where/why they used this specific number to
4 digits? Is it in the paper and I missed it?
…On Mon, Jul 20, 2020, 5:49 PM alanlujan91 ***@***.***> wrote:
I have ell tilde in my class notes as 0.3271, if that helps
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#762 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADKRAFIWUV5MAZ2XHIBWL4TR4S3UZANCNFSM4PCZ675Q>
.
|
I don't think the number is on the paper. As far as I remember, the source of this number is my prof. emailing one of the authors. |
Thank you very much for confirming this.
…On Mon, Jul 20, 2020, 7:42 PM alanlujan91 ***@***.***> wrote:
I don't think the number is on the paper. As far as I remember, the source
of this number is my prof. emailing one of the authors.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#762 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADKRAFLIAS5SGD2Y4T7CKOTR4TI63ANCNFSM4PCZ675Q>
.
|
# This can be written more concisely, but is intentionally explicit for | ||
# the sake of making it very easy to read | ||
if self.MrkvNow == 0: # Bad macroeconomic conditions | ||
these = np.logical_not(self.EmpNow) # Unemployed agents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe name this variable unemployed_agents
instead of these
.
Save you having to explain it in comment :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose, but this is used throughout HARK for binary indexing arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough. just a suggestion.
# Add consumer-type specific objects | ||
self.time_vary = [] | ||
self.time_inv = ['DiscFac', 'CRRA',] | ||
self.poststate_vars = ['aNow','EmpNow'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a critique of this code but a general question...
I see that the poststate_vars are listed explicitly here.
Would it be silly to list (a) the regular states, (b) the control variables, and (c) the shocks in lists like these?
I mean, in a future implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That can be done. They're listed here and in all HARK models because initializeSim() initializes them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. I think I can demo how this would look in a PR for the next weekly meeting.
Mcount = self.Mgrid.size | ||
|
||
# Make tiled array of end-of-period idiosyncratic assets (order: a, M, s, s') | ||
aNow_tiled = np.tile(np.reshape(self.aGrid, [aCount, 1, 1, 1]), [1, Mcount, 4, 4]) # shape (aCount, Mcount, 4, 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I think the code formatting of this PR is really nice.
I was going to ask if you used black
for it?
I'm surprised by this long line (in terms of number of characters) though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I didn't use black. All of my comments with the shape of arrays can be removed (will do that now). I put those in while explaining the code the Mridul.
Ack, just caught that I forgot to put pre-computed arrays into the solveKrusellSmith docstring. |
I've made a few minor comments. |
Fixed and expanded some comments, added comparison of our results to KS' published numbers (in the example). Adjusted LbrInd parameter to use value that Alan Lujan says his prof got from KS. Future readers: please cite this chain for the parameter value missing from Krusell-Smith (1998).
self.makeGrid() | ||
self.updateSolutionTerminal() | ||
|
||
def getEconomyData(self, Economy): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be lower case -- see how the GitHub syntax highlighting misformats this as a class name because it is capitalized.
I see this is common to other uses of getEconomyData though.
self.MrkvIndArray = Economy.MrkvIndArray # Transition probabilities among discrete states | ||
self.MrkvAggArray = Economy.MrkvArray # Transition probabilities among aggregate discrete states | ||
self.addToTimeInv('Mgrid', 'AFunc', 'DeprFac', 'CapShare', 'UrateB', 'LbrInd',\ | ||
'UrateG', 'ProdB', 'ProdG', 'MrkvIndArray', 'MrkvAggArray') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #764 . If those aspects of the economy that needed to be brought into the Agent were available in a list (as most of them are here), then it would be possible to write this method generically as a loop over those values, rather than writing out each one individually.
This is common across all uses of getEconomyData
But not all of them are just "take this attribute of that and make it an
attribute of self". Some of them change names or do a very small bit of
coding. Yes, that can be done in the lines below.
Change it as you see fit.
…On Tue, Jul 21, 2020 at 3:29 PM Sebastian Benthall ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In HARK/ConsumptionSaving/ConsAggShockModel.py
<#762 (comment)>:
> + self.T_sim = Economy.act_T # Need to be able to track as many periods as economy runs
+ self.kInit = Economy.KSS # Initialize simulation assets to steady state
+ self.MrkvInit = Economy.MrkvNow_init # Starting Markov state for the macroeconomy
+ self.Mgrid = Economy.MSS*self.MgridBase # Aggregate market resources grid adjusted around SS capital ratio
+ self.AFunc = Economy.AFunc # Next period's aggregate savings function
+ self.DeprFac = Economy.DeprFac # Rate of capital depreciation
+ self.CapShare = Economy.CapShare # Capital's share of production
+ self.LbrInd = Economy.LbrInd # Idiosyncratic labor supply (when employed)
+ self.UrateB = Economy.UrateB # Unemployment rate in bad state
+ self.UrateG = Economy.UrateG # Unemployment rate in good state
+ self.ProdB = Economy.ProdB # Total factor productivity in bad state
+ self.ProdG = Economy.ProdG # Total factor productivity in good state
+ self.MrkvIndArray = Economy.MrkvIndArray # Transition probabilities among discrete states
+ self.MrkvAggArray = Economy.MrkvArray # Transition probabilities among aggregate discrete states
+ self.addToTimeInv('Mgrid', 'AFunc', 'DeprFac', 'CapShare', 'UrateB', 'LbrInd',\
+ 'UrateG', 'ProdB', 'ProdG', 'MrkvIndArray', 'MrkvAggArray')
See #764 <#764> . If those aspects
of the economy that needed to be brought into the Agent were available in a
list (as most of them are here), then it would be possible to write this
method generically as a loop over those values, rather than writing out
each one individually.
This is common across all uses of getEconomyData
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#762 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADKRAFIL47CWPTZGFVUU4DLR4XUA7ANCNFSM4PCZ675Q>
.
|
Made #766 for that issue. |
Is this PR ready to merge, from your perspective, @mnwhite ? |
Yes, I think so.
…On Tue, Jul 21, 2020 at 4:00 PM Sebastian Benthall ***@***.***> wrote:
Is this PR ready to merge, from your perspective, @mnwhite
<https://github.com/mnwhite> ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#762 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADKRAFK3V6FQ4FNXUMD6NM3R4XXUTANCNFSM4PCZ675Q>
.
|
Ah, the one thing left is to make the ipynb example match the py. There's
an automated thing for that?
…On Tue, Jul 21, 2020 at 4:25 PM Sebastian Benthall ***@***.***> wrote:
Merged #762 <#762> into master.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#762 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADKRAFPPVIJNO52STJGYY7TR4X2SFANCNFSM4PCZ675Q>
.
|
! Oh, perhaps I merged too soon ! Yes, I think what you are looking for is |
We can just do it in another branch.
…On Tue, Jul 21, 2020 at 4:36 PM Sebastian Benthall ***@***.***> wrote:
! Oh, perhaps I merged too soon !
Yes, I think what you are looking for is jupytext
https://jupytext.readthedocs.io/en/latest/using-cli.html
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#762 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADKRAFJ5J3ZV5RKWZMS26QLR4X35RANCNFSM4PCZ675Q>
.
|
CDC has long wanted HARK to be able to solve the Krusell-Smith (1998) model verbatim; this PR adds that capability. Previously, we had "fake KS", as our Markov ConsAggShock model didn't have serially correlated unemployment.
This PR includes new AgentType and Market subclasses in ConsAggShockModel.py, as the Krusell-Smith model is so specialized that trying to shoehorn trivial versions of existing HARK model objects would just overcomplicate things. The one compromise with HARK is that the aggregate saving rule (regressing log A_t on log M_t conditional on the state of the economy) is still the equilibrium object, rather than a straight log K_t on log K_{t-1} like in the Krusell-Smith paper. HARK's existing models use the "A on M" approach because we have aggregate risk other than the binary state of the macroeconomy, so K_{t-1} is not a sufficient statistic for the aggregate state in period t.
Example has been added to the ConsAggShock example file, replacing the old "fake KS" example. Tests have also been added. Default parameters are set to those in the KS paper, with the exception of LbrInd (\tilde{\ell}), whose value is not provided in the paper as far as I can tell. Their results are nearly identically replicated.
This code does not handle the KS version of discount factor heterogeneity, as CDC did not reply to my query about whether he wanted that included.