예제 #1
0
 def TC_star(v_init, tol):
     rho = v_init[0]
     sigma = v_init[1]
     rho_updated = fixed_point(lambda v: T(v, sigma),
                               rho,
                               error_flag=1,
                               tol=tol,
                               error_name="pricing")
     sigma_updated = fixed_point(lambda v: C(rho_updated, v),
                                 sigma,
                                 error_flag=1,
                                 tol=tol,
                                 error_name="Coleman-Reffett")
     return np.array([rho_updated, sigma_updated])
    def TC_star(v_init, K, S_bar, tol, grid):
        """"
        Fixed point operator. For initial guess of time operator, returns its fixed point

        Parameters
        ----------
        v_init :    2D numpy array
                     initial pricing function (rows index shock index and column index grid index)
        K:      float
                 generation capital 
        S_bar:  float
                 storage capital    
        grid:   numpy array
                 storage grid with S_bar as max value

        Returns
        -------
        rho_new: float 
                  fixed point of price function 
        """

        rho = v_init
        rho_updated = fixed_point(lambda v: T(v, K, S_bar, config.grid),
                                  rho,
                                  error_flag=0,
                                  tol=tol,
                                  error_name="pricing")

        return rho_updated
예제 #3
0
"""

if __name__ == '__main__':

    og = EmarketModel(s_supply=.1,
                      grid_size=350,
                      grid_max_x=300,
                      S_bar_flag=0,
                      p=pr,
                      p_inv=p_inv,
                      phi=phi,
                      phi_prime=phi_prime,
                      demand_shocks=[1, 1.5],
                      demand_P=[1, 0])

    TC_star = time_operator_factory(og)

    # n = 15
    sigma = np.ones(og.grid.shape)  # Set initial condition
    rho = np.ones(og.grid.shape)
    v_init = np.array([rho, sigma])

    og.sol_func = fixed_point(lambda v: TC_star(v, tol=1e-5),
                              v_init,
                              error_flag=1,
                              tol=1e-5,
                              error_name="main",
                              maxiter=20)

    pickle.dump(og, open("/home/akshay_shanker/model_0.mod", "wb"))
    og.S_bar_star = S_bar_star
    og.solved_flag = 1
    og.grid = config.grid
    end = time.time()
    og.time_exog = end - start

    pickle.dump(og, open("/scratch/kq62/array_6a_{}.mod".format(index), "wb"))
    """
    Run model with endogenous stock of capital. 
    """

    config.toggle_GF = 0
    start = time.time()
    K_star = fixed_point(
        lambda K: GF_star(K, tol_TC, tol_brent_1, tol_brent, tol_pi),
        v_init=K_init,
        error_flag=1,
        tol=tol_K,
        error_name="pricing")

    #K_star = 5.700222761535536
    #S_bar_star = 6.534672003614626

    rho_star = TC_star(config.rho_global_old, K_star, config.S_bar_star,
                       tol_TC, config.grid)

    og.K = K_star
    og.rho_star = rho_star
    og.S_bar_star = config.S_bar_star
    og.solved_flag = 1
    og.grid = config.grid
    end = time.time()