Time Iteration¶
Time iteration is the core nonlinear policy-iteration algorithm in Dolo for solving dynamic stochastic general equilibrium (DSGE) models, optionally subject to occasionally binding inequality constraints.
1. Mathematical Formulation¶
Classical Structural Form¶
In its classical structural formulation, a discrete-time continuous-state economic model is represented by:
where: - \(m_t\) is the vector of exogenous shocks, - \(s_t\) is the vector of endogenous states, - \(x_t\) is the vector of controls (decisions), - \(g\) is the state transition law, - \(f\) is the arbitrage equation (Euler residuals), - \(\underline{x}, \overline{x}\) are lower and upper bounds on controls, with the complementarity condition \(\perp\).
The Unified \(\tau\) Transition Operator¶
Following the design of Dolo.jl, dolo.py generalizes this formulation by abstracting the state transition and stochastic process into a unified transition kernel \(\tau\).
Instead of treating exogenous Markov chains, VAR(1) processes, and i.i.d. quadrature shocks through disparate control flows, the next state distribution is written universally as:
where a state \(S\) is represented as a QualifiedPoint (or QP) bundling:
1. loc (Locator / Address): The discrete regime index or computational address in the discretized domain (e.g. regime index \(i_m\) for Markov chains, or coordinate indices for table lookups).
2. val (Evaluated Payload): The continuous economic state coordinates \([m, s]\) passed into equations.
Given a policy rule \(x = \varphi(S)\), the conditional transition \(\tau(S_t, x_t)\) yields a set of discrete branches with weights and target qualified states:
The arbitrage equation is formulated universally as:
This abstraction ensures that the Euler residuals and solution algorithms are identical whether the model features pure continuous states, discrete Markov regimes, or mixed exogenous processes.
2. Discrete Model & Core Abstractions¶
DiscretizedModel¶
A DiscretizedModel bundles the continuous model specification, the computational grid \(\mathcal{G}\), and the discrete transition operator \(\tau\):
from dolo import yaml_import
from dolo.numeric import DiscretizedModel
model = yaml_import("examples/models/rbc.yaml")
dmodel = DiscretizedModel(model)
It provides:
- dmodel.initial_guess(): Returns a GArray initialized from steady-state calibration.
- dmodel.lower_bounds(), dmodel.upper_bounds(): Returns GArray bounds.
- dmodel.arbitrage(...): Evaluates arbitrage equations across regimes and batches.
- dmodel.transition_matrix(dr): Computes the full row-stochastic Markov transition matrix \(P\) on grid nodes.
- dmodel.ergodic_distribution(dr): Computes the stationary distribution \(\mu P = \mu\).
GArray (Grid-Bound Fields)¶
A GArray represents a discrete field of values living on a grid \(\mathcal{G}\). It exhibits a powerful duality:
- Geometric Indexing: Slice by discrete regime or subgrid, e.g., controls[i_m].
- Vectorized Solver Interface: Directly provides ravel() (flat 1D view for SciPy/Newton solvers) and unravel(flat_x) to reconstruct structured fields without manual tensor reshaping.
- Linear Algebra: Implements vectorized addition, scaling, and \(L_\infty\) distance norm (ga.norm()).
3. The Time Iteration Algorithm¶
The algorithm proceeds as follows:
- Initial Guess: Start with an initial policy field \(x^{(0)} = \varphi^{(0)} \in \mathcal{G}\) (typically the calibrated steady-state controls).
- Policy Update (Euler Equation Solve): Given future policy \(\varphi^{(n)}\), solve for current period controls \(\varphi^{(n+1)}(S)\) at each grid node \(S \in \mathcal{G}\): $\(0 = \sum_{(w_k, S'_k) \in \tau(S, x)} w_k \cdot f\left(S, x, S'_k, \varphi^{(n)}(S'_k)\right) \quad \perp \quad \underline{x}(S) \le x \le \overline{x}(S)\)$ This step uses a vectorized serial Newton-Raphson or Non-Linear Complementarity Problem (NCP) solver.
- Policy Acceleration (Optional Multi-Step Lookahead): To accelerate convergence, an intermediate policy evaluation step can be applied using Neumann series or GMRES linear solves (similar to Howard improvement in value iteration): $\(\varphi^{(n+1)} \leftarrow \varphi^{(n+1)} + (I - J_x)^{-1} \cdot R\big(\varphi^{(n+1)}\big)\)$
- Convergence Check: Compute the residual norm \(\epsilon_{n+1} = \|R(\varphi^{(n+1)})\|_\infty\) and the policy step error \(\eta_{n+1} = \|\varphi^{(n+1)} - \varphi^{(n)}\|_\infty\):
- If \(\epsilon_{n+1} < \tau_\epsilon\) and \(\eta_{n+1} < \tau_\eta\), terminate and return the converged decision rule \(\varphi^*\).
- Otherwise, update \(\varphi^{(n)} \leftarrow \varphi^{(n+1)}\) and return to Step 2.
4. Usage & Options¶
Basic Usage¶
from dolo import yaml_import, time_iteration
# Load model
model = yaml_import("examples/models/rbc.yaml")
# Solve using time iteration
sol = time_iteration(model)
# Access decision rule
dr = sol.dr
print("Converged:", sol.converged)
print("Iterations:", sol.iterations)
Accelerated Time Iteration¶
For models with high persistence or slow policy adjustment, acceleration drastically reduces the number of outer iterations:
# Enable Neumann policy acceleration
sol = time_iteration(model, accelerate=True)
# Custom acceleration configuration
sol = time_iteration(
model,
accelerate={
"linsolve": "neumann", # or "gmres"
"maxit": 50,
"wait": 5, # wait 5 iterations before starting acceleration
"tol": 1e-8,
}
)
5. API Reference¶
Finds a global solution for model using backward time-iteration.
Parameters¶
model : Model, ModelV2, or DiscretizedModel model to be solved engine / backend : str ("auto", "jax", "gpu", "cpu", "vectorized") computational engine for residual and Jacobian evaluations dr0 : DecisionRule, optional initial guess for the decision rule tol_eps : float (1e-8) tolerance on Euler equation residuals ||F(x)|| tol_eta : float (1e-6) tolerance on policy update step ||x_{k+1} - x_k|| maxit : int (500) maximum number of outer time-iteration loops inner : dict, optional options for the inner pointwise Euler solver: dict(maxit=10, max_backsteps=10, tol=1e-8) accelerate : bool or dict (False) if True or a dict, accelerates policy iterations using a preconditioned Neumann or GMRES step on (I - L) dx = (x_1 - x_0) after a warm-up phase. e.g. dict(wait=10, linsolve="neumann", maxit=50, safeguarded=False) interpolation : str ("cubic") interpolation method ("cubic" or "linear") verbose : bool (True) display iteration progress trace : bool (False) record intermediate decision rules
Source code in src/dolo/algos/time_iteration.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
Bases: AlgoResult