Skip to content

Commit cb96f47

Browse files
committed
Merge branch 'tests' of github.com:jstac/quant-econ into tests
2 parents b5badac + 5da15e6 commit cb96f47

File tree

9 files changed

+499
-151
lines changed

9 files changed

+499
-151
lines changed

examples/evans_sargent_plot1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
tt = np.arange(T) # tt is used to make the plot time index correct.
1313

1414
n_rows = 3
15-
fig, axes = plt.subplots(n_rows, 1, figsize=(10, 16))
15+
fig, axes = plt.subplots(n_rows, 1, figsize=(10, 12))
1616

1717
plt.subplots_adjust(hspace=0.5)
1818
for ax in axes:

examples/evans_sargent_plot2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
tt2 = np.arange(T-1)
1414

1515
n_rows = 4
16-
fig, axes = plt.subplots(n_rows, 1, figsize=(10, 10))
16+
fig, axes = plt.subplots(n_rows, 1, figsize=(10, 16))
1717

1818
plt.subplots_adjust(hspace=0.5)
1919
for ax in axes:

examples/lucas_tree_price1.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22
from __future__ import division # Omit for Python 3.x
33
import numpy as np
44
import matplotlib.pyplot as plt
5-
from quantecon.models import lucas_tree, compute_lt_price
5+
from quantecon.models import LucasTree
66

77
fig, ax = plt.subplots()
8-
#grid = np.linspace(1e-10, 4, 100)
98

10-
tree = lucas_tree(gamma=2, beta=0.95, alpha=0.90, sigma=0.1)
11-
grid, price_vals = compute_lt_price(tree)
9+
tree = LucasTree(gamma=2, beta=0.95, alpha=0.90, sigma=0.1)
10+
grid, price_vals = tree.grid, tree.compute_lt_price()
1211
ax.plot(grid, price_vals, lw=2, alpha=0.7, label=r'$p^*(y)$')
1312
ax.set_xlim(min(grid), max(grid))
1413

15-
#tree = lucas_tree(gamma=3, beta=0.95, alpha=0.90, sigma=0.1)
16-
#grid, price_vals = compute_price(tree)
17-
#ax.plot(grid, price_vals, lw=2, alpha=0.7, label='more patient')
18-
#ax.set_xlim(min(grid), max(grid))
14+
# tree = LucasTree(gamma=3, beta=0.95, alpha=0.90, sigma=0.1)
15+
# grid, price_vals = tree.grid, tree.compute_lt_price()
16+
# ax.plot(grid, price_vals, lw=2, alpha=0.7, label='more patient')
17+
# ax.set_xlim(min(grid), max(grid))
1918

2019
ax.set_xlabel(r'$y$', fontsize=16)
2120
ax.set_ylabel(r'price', fontsize=16)

quantecon/compute_fp.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import numpy as np
1111

1212

13-
def compute_fixed_point(T, v, error_tol=1e-3, max_iter=50, verbose=1):
13+
def compute_fixed_point(T, v, error_tol=1e-3, max_iter=50, verbose=1, *args,
14+
**kwargs):
1415
"""
1516
Computes and returns :math:`T^k v`, an approximate fixed point.
1617
@@ -30,6 +31,9 @@ def compute_fixed_point(T, v, error_tol=1e-3, max_iter=50, verbose=1):
3031
Maximum number of iterations
3132
verbose : bool, optional(default=True)
3233
If True then print current error at each iterate.
34+
args, kwargs :
35+
Other arguments and keyword arguments that are passed directly
36+
to the function T each time it is called
3337
3438
Returns
3539
-------
@@ -40,11 +44,11 @@ def compute_fixed_point(T, v, error_tol=1e-3, max_iter=50, verbose=1):
4044
iterate = 0
4145
error = error_tol + 1
4246
while iterate < max_iter and error > error_tol:
43-
new_v = T(v)
47+
new_v = T(v, *args, **kwargs)
4448
iterate += 1
4549
error = np.max(np.abs(new_v - v))
4650
if verbose:
4751
print("Computed iterate %d with error %f" % (iterate, error))
48-
v = new_v
52+
v[:] = new_v
4953

5054
return v

quantecon/models/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
"""
77

88
__all__ = ["AssetPrices", "CareerWorkerProblem", "ConsumerProblem",
9-
"JvWorker", "lucas_tree", "compute_lt_price", "SearchProblem",
10-
"GrowthModel"]
9+
"JvWorker", "LucasTree", "SearchProblem", "GrowthModel"]
1110

1211
from .asset_pricing import AssetPrices
1312
from .career import CareerWorkerProblem
1413
from .ifp import ConsumerProblem
1514
from .jv import JvWorker
16-
from .lucastree import lucas_tree, compute_lt_price
15+
from .lucastree import LucasTree
1716
from .odu import SearchProblem
1817
from .optgrowth import GrowthModel

0 commit comments

Comments
 (0)