﻿ IGIER - Universita' Bocconi
Home

# Python codes

I developed the following Python modules for use in my own research projects. Even if some of the tools are already available in the standard toolboxes, my implementations are generally faster (Numba and its multithreading capabilities are extensively used) and tailored to the typical workflow in quantitative macroeconomics. Please cite the source if my codes are used for academic work. Enjoy!

PS. No implicit or explicit warranty is provided. Use my codes at your own risk. Consider that your PC may blow up, reformat itself, or you may be prevented from publishing your stuff on Econometrica.

Linear and non-linear interpolation:

• interpolation.py. This module exposes the following classes:
• Interp1D: fast univariate linear interpolation. The class is instantiated with x, the nodes, and xn, the points where to interpolate. The points in xn are located on the grid only once. The instance can be called with y, the function values at x, and outputs yn, the interpolated values. Note that y can be multidimensional. The code is accelerated and parallelized with Numba. A typical application would be the following: x can be the grid for physical capital, y the consumption levels on the grid (for each value of TFP), xn the array of future capital stocks. yn becomes the array of interpolated future consumption levels (for each value of TFP). Rings a bell?
• Interp2D: fast bivariate bilinear and simplicial interpolation. The workflow is a bivariate version of the one above.
• InterpND: fast multivariate interpolation. One can choose between Piecewise multilinear interpolation and Piecewise linear interpolation on Kuhn triangulation. See Weiser and Zarantonello, “A note on piecewise linear and  multilinear table interpolation in many dimensions.” MATH. COMPUT. 50.181 (1988): 189-196.
• splines.py. This module requires interpolation.py and exposes the following classes:
• Pchip. PCHIP cubic interpolation. See C. Moler, Numerical Computing with Matlab, 2004.
• CubicSpline. Standard cubic spline with various endpoint conditions.
• SchumakerSpline. 1-D piecewise shape-preserving quadratic spline interpolation, following Schumaker (1983): "On Quadratic Spline Interpolation," SIAM J. of Numerical Analysis 20(4), 854-864.
• Again, all classes have been accellerated and parallelized whenever possible with Numba.
• splines.py (14 Kb)
• interpolation.py (14 Kb)

• Last updated June 15, 2018