Skip to content

Commit f0c56c2

Browse files
committed
fix formatting
2 parents af7235b + b4ce647 commit f0c56c2

File tree

17 files changed

+113
-112
lines changed

17 files changed

+113
-112
lines changed

docs/guide/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ Installing the `repository version <https://pypi.org/project/econpizza/>`_ from
1111
1212
in your terminal or Anaconda Prompt.
1313

14-
The current version is supporting Python versions 3.9 to 3.11 on Windows, Mac and Linux.
14+
The current version is supporting the latest three minor Python versions on Windows, Mac and Linux.
1515
The `changelog and release history <https://github.com/gboehl/econpizza/releases>`_ can be found on GitHub.

docs/tutorial/boehl_hommes.rst

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
Boehl-Hommes method
33
-------------------
44

5-
The package also contains an alternative "shooting" method much aligned to the one introduced in Boehl & Hommes (2021). In the original paper we use this method to solve for chaotic asset price dynamics. The method can be understood as a policy function iteration where the initial state is the only fixed grid point and all other grid points are chosen endogenously (as in a "reverse" EGM) to map the expected trajectory.
5+
The package also contains an alternative "shooting" method much aligned to the one introduced in Boehl & Hommes (2021). In the original paper we use this method to solve for chaotic asset price dynamics. The method can be understood as an extension to Fair & Taylor (1983) and is similar to a policy function iteration where the initial state is the only fixed grid point and all other grid points are chosen endogenously (as in a "reverse" EGM) to map the expected trajectory.
66

7-
The main advantage (in terms of robustness) over the stacking method comes from exploiting the property that most determined perfect foresight models are a contraction mapping both, forward and backwards. The model is given by
7+
Assume the model is given by
88

99
.. code-block::
1010
@@ -17,39 +17,9 @@ We iterate on the expected trajectory itself instead of the policy function. We
1717
d f(x_{t-1}, x_t, x_{t+1} ) < d x_{t-1},
1818
d f(x_{t-1}, x_t, x_{t+1} ) < d x_{t+1}.
1919
20-
This is also the weakness of the method: not every DSGE model (that is determined in the Blanchard-Kahn sense) is such backward-and-forward contraction. In most cases the algorithm converges anyways, but convergence is not guaranteed.
20+
This is also the weakness of the method: not every DSGE model (that is determined in the Blanchard-Kahn sense) is such backward-and-forward contraction. Thus, unless you are interested in chaotic dynamics, the standard "stacking" method is to be prefered.
2121

22-
The following example shows how to use the shooting method on the simple New Keynesian model.
23-
24-
.. code-block:: python
25-
26-
import numpy as np
27-
import matplotlib.pyplot as plt
28-
import econpizza as ep
29-
from econpizza import example_nk
30-
31-
# load the example.
32-
# example_nk is nothing else but the path to the yaml, hence you could also use `filename = 'path_to/model.yaml'`
33-
mod = ep.load(example_nk)
34-
# solve for the steady state
35-
_ = mod.solve_stst()
36-
37-
# get the steady state as an initial state
38-
state = mod['stst'].copy()
39-
# increase the discount factor by one percent
40-
state['beta'] *= 1.02
41-
42-
# simulate the model
43-
x, _, flag = mod.find_path_shooting(state.values())
44-
45-
# plotting
46-
for i,v in enumerate(mod.var_names):
47-
48-
plt.figure()
49-
plt.plot(x[:,i])
50-
plt.title(v)
51-
52-
Lets go for a second, numerically more challenging example: the chaotic rational expectations model of Boehl & Hommes (2021)
22+
The following example shows how to use the shooting method to a numerically challenging example: the chaotic rational expectations model of Boehl & Hommes (2021). The YAML for this model can be found `here <https://github.com/gboehl/econpizza/blob/master/econpizza/examples/bh.yml>`_.
5323

5424
.. code-block:: python
5525
@@ -81,3 +51,8 @@ This will give you boom-bust cycles in asset pricing dynamics:
8151
.. image:: https://github.com/gboehl/econpizza/blob/master/docs/p_and_n.png?raw=true
8252
:width: 800
8353
:alt: Dynamics of prices and fractions
54+
55+
Below, find the documentation for the additional function:
56+
57+
.. autofunction:: econpizza.PizzaModel.find_path_shooting
58+

docs/tutorial/hank1.ipynb

Lines changed: 29 additions & 29 deletions
Large diffs are not rendered by default.

docs/tutorial/hank2.ipynb

Lines changed: 22 additions & 15 deletions
Large diffs are not rendered by default.

econpizza/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
__version__ = '0.6.5'
3+
__version__ = '0.6.6'

econpizza/examples/dsge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ steady_state:
7676
rho: 0.8 # persistence in (notional) nominal interest rate
7777
omega_p: 0.44 # coefficient on steady state inflation in price indexation
7878
omega_w: 0.66 # coefficient on steady state wage inflation in wage indexation
79-
iota_w: 1 # degree of dowards nominal wage rigidity
79+
iota_w: 0 # degree of dowards nominal wage rigidity
8080
elb: 1 # position of ELB
8181
rho_beta: 0.9 # persistence of discount factor shock
8282
rho_z: 0.9 # persistence of technology shocks

econpizza/parser/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ def load(
348348
if model.get('decisions'):
349349
decisions_outputs = model['decisions']['outputs']
350350
decisions_inputs = model['decisions']['inputs']
351+
check_for_lags(model['decisions']['calls'], evars)
351352
model['func_strings']["func_backw"] = compile_backw_func_str(
352353
evars, par_names, shocks, decisions_inputs, decisions_outputs, model['decisions']['calls'])
353354
_define_function(model['func_strings']

econpizza/parser/build_generic_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def get_stacked_func_het_agents(func_backw, func_forw, func_eqns, stst, wfSS, ho
170170

171171
# build partials of output functions
172172
backwards_sweep_local = jax.tree_util.Partial(
173-
backwards_sweep, stst=stst, wfSS=wfSS, horizon=horizon, func_backw=partial_backw)
173+
backwards_sweep, stst=stst, wfSS=wfSS, func_backw=partial_backw)
174174
forwards_sweep_local = jax.tree_util.Partial(
175175
forwards_sweep, horizon=horizon, func_forw=partial_forw)
176176
final_step_local = jax.tree_util.Partial(

econpizza/parser/checks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,10 @@ def check_if_compiled(model, horizon, pars, stst):
129129
return jnp.allclose(model['cache']['pars'], pars)
130130
except:
131131
return False
132+
133+
134+
def check_for_lags(calls, evars):
135+
for v in evars:
136+
if v+'Lag' in calls:
137+
raise Exception(
138+
f"`{v}Lag` in decisions calls detected. For efficiency reasons, the use of lagged values is not supported here. This can be circumvented by defining an auxilliary variable, e.g. `{v}_lagged = {v}Lag`.")

econpizza/parser/het_agent_base_funcs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ def _backwards_step(carry, i):
3434
return (wf, X, shocks, func_backw, stst, pars), (wf, decisions_output)
3535

3636

37-
def backwards_sweep(x: Array, x0: Array, shocks: Array, pars: Array, stst: Array, wfSS: Array, horizon: int, func_backw: Callable, return_wf=False) -> Array:
37+
def backwards_sweep(x: Array, x0: Array, shocks: Array, pars: Array, stst: Array, wfSS: Array, func_backw: Callable, return_wf=False) -> Array:
3838

39+
# get horizon from input size
40+
horizon = len(x)//len(stst) + 1
3941
X = jnp.hstack((x0, x, stst)).reshape(horizon+1, -1).T
4042

4143
_, (wf_storage, decisions_output_storage) = jax.lax.scan(

0 commit comments

Comments
 (0)