Ejemplo n.º 1
0
def test_production_function_factory_invalid_A():
    "Tests the function `production_function_factory` with invalid input"

    A = 0.
    σ_1, σ_2 = 0.3, 0.3

    with pytest.raises(ValueError) as e_info:
        production_function_factory(A, σ_1, σ_2)
Ejemplo n.º 2
0
def test_production_function_factory():
    "Tests the function `production_function_factory`"

    tol = 1e-8
    A = 1.
    σ_1, σ_2 = 1 / 3, 1 / 3

    F, F_K, F_L, F_M = production_function_factory(A, σ_1, σ_2)

    K = 1 / 3
    L = 2 / 3
    M = 1.

    F_computed = F(K, L, M)
    F_K_computed = F_K(K, L, M)
    F_L_computed = F_L(K, L, M)
    F_M_computed = F_M(K, L, M)

    F_sol = K**σ_1 * L**σ_2 * M**(1 - σ_1 - σ_2)
    F_K_sol = σ_1 * F_sol / K
    F_L_sol = σ_2 * F_sol / L
    F_M_sol = (1 - σ_1 - σ_2) * F_sol / M

    assert abs(F_computed - F_sol) < tol
    assert abs(F_K_computed - F_K_sol) < tol
    assert abs(F_L_computed - F_L_sol) < tol
    assert abs(F_M_computed - F_M_sol) < tol
Ejemplo n.º 3
0
    def __init__(self, A=3., σ_1=0.3, σ_2=0.3):
        # The following also checks that the parameters are valid
        self._F, self._F_K, self._F_L, self._F_M = \
            production_function_factory(A, σ_1, σ_2)

        self._A = A
        self._σ_1 = σ_1
        self._σ_2 = σ_2
def test_solve_dp_vi():
    """
    Tests if the function `solve_dp_vi` successfully converges to an
    approximate fixed point without checking its output.

    """

    # Parameters
    α = 1.
    A = 1.5
    σ_1 = 0.3
    σ_2 = 0.3
    γ = 0.95
    μ = 0.5
    π = 1
    β = 0.9
    ν = 2
    δ_vals = np.array([0.93, 1])
    P_δ = np.array([0.5, 0.5])

    # State Space
    w_min = 1e-8
    w_max = 10.
    w_size = 2**9
    w_vals = np.linspace(w_min, w_max, w_size)

    ζ_vals = np.array([1., 1.5])
    P_ζ = np.array([[0.5, 0.5], [0.5, 0.5]])

    ι_vals = np.array([0., 1.])
    P_ι = np.array([1 - μ, μ])

    b_min = -0.
    b_max = 10.
    b_size = w_size
    b_vals = np.linspace(b_min, b_max, b_size)

    k_tilde_min = b_min
    k_tilde_max = w_max
    k_tilde_size = w_size
    k_tilde_vals = np.linspace(k_tilde_min, k_tilde_max, k_tilde_size)

    u = utility_function_factory(ν)
    F, F_K, F_L, F_M = production_function_factory(A, σ_1, σ_2)

    # Step 1: Guess initial values of K, L, M
    K, L, M = 5, 1, 0.5

    # Step 2: Guess initial value of R
    R = 1.03

    # Step 3: Compute r, w, p_m
    r, wage, p_M = F_K(K, L, M), F_L(K, L, M), F_M(K, L, M)

    # Step 4: Compute j_bar and Γ_star
    j_bar = np.floor(np.log(R / p_M) / np.log(γ))
    js = np.arange(0, j_bar + 1)
    Γ_star = ((γ**js * p_M / R - 1) / R**(-js)).sum()

    states_vals = w_vals, ζ_vals, ι_vals, k_tilde_vals

    uc = create_uc_grid(u, states_vals, wage)
    next_w, next_w_star = create_next_w(r, δ_vals, k_tilde_vals, b_vals, R,
                                        Γ_star)

    V1_star, V1_store, V2_star, V2_store, b_av, k_tilde_av, π_star = \
        initialize_values_and_policies(states_vals, b_vals)

    P = create_P(P_δ, P_ζ, P_ι)

    method = 0
    method_args = \
        (P, uc, b_vals, k_tilde_av, b_av, next_w_star, next_w)

    results = solve_dp_vi(V1_star,
                          V1_store,
                          V2_star,
                          V2_store,
                          states_vals,
                          δ_vals,
                          π,
                          β,
                          method,
                          method_args,
                          tol=1e-7)

    assert results.success == 1
Ejemplo n.º 5
0
 def σ_2(self, value):
     # Update production functions and check that the parameters are valid
     self._F, self._F_K, self._F_L, self._F_M = \
         production_function_factory(self.A, self.σ_1, value)
     self._σ_1 = value
Ejemplo n.º 6
0
 def A(self, value):
     # Update production functions and check that the parameters are valid
     self._F, self._F_K, self._F_L, self._F_M = \
         production_function_factory(value, self.σ_1, self.σ_2)
     self._A = A