pyperfectforesight#
A minimal Dynare-style perfect foresight solver in Python. pyperfectforesight lets you define dynamic economic models with Dynare’s familiar lag notation, then solve for the perfect foresight transition path using a sparse Newton BVP solver. It supports stock/jump variable models, homotopy continuation for large shocks, and Dynare’s expectation-errors (multiple surprise MIT shocks) protocol — all from pure Python with NumPy, SciPy, and SymPy.
Features#
Dynare lag notation — write
v("k", -1)for \(k_{t-1}\) andv("c", 1)for \(c_{t+1}\), matching Dynare’s convention exactlyAugmented-path BVP solver — pre-period-0
initial_state(k_{-1}) is pinned; all period-0 variables including jump variables are solved simultaneouslyAutomatic stock-variable inference — lead-lag incidence detects predetermined variables; no manual classification needed
Homotopy continuation —
solve_perfect_foresight_homotopyfor large shocks that defeat direct NewtonExpectation-errors solver — replicates Dynare’s
perfect_foresight_with_expectation_errors_solverfor sequences of surprise shocksAuxiliary variable support — four methods (
auto,analytical,dynamic,nested) to handle static/auxiliary variablesSymbolic processing + automatic differentiation — models defined via SymPy; sparse Jacobians computed automatically