Log in

Matlab, Python, Julia: What to Choose in Economics?

  • Published:
Computational Economics Aims and scope Submit manuscript

Abstract

We perform a comparison of Matlab, Python and Julia as programming languages to be used for implementing global nonlinear solution techniques. We consider two popular applications: a neoclassical growth model and a new Keynesian model. The goal of our analysis is twofold: First, it is aimed at hel** researchers in economics choose the programming language that is best suited to their applications and, if needed, help them transit from one programming language to another. Second, our collections of routines can be viewed as a toolbox with a special emphasis on techniques for dealing with high dimensional economic problems. We provide the routines in the three languages for constructing random and quasi-random grids, low-cost monomial integration, various global solution methods, routines for checking the accuracy of the solutions as well as examples of parallelization. Our global solution methods are not only accurate but also fast. Solving a new Keynesian model with eight state variables only takes a few seconds, even in the presence of an active zero lower bound on nominal interest rates. This speed is important because it allows the model to be solved repeatedly as would be required for estimation.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Subscribe and save

Springer+ Basic
EUR 32.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or Ebook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2

Similar content being viewed by others

Notes

  1. The accuracy of local perturbation solutions can decrease rapidly away from steady state even in relatively smooth models; see Kollmann et al. (2011). In models with stronger nonlinearities, such as new Keynesian models, approximation errors can reach hundreds of percent under empirically relevant parameterizations; see Judd et al. (2017). In models of labor search, a global solution is important for accurate capturing even first moments of equilibrium dynamics; see Petrosky-Nadeau and Zhang (2017) .

  2. For example, perturbation methods are not well suitable for analyzing sovereign default problems (e.g., Arellano (2008) and portfolio choice problems (e.g., Hasanhodzic and Kotlikoff (2013)). There are perturbation-based methods that can deal with occasionally binding constraints but they are limited to the first-order approximation, for example, see Laseen and Svensson (2011) and Guerrieri and Iacoviello (2015).

  3. For example, Maliar et al. (2019) use deep learning and Google Tensorflow platform to solve a version of Krusell and Smith’s (1998) model by approximating decision functions with 2000 state variables; Lepetuyk et al. (2019) use a combination of unsupervised and supervised (deep) learning to solve a large-scale projection model of the Bank of Canada, etc.

  4. Additionally, we provide a github repository with the code and notebooks with a description of our code and algorithms on the QuantEcon Notebook site. The code is licensed under the BSD-3 license and the Jupyter notebooks are released under the CC BY-ND 4.0 International license.

  5. In a 2018 update to the 2015 paper, Aruoba and Fernandez-Villaverde (2018) recomputed the previously reported running times and find great improvements in several languages, including Matlab, Julia, and Python—their running times are only slightly (less than two times) slower than the fastest C++ code under efficient implementation (MEX, just-in-time compilers). This finding indicates that the users of high-level languages such as Matlab, Julia, and Python do not sacrifice much of computational speed relative to the fastest low-level alternatives.

  6. As an example, if one wanted to run a Matlab program on 16 optimized processors on the Amazon Compute Cloud, then in addition to paying $0.68/h for the processor time, it would cost an additional $0.06/h per processor to license each processor bringing the total cost from $0.68 to $1.64/h. For details see Matlab’s pricing site and Amazon’s pricing site.

  7. An exception is Matlab Central which is an open exchange for the Matlab users with 365,000 current contributors.

  8. This is a popular question-and-answer website for programming.

  9. The solutions mostly involve allowing for shared memory parallel for-loops, numerical operations, and linear algebra.

  10. Just-in-time compilation means that a function is compiled the first time it is called and all subsequent calls to that function are faster.

  11. ,See https://julialang.org/benchmarks/ for some example benchmarks.

  12. There has been work to add just-in-time compilation to both Matlab and Python, but, because it isn’t native to either language, it does not work as generically as it does in Julia.

  13. The main exception to this was interpolation with complete polynomials but this was also missing in both Python and Matlab.

  14. The use of @ for matrix multiplication was added in Python version 3.5. Readers who have seen or written Python code written for Python versions earlier than version 3.5 might have come across A.dot(B) or np.dot(A, B) instead.

  15. The Matlab notebook, Python notebook, Julia notebook.

  16. A version of the envelope condition argument is used in Achdou et al. (2017) to construct a new class of fast and efficient numerical methods for solving dynamic economic models in continuous time.

  17. Matlab notebook, Python notebook, Julia notebook.

References

  • Achdou, Y., Han, J., Lasry, J.-M., Lions, P.-L., & Moll, B. (2017). Income and wealth distribution in macroeconomics: A continuous-time approach. NBER Working Paper No. w23732.

  • Arellano, C. (2008). Default risk and income fluctuations in emerging economies. American Economic Review, 98(3), 690–712.

    Article  Google Scholar 

  • Arellano, C., Maliar, L., Maliar, S., & Tsyrennikov, V. (2016). Envelope condition method with an application to default risk models. Journal of Economic Dynamics and Control, 69, 436–459.

    Article  Google Scholar 

  • Aruoba, S., & Fernandez-Villaverde, J. (2015). A comparison of programming languages in economics. Journal of Economic Dynamics and Control, 58, 265–273.

    Article  Google Scholar 

  • Aruoba, S., & Fernandez-Villaverde, J. (2018). A comparison of programming languages in economics: An update.

  • Barillas, F., & Fernandez-Villaverde, J. (2007). A generalization of the endogenous grid method. Journal of Economic Dynamics and Control, 31, 2698–2712.

    Article  Google Scholar 

  • Carroll, K. (2005). The method of endogenous grid points for solving dynamic stochastic optimal problems. Economic Letters, 91, 312–320.

    Article  Google Scholar 

  • Fernández-Villaverde, J., Rubio-Ramírez, J., & Schorfheide, F. (2015). Solution and estimation methods for DSGE models. Handbook of Macroeconomics, 2, 527–724.

    Article  Google Scholar 

  • Fernández-Villaverde, J., & Zarruk Valencia, D. (2018). A practical guide to parallelization in economics.

  • Guerrieri, L., & Iacoviello, M. (2015). OccBin: A toolkit for solving dynamic models with occasionally binding constraints easily. Journal of Monetary Economics, 70, 22–38.

    Article  Google Scholar 

  • Hasanhodzic, J., & Kotlikoff, L. (2013). Generational risk—Is it a big deal? Simulating an 80-period OLG model with aggregate shocks. NBER Working Paper 19179.

  • Judd, K. (1998). Numerical methods in economics. Cambridge, MA: MIT Press.

    Google Scholar 

  • Judd, K., Maliar, L., & Maliar, S. (2011). Numerically stable and accurate stochastic simulation approaches for solving dynamic models. Quantitative Economics, 2, 173–210.

    Article  Google Scholar 

  • Judd, K., Maliar, L., & Maliar, S. (2016). Lower bounds on approximation errors to numerical solutions of dynamic economic models. Econometrica, 85(3), 991–1012.

    Article  Google Scholar 

  • Kollmann, R., Kim, S., & Kim, J. (2011). Solving the multi-country real business cycle model using a perturbation method. Journal of Economic Dynamics and Control, 35, 203–206.

    Article  Google Scholar 

  • Krusell, P., & Smith, A. A, Jr. (1998). Income and wealth heterogeneity in the macroeconomy. Journal of Political Economy, 106(5), 867–896.

    Article  Google Scholar 

  • Laseen, S., & Svensson, L. (2011). Anticipated alternative policy rate paths inpolicy simulations. UCB International Journal of International Banking, 7(3), 1–36.

    Google Scholar 

  • Lepetuyk, V., Maliar, L., & Maliar, S. (2019). When the U.S. Catches a Cold, Canada Sneezes: A Lower-Bound Tale Told by Deep Learning. CEPR working paper DP 14025.

  • Maliar, L., & Maliar, S. (2013). Envelope condition method versus endogenous grid method for solving dynamic programming problems. Economic Letters, 120, 262–266.

    Article  Google Scholar 

  • Maliar, L., & Maliar, S. (2014). Numerical methods for large scale dynamic economic models. In K. Schmedders & K. Judd (Eds.), Handbook of computational economics (Vol. 3). Amsterdam: Elsevier Science.

    Google Scholar 

  • Maliar, L., & Maliar, S. (2015). Merging simulation and projection approaches to solve high-dimensional problems with an application to a new Keynesian Model. Quantitative Economics, 6, 1–47.

    Article  Google Scholar 

  • Maliar, L., Maliar, S., Taylor, J.B., & Tsener, I. (2015). A tractable framework for analyzing a class of nonstationary markov models. NBER working paper 21155.

  • Maliar, L., Maliar, S., & Winant, P. (2019). Will Artificial Intelligence Replace Computational Economists Any Time Soon?. CEPR working paper DP 14024.

  • Negro, M. D., et al. (2007). On the fit of new Keynesian models. Journal of Business & Economic Statistics, 25(2), 123–143.

    Article  Google Scholar 

  • Petrosky-Nadeau, N., & Zhang, L. (2017). Solving the Diamond–Mortensen-pissarides model accurately. Quantitative Economics, 8(2), 611–650.

    Article  Google Scholar 

  • Santos, M. (1999). Numerical solution of dynamic economic models. In J. Taylor & M. Woodford (Eds.), Handbook of macroeconomics (pp. 312–382). Amsterdam: Elsevier Science.

    Google Scholar 

  • Santos, M., & Rust, J. (2008). Convergence properties of policy iteration. SIAM Journal on Control and Optimization, 42(6), 2094–2115.

    Article  Google Scholar 

  • Smets, F., & Wouters, R. (2007). Shocks and frictions in US business cycles: A Bayesian DSGE approach. American Economic Review, 97(3), 586–606.

    Article  Google Scholar 

  • Taylor, J., & Uhlig, H. (1990). Solving nonlinear stochastic growth models: A comparison of alternative solution methods. Journal of Business and Economic Statistics, 8, 1–17.

    Google Scholar 

Download references

Funding

Lilia Maliar and Serguei Maliar acknowledge the support from NSF grants SES-1949413 and SES-1949430, respectively.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Chase Coleman.

Additional information

Publisher's Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Electronic supplementary material

Below is the link to the electronic supplementary material.

Electronic supplementary material 1 (PDF 5794 kb)

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Coleman, C., Lyon, S., Maliar, L. et al. Matlab, Python, Julia: What to Choose in Economics?. Comput Econ 58, 1263–1288 (2021). https://doi.org/10.1007/s10614-020-09983-3

Download citation

  • Accepted:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10614-020-09983-3

Keywords

JEL Classification

Navigation