示例#1
0
    beta, c, f, g, q = sp.beta, sp.c, sp.f, sp.g, sp.q  # Simplify names
    phi_f = lambda p: interp(p, sp.pi_grid, phi)  # Turn phi into a function
    new_phi = np.empty(len(phi))
    for i, pi in enumerate(sp.pi_grid):

        def integrand(x):
            "Integral expression on right-hand side of operator"
            return npmax(x, phi_f(q(x, pi))) * (pi * f(x) + (1 - pi) * g(x))

        integral, error = fixed_quad(integrand, 0, sp.w_max)
        new_phi[i] = (1 - beta) * c + beta * integral
    return new_phi


if __name__ == '__main__':  # If module is run rather than imported

    sp = searchProblem(pi_grid_size=50)
    phi_init = np.ones(len(sp.pi_grid))
    w_bar = compute_fixed_point(res_wage_operator, sp, phi_init)

    fig, ax = plt.subplots()
    ax.plot(sp.pi_grid, w_bar, linewidth=2, color='black')
    ax.set_ylim(0, 2)
    ax.grid(axis='x', linewidth=0.25, linestyle='--', color='0.25')
    ax.grid(axis='y', linewidth=0.25, linestyle='--', color='0.25')
    ax.fill_between(sp.pi_grid, 0, w_bar, color='blue', alpha=0.15)
    ax.fill_between(sp.pi_grid, w_bar, 2, color='green', alpha=0.15)
    ax.text(0.42, 1.2, 'reject')
    ax.text(0.7, 1.8, 'accept')
    plt.show()
"""
Origin: QE by John Stachurski and Thomas J. Sargent
Filename: odu_plot_densities.py
Authors: John Stachurski, Thomas J. Sargent
LastModified: 11/08/2013

"""
import numpy as np
import matplotlib.pyplot as plt
from odu_vfi import searchProblem

sp = searchProblem(F_a=1, F_b=1, G_a=3, G_b=1.2)
grid = np.linspace(0, 2, 150)
fig, ax = plt.subplots()
ax.plot(grid, sp.f(grid), label=r'$f$', lw=2)
ax.plot(grid, sp.g(grid), label=r'$g$', lw=2)
ax.legend(loc=0)
plt.show()
from scipy import interp
import numpy as np
import matplotlib.pyplot as plt
from odu_vfi import searchProblem
from solution_odu_ex1 import res_wage_operator
from compute_fp import compute_fixed_point

# Set up model and compute the function w_bar
sp = searchProblem(pi_grid_size=50, F_a=1, F_b=1)
pi_grid, f, g, F, G = sp.pi_grid, sp.f, sp.g, sp.F, sp.G
phi_init = np.ones(len(sp.pi_grid)) 
w_bar_vals = compute_fixed_point(res_wage_operator, sp, phi_init)
w_bar = lambda x: interp(x, pi_grid, w_bar_vals)


class Agent:
    """
    Holds the employment state and beliefs of an individual agent.
    """

    def __init__(self, pi=1e-3):
        self.pi = pi
        self.employed = 1

    def update(self, H):
        "Update self by drawing wage offer from distribution H."
        if self.employed == 0:
            w = H.rvs()
            if w >= w_bar(self.pi):
                self.employed = 1
            else:
示例#4
0
    """
    beta, c, f, g, q = sp.beta, sp.c, sp.f, sp.g, sp.q    # Simplify names
    phi_f = lambda p: interp(p, sp.pi_grid, phi)  # Turn phi into a function
    new_phi = np.empty(len(phi))
    for i, pi in enumerate(sp.pi_grid):
        def integrand(x):
            "Integral expression on right-hand side of operator"
            return npmax(x, phi_f(q(x, pi))) * (pi * f(x) + (1 - pi) * g(x))
        integral, error = fixed_quad(integrand, 0, sp.w_max)
        new_phi[i] = (1 - beta) * c + beta * integral
    return new_phi


if __name__ == '__main__':  # If module is run rather than imported

    sp = searchProblem(pi_grid_size=50)
    phi_init = np.ones(len(sp.pi_grid)) 
    w_bar = compute_fixed_point(res_wage_operator, sp, phi_init)

    fig, ax = plt.subplots()
    ax.plot(sp.pi_grid, w_bar, linewidth=2, color='black')
    ax.set_ylim(0, 2)
    ax.grid(axis='x', linewidth=0.25, linestyle='--', color='0.25')
    ax.grid(axis='y', linewidth=0.25, linestyle='--', color='0.25')
    ax.fill_between(sp.pi_grid, 0, w_bar, color='blue', alpha=0.15)
    ax.fill_between(sp.pi_grid, w_bar, 2, color='green', alpha=0.15)
    ax.text(0.42, 1.2, 'reject')
    ax.text(0.7, 1.8, 'accept')
    plt.show()