Code for krusell & smith (1998)

Is there any plan to release the python code for krusell & smith (1998) in the lecture notes?

Hi @coolsun, good question. We should certainly have a lecture on Krusell–Smith or, more generally, Bewley models with aggregate shocks. It would be useful to have both Python and Julia code.

I’m not sure when we’ll get it up, but I’ll put an issue in our issue tracker and hopefully we’ll get to it in the next month or two.

Thanks for the suggestion.

Thanks a lot, @john.stachurski. It sounds very promising. Besides, some examples of structural estimations (e.g SMM etc) would also be highly desirable.

1 Like

Thanks @coolsun, that’s very true. If you don’t mind, it would be great if you could open up a new topic to discuss structural estimation separately. We can keep this topic for Krusell–Smith and related work.

Regarding Krusell–Smith, the QuantEcon team reviewed the issue internally. The main thoughts were

  • Although more sophisticated approaches are available, the original KS method is worth treating for pedagogical reasons

  • Regarding more recent approaches, this paper (Reiter, JEDC, 2009) is worth treating

Further comments are welcome.

1 Like

Thank you very much, @john.stachurski. I am looking forward to seeing the python implementation in the original KS method. Besides, I will start a new thread to discuss about the structural estimation. Thanks again.

@john.stachurski Can I start writing a program for Krusell-Smith using Julia for my practice and, possibly, for the lecture?

That would be great. A good first step would be to simply port existing Matlab code or Fortran code and verify that the results are the same.

1 Like

Hi all, FYI, @Shunsuke-Hori has written a first pass at implementing KS using Julia.

You can find (and comment on or contribute to) it here:

@Shunsuke-Hori Would you mind to explain a bit more about what you’ve done, either here or in the notebook? The code runs fine for me, in a bit over an hour. But I’m not sure how to assess it. Does it replicate some particular existing result or computation? How does it succeed or fail?

PS Thanks to Victoria Gregory and James Graham from NYU for also submitting code.

I updated the notebook. The new notebook includes explanations about the code.

I compared the result of my program and the one by Matlab, which you can find here, with same parameterization (i.e., set mu=0 in Matlab)

  • The path of aggregate capital law of motion looks very close; it fluctuates around 40
  • The R2 is sufficiently high in my code as well, 0.99987477 for good state and 0.99973780 for bad state
  • Should the coefficient of approximated capital law of motion be closer to Matlab one? In Matlab,
    log(K_{t+1})=0.1390+0.9629 log(K_{t}) in good time
    log(K_{t+1})=0.1266+0.9648 log(K_{t}) in bad time

Hi. Greetings. I have adapted the Krusell-Smith code from Maliar, Maliar, and Valli (2010) JEDC into Python. The only major difference from the original paper is that an Euler-equation method is used to solve the household problem. How should I make it available? I have not yet used GitHub.


Hi @msilva913,

Sorry for the slow reply. We’ve been working on a new site for sharing notebooks that you can find here:

Please feel free to share your code using that site, as a Jupyter notebook.

We’re still in the process of eliminating bugs, so if you have any problems submitting or notice any issues, please let me know.

Thanks for being willing to share your code!

Regards, John.

@Shunsuke-Hori If you are willing to share your code on the same site ( that would also be appreciated!

Regards, John.

Dear John Stachurski:

Sure thing. I will reformat it as a Jupyter notebook and submit it within the next few days.


Mario Silva

Dear John:

Apologies for the delay. I have submitted the notebook under the name Krusell_Smith.ipynb.

By the way, I noticed under quantecon.optimize.scalar_maximization there is development of a jitted version of fminbound. Is this function operational or still under

development? It would be extremely useful!

Thank you.


Mario Silva

@msilva913 Cool, thanks. Very nice.

Regarding jitted scalar maximization, that’s actually been merged now:

But I don’t think it’s in the latest pip / conda release. If you want it please instead grab the master branch from GitHub.

We’re on a mission to add JIT compilation to most of the lectures, and that means building jitted optimization and interpolation routines. You can find some discussion here:

Feel free to comment if you have feature requests.


Excellent! Thank you very much.