def EulerSys_b(b, *objs):
    '''
    Generates vector of all Euler errors for a given b, which errors
    characterize all optimal lifetime savings decisions

    Inputs:
        b     = [S-1,] vector, lifetime savings decisions
        objs     = length 9 tuple,
                   (alpha, beta, sigma, r, w, p, p, c_bar, n)
        alpha    = [I,] vector, expenditure shares on each good
        beta     = scalar in [0,1), discount factor for each model
                   period
        sigma    = scalar > 0, coefficient of relative risk aversion
        r        = scalar > 0, interest rate
        w        = scalar > 0, real wage
        p_tilde        = scalar > 0, composite good price
        p_c    = [I,] vector, price for each consumption good
        c_bar = [I,] vector, minimum consumption values for all goods
        n     = [S,] vector, exogenous labor supply n_{s}

    Functions called:
        firm.get_c_tilde
        firm.get_c
        firm.get_b_errors

    Objects in function:
        c_params     = length 3 tuple, parameters for get_c (r, w, p)
        c_tilde         = [S,] vector, remaining lifetime consumption
                       levels implied by b
        c_tilde_cstr       = [S, ] boolean vector, =True if c_{s,t}<=0
        c_params    = length 2 tuple, parameters for get_c
                       (alpha, p)
        c        = [I,S] matrix, consumption values for each good
                       and age c_{i,s}
        c_cstr      = [I,S] boolean matrix, =True if c_{i,s}<=0
        b_err_params = length 2 tuple, parameters to pass into
                       get_b_errors (beta, sigma)
        b_err_vec    = [S-1,] vector, Euler errors from lifetime
                       consumption vector

    Returns: b_err_vec
    '''
    alpha, beta, sigma, r, w, p_tilde, p_c, c_bar, I, S, n = objs

    c_tilde, c_tilde_cstr = firm.get_c_tilde(c_bar, r, w, p_c, p_tilde, n,
                                             np.append([0], b))
    c, c_cstr = firm.get_c(np.tile(np.reshape(alpha, (I, 1)), (1, S)),
                           np.tile(np.reshape(c_bar, (I, 1)), (1, S)),
                           np.tile(c_tilde, (I, 1)),
                           np.tile(np.reshape(p_c, (I, 1)), (1, S)), p_tilde)
    b_err_params = (beta, sigma)
    b_err_vec = firm.get_b_errors(b_err_params,
                                  r,
                                  c_tilde,
                                  c_tilde_cstr,
                                  diff=True)
    return b_err_vec
Beispiel #2
0
def get_cbess(params, b_guess, p_c, c_bar, I, S, n):
    '''
    Generates vectors for individual savings, composite consumption,
    industry-specific consumption, constraint vectors, and Euler errors
    for a given set of prices (r, w, p, p).

    Inputs:
        params   = length 7 tuple, (alpha, beta, sigma, r, w, p ss_tol)
        alpha    = [I,] vector, expenditure shares on each good
        beta     = scalar in [0,1), discount factor for each model
                   period
        sigma    = scalar > 0, coefficient of relative risk aversion
        r        = scalar > 0, interest rate
        w        = scalar > 0, real wage
        p_tilde        = scalar > 0, composite good price
        ss_tol   = scalar > 0, tolerance level for steady-state fsolve
        b_guess  = [S-1,] vector, initial guess for savings vector
        p_c    = [I,] vector, prices in each industry
        c_bar = [I,] vector, minimum consumption values for all goods
        n     = [S,] vector, exogenous labor supply n_{s}

    Functions called:
        EulerSys_b
        firm.get_c_tilde
        firm.get_c
        firm.get_b_errors

    Objects in function:
        eulb_objs  = length 9 tuple, objects to be passed in to
                     EulerSys_b: (alpha, beta, sigma, r, w, p, p,
                     c_bar, n)
        b       = [S-1,] vector, optimal lifetime savings decisions
        c_tidle_params   = length 3 tuple, parameters for get_c_tilde(r, w, p_tilde)
        c_tilde       = [S,] vector, optimal lifetime consumption
        c_tilde_cstr     = [S,] boolean vector, =True if c_s<=0
        c_params  = length 2 tuple, parameters for get_c (alpha, p)
        c        = [I,S] matrix,  optimal consumption of each good
                     given prices
        c_cstr    = [I,S] boolean matrix, =True if c_{i,s}<=0 for given
                     c_s
        eul_params = length 2 tuple, parameters for get_b_errors
                     (beta, sigma)
        euler_errors     = [S-1,] vector, Euler errors from savings decisions

    Returns: b, c, c_cstr, c, c_cstr, euler_errors
    '''
    alpha, beta, sigma, r, w, p_tilde, ss_tol = params
    eulb_objs = (alpha, beta, sigma, r, w, p_tilde, p_c, c_bar, I, S, n)
    b = opt.fsolve(EulerSys_b, b_guess, args=(eulb_objs), xtol=ss_tol)
    c_tilde, c_tilde_cstr = firm.get_c_tilde(c_bar, r, w, p_c, p_tilde, n, np.append([0], b))
    c_params = (alpha, p_tilde)
    c, c_cstr = firm.get_c(np.tile(np.reshape(alpha,(I,1)),(1,S)), np.tile(np.reshape(c_bar,(I,1)),(1,S)), 
                           np.tile(c_tilde,(I,1)), np.tile(np.reshape(p_c,(I,1)),(1,S)) , p_tilde)
    eul_params = (beta, sigma)
    euler_errors = firm.get_b_errors(eul_params, r, c_tilde, c_tilde_cstr, diff=True)

    return b, c, c_cstr, c, c_cstr, euler_errors
Beispiel #3
0
def LfEulerSys(b, *objs):
    '''
    Generates vector of all Euler errors for a given b, which errors
    characterize all optimal lifetime decisions

    Inputs:
        b       = [u-1,] vector, remaining lifetime savings decisions
                     where p is the number of remaining periods
        objs       = length 9 tuple, (u, beta, sigma, beg_wealth, n,
                     r_path, w_path, p_path, p_tilde_path)
        u          = integer in [2,S], remaining periods in life
        beta       = scalar in [0,1), discount factor
        sigma      = scalar > 0, coefficient of relative risk aversion
        beg_wealth = scalar, wealth at the beginning of first age
        n       = [u,] vector, remaining exogenous labor supply
        r_path      = [u,] vector, interest rates over remaining life
        w_path      = [u,] vector, wages rates over remaining life
        p_c_path     = [I, u] matrix, remaining lifetime
                     consumption good prices
        p_tilde_path      = [u,] vector, remaining lifetime composite
                     goods prices
        p_tilde_path      = [u,] vector of composite good prices

    Functions called:
        firm.get_c_tilde
        firm.get_b_errors

    Objects in function:
        b2        = [u, ] vector, remaining savings including initial
                       savings
        c         = [u, ] vector, remaining lifetime consumption
                       levels implied by b2
        c_constr     = [u, ] boolean vector, =True if c_{s,t}<=0
        b_err_params = length 2 tuple, parameters to pass into
                       get_b_errors (beta, sigma)
        b_err_vec    = [u-1,] vector, Euler errors from lifetime
                       consumption vector

    Returns: b_err_vec
    '''
    (u, beta, sigma, beg_wealth, c_bar, n, r_path, w_path, p_c_path,
     p_tilde_path) = objs
    b2 = np.append(beg_wealth, b)
    c_tilde, c_tilde_cstr = firm.get_c_tilde(c_bar, r_path, w_path, p_c_path,
                                             p_tilde_path, n, b2)
    b_err_params = (beta, sigma)
    b_err_vec = firm.get_b_errors(b_err_params,
                                  r_path[1:],
                                  c_tilde,
                                  c_tilde_cstr,
                                  diff=True)
    return b_err_vec
Beispiel #4
0
def EulerSys_b(b, *objs):
    '''
    Generates vector of all Euler errors for a given b, which errors
    characterize all optimal lifetime savings decisions

    Inputs:
        b     = [S-1,] vector, lifetime savings decisions
        objs     = length 9 tuple,
                   (alpha, beta, sigma, r, w, p, p, c_bar, n)
        alpha    = [I,] vector, expenditure shares on each good
        beta     = scalar in [0,1), discount factor for each model
                   period
        sigma    = scalar > 0, coefficient of relative risk aversion
        r        = scalar > 0, interest rate
        w        = scalar > 0, real wage
        p_tilde        = scalar > 0, composite good price
        p_c    = [I,] vector, price for each consumption good
        c_bar = [I,] vector, minimum consumption values for all goods
        n     = [S,] vector, exogenous labor supply n_{s}

    Functions called:
        firm.get_c_tilde
        firm.get_c
        firm.get_b_errors

    Objects in function:
        c_params     = length 3 tuple, parameters for get_c (r, w, p)
        c_tilde         = [S,] vector, remaining lifetime consumption
                       levels implied by b
        c_tilde_cstr       = [S, ] boolean vector, =True if c_{s,t}<=0
        c_params    = length 2 tuple, parameters for get_c
                       (alpha, p)
        c        = [I,S] matrix, consumption values for each good
                       and age c_{i,s}
        c_cstr      = [I,S] boolean matrix, =True if c_{i,s}<=0
        b_err_params = length 2 tuple, parameters to pass into
                       get_b_errors (beta, sigma)
        b_err_vec    = [S-1,] vector, Euler errors from lifetime
                       consumption vector

    Returns: b_err_vec
    '''
    alpha, beta, sigma, r, w, p_tilde, p_c, c_bar, I, S, n = objs

    c_tilde, c_tilde_cstr = firm.get_c_tilde(c_bar, r, w, p_c, p_tilde, n, np.append([0], b))
    c, c_cstr = firm.get_c(np.tile(np.reshape(alpha,(I,1)),(1,S)), np.tile(np.reshape(c_bar,(I,1)),(1,S)), 
                           np.tile(c_tilde,(I,1)), np.tile(np.reshape(p_c,(I,1)),(1,S)) , p_tilde)
    b_err_params = (beta, sigma)
    b_err_vec = firm.get_b_errors(b_err_params, r, c_tilde, c_tilde_cstr, diff=True)
    return b_err_vec
Beispiel #5
0
def LfEulerSys(b, *objs):
    '''
    Generates vector of all Euler errors for a given b, which errors
    characterize all optimal lifetime decisions

    Inputs:
        b       = [u-1,] vector, remaining lifetime savings decisions
                     where p is the number of remaining periods
        objs       = length 9 tuple, (u, beta, sigma, beg_wealth, n,
                     r_path, w_path, p_path, p_tilde_path)
        u          = integer in [2,S], remaining periods in life
        beta       = scalar in [0,1), discount factor
        sigma      = scalar > 0, coefficient of relative risk aversion
        beg_wealth = scalar, wealth at the beginning of first age
        n       = [u,] vector, remaining exogenous labor supply
        r_path      = [u,] vector, interest rates over remaining life
        w_path      = [u,] vector, wages rates over remaining life
        p_c_path     = [I, u] matrix, remaining lifetime
                     consumption good prices
        p_tilde_path      = [u,] vector, remaining lifetime composite
                     goods prices
        p_tilde_path      = [u,] vector of composite good prices

    Functions called:
        firm.get_c_tilde
        firm.get_b_errors

    Objects in function:
        b2        = [u, ] vector, remaining savings including initial
                       savings
        c         = [u, ] vector, remaining lifetime consumption
                       levels implied by b2
        c_constr     = [u, ] boolean vector, =True if c_{s,t}<=0
        b_err_params = length 2 tuple, parameters to pass into
                       get_b_errors (beta, sigma)
        b_err_vec    = [u-1,] vector, Euler errors from lifetime
                       consumption vector

    Returns: b_err_vec
    '''
    (u, beta, sigma, beg_wealth, c_bar, n, r_path, w_path, p_c_path,
        p_tilde_path) = objs
    b2 = np.append(beg_wealth, b)
    c_tilde, c_tilde_cstr = firm.get_c_tilde(c_bar, r_path, w_path, p_c_path, p_tilde_path,
                               n, b2)
    b_err_params = (beta, sigma)
    b_err_vec = firm.get_b_errors(b_err_params, r_path[1:], c_tilde,
                                   c_tilde_cstr, diff=True)
    return b_err_vec
Beispiel #6
0
def paths_life(params, beg_age, beg_wealth, c_bar, n, r_path,
               w_path, p_c_path, p_tilde_path, b_init):
    '''
    Solve for the remaining lifetime savings decisions of an individual
    who enters the model at age beg_age, with corresponding initial
    wealth beg_wealth.

    Inputs:
        params     = length 5 tuple, (S, alpha, beta, sigma, tp_tol)
        S          = integer in [3,80], number of periods an individual
                     lives
        alpha      = [I,S-beg_age+1], expenditure share on good for remaing lifetime
        beta       = scalar in [0,1), discount factor for each model
                     period
        sigma      = scalar > 0, coefficient of relative risk aversion
        tp_tol    = scalar > 0, tolerance level for fsolve's in TPI
        beg_age    = integer in [1,S-1], beginning age of remaining life
        beg_wealth = scalar, beginning wealth at beginning age
        n       = [S-beg_age+1,] vector, remaining exogenous labor
                     supplies
        r_path      = [S-beg_age+1,] vector, remaining lifetime interest
                     rates
        w_path      = [S-beg_age+1,] vector, remaining lifetime wages
        p_c_path     = [I, S-beg_age+1] matrix, remaining lifetime
                     consumption good prices
        p_tilde_path      = [S-beg_age+1,] vector, remaining lifetime composite
                     goods prices
        b_init     = [S-beg_age,] vector, initial guess for remaining
                     lifetime savings

    Functions called:
        LfEulerSys
        firm.get_c_tilde
        firm.get_c
        firm.get_b_errors

    Objects in function:
        u            = integer in [2,S], remaining periods in life
        b_guess      = [u-1,] vector, initial guess for lifetime savings
                       decisions
        eullf_objs   = length 9 tuple, objects to be passed in to
                       LfEulerSys: (p, beta, sigma, beg_wealth, n,
                       r_path, w_path, p_path, p_tilde_path)
        b_path        = [u-1,] vector, optimal remaining lifetime savings
                       decisions
        c_tilde_path        = [u,] vector, optimal remaining lifetime
                       consumption decisions
        c_path       = [u,I] martrix, remaining lifetime consumption
                        decisions by consumption good
        c_constr     = [u,] boolean vector, =True if c_{u}<=0,
        b_err_params = length 2 tuple, parameters to pass into
                       firm.get_b_errors (beta, sigma)
        b_err_vec    = [u-1,] vector, Euler errors associated with
                       optimal savings decisions

    Returns: b_path, c_tilde_path, c_path, b_err_vec
    '''
    S, alpha, beta, sigma, tp_tol = params
    u = int(S - beg_age + 1)
    if beg_age == 1 and beg_wealth != 0:
        sys.exit("Beginning wealth is nonzero for age s=1.")
    if len(r_path) != u:
        #print len(r_path), S-beg_age+1
        sys.exit("Beginning age and length of r_path do not match.")
    if len(w_path) != u:
        sys.exit("Beginning age and length of w_path do not match.")
    if len(n) != u:
        sys.exit("Beginning age and length of n do not match.")
    b_guess = 1.01 * b_init
    eullf_objs = (u, beta, sigma, beg_wealth, c_bar, n, r_path,
                  w_path, p_c_path, p_tilde_path)
    b_path = opt.fsolve(LfEulerSys, b_guess, args=(eullf_objs),
                       xtol=tp_tol)
    c_tilde_path, c_tilde_cstr = firm.get_c_tilde(c_bar, r_path, w_path, p_c_path, p_tilde_path,
                    n, np.append(beg_wealth, b_path))
    c_path, c_cstr = firm.get_c(alpha[:,:u], c_bar, c_tilde_path, p_c_path, p_tilde_path)
    b_err_params = (beta, sigma)
    b_err_vec = firm.get_b_errors(b_err_params, r_path[1:], c_tilde_path,
                                   c_tilde_cstr, diff=True)
    return b_path, c_tilde_path, c_path, b_err_vec
def get_cbess(params, b_guess, p_c, c_bar, I, S, n):
    '''
    Generates vectors for individual savings, composite consumption,
    industry-specific consumption, constraint vectors, and Euler errors
    for a given set of prices (r, w, p, p).

    Inputs:
        params   = length 7 tuple, (alpha, beta, sigma, r, w, p ss_tol)
        alpha    = [I,] vector, expenditure shares on each good
        beta     = scalar in [0,1), discount factor for each model
                   period
        sigma    = scalar > 0, coefficient of relative risk aversion
        r        = scalar > 0, interest rate
        w        = scalar > 0, real wage
        p_tilde        = scalar > 0, composite good price
        ss_tol   = scalar > 0, tolerance level for steady-state fsolve
        b_guess  = [S-1,] vector, initial guess for savings vector
        p_c    = [I,] vector, prices in each industry
        c_bar = [I,] vector, minimum consumption values for all goods
        n     = [S,] vector, exogenous labor supply n_{s}

    Functions called:
        EulerSys_b
        firm.get_c_tilde
        firm.get_c
        firm.get_b_errors

    Objects in function:
        eulb_objs  = length 9 tuple, objects to be passed in to
                     EulerSys_b: (alpha, beta, sigma, r, w, p, p,
                     c_bar, n)
        b       = [S-1,] vector, optimal lifetime savings decisions
        c_tidle_params   = length 3 tuple, parameters for get_c_tilde(r, w, p_tilde)
        c_tilde       = [S,] vector, optimal lifetime consumption
        c_tilde_cstr     = [S,] boolean vector, =True if c_s<=0
        c_params  = length 2 tuple, parameters for get_c (alpha, p)
        c        = [I,S] matrix,  optimal consumption of each good
                     given prices
        c_cstr    = [I,S] boolean matrix, =True if c_{i,s}<=0 for given
                     c_s
        eul_params = length 2 tuple, parameters for get_b_errors
                     (beta, sigma)
        euler_errors     = [S-1,] vector, Euler errors from savings decisions

    Returns: b, c, c_cstr, c, c_cstr, euler_errors
    '''
    alpha, beta, sigma, r, w, p_tilde, ss_tol = params
    eulb_objs = (alpha, beta, sigma, r, w, p_tilde, p_c, c_bar, I, S, n)
    b = opt.fsolve(EulerSys_b, b_guess, args=(eulb_objs), xtol=ss_tol)
    c_tilde, c_tilde_cstr = firm.get_c_tilde(c_bar, r, w, p_c, p_tilde, n,
                                             np.append([0], b))
    c_params = (alpha, p_tilde)
    c, c_cstr = firm.get_c(np.tile(np.reshape(alpha, (I, 1)), (1, S)),
                           np.tile(np.reshape(c_bar, (I, 1)), (1, S)),
                           np.tile(c_tilde, (I, 1)),
                           np.tile(np.reshape(p_c, (I, 1)), (1, S)), p_tilde)
    eul_params = (beta, sigma)
    euler_errors = firm.get_b_errors(eul_params,
                                     r,
                                     c_tilde,
                                     c_tilde_cstr,
                                     diff=True)

    return b, c, c_cstr, c, c_cstr, euler_errors
Beispiel #8
0
def paths_life(params, beg_age, beg_wealth, c_bar, n, r_path, w_path, p_c_path,
               p_tilde_path, b_init):
    '''
    Solve for the remaining lifetime savings decisions of an individual
    who enters the model at age beg_age, with corresponding initial
    wealth beg_wealth.

    Inputs:
        params     = length 5 tuple, (S, alpha, beta, sigma, tp_tol)
        S          = integer in [3,80], number of periods an individual
                     lives
        alpha      = [I,S-beg_age+1], expenditure share on good for remaing lifetime
        beta       = scalar in [0,1), discount factor for each model
                     period
        sigma      = scalar > 0, coefficient of relative risk aversion
        tp_tol    = scalar > 0, tolerance level for fsolve's in TPI
        beg_age    = integer in [1,S-1], beginning age of remaining life
        beg_wealth = scalar, beginning wealth at beginning age
        n       = [S-beg_age+1,] vector, remaining exogenous labor
                     supplies
        r_path      = [S-beg_age+1,] vector, remaining lifetime interest
                     rates
        w_path      = [S-beg_age+1,] vector, remaining lifetime wages
        p_c_path     = [I, S-beg_age+1] matrix, remaining lifetime
                     consumption good prices
        p_tilde_path      = [S-beg_age+1,] vector, remaining lifetime composite
                     goods prices
        b_init     = [S-beg_age,] vector, initial guess for remaining
                     lifetime savings

    Functions called:
        LfEulerSys
        firm.get_c_tilde
        firm.get_c
        firm.get_b_errors

    Objects in function:
        u            = integer in [2,S], remaining periods in life
        b_guess      = [u-1,] vector, initial guess for lifetime savings
                       decisions
        eullf_objs   = length 9 tuple, objects to be passed in to
                       LfEulerSys: (p, beta, sigma, beg_wealth, n,
                       r_path, w_path, p_path, p_tilde_path)
        b_path        = [u-1,] vector, optimal remaining lifetime savings
                       decisions
        c_tilde_path        = [u,] vector, optimal remaining lifetime
                       consumption decisions
        c_path       = [u,I] martrix, remaining lifetime consumption
                        decisions by consumption good
        c_constr     = [u,] boolean vector, =True if c_{u}<=0,
        b_err_params = length 2 tuple, parameters to pass into
                       firm.get_b_errors (beta, sigma)
        b_err_vec    = [u-1,] vector, Euler errors associated with
                       optimal savings decisions

    Returns: b_path, c_tilde_path, c_path, b_err_vec
    '''
    S, alpha, beta, sigma, tp_tol = params
    u = int(S - beg_age + 1)
    if beg_age == 1 and beg_wealth != 0:
        sys.exit("Beginning wealth is nonzero for age s=1.")
    if len(r_path) != u:
        #print len(r_path), S-beg_age+1
        sys.exit("Beginning age and length of r_path do not match.")
    if len(w_path) != u:
        sys.exit("Beginning age and length of w_path do not match.")
    if len(n) != u:
        sys.exit("Beginning age and length of n do not match.")
    b_guess = 1.01 * b_init
    eullf_objs = (u, beta, sigma, beg_wealth, c_bar, n, r_path, w_path,
                  p_c_path, p_tilde_path)
    b_path = opt.fsolve(LfEulerSys, b_guess, args=(eullf_objs), xtol=tp_tol)
    c_tilde_path, c_tilde_cstr = firm.get_c_tilde(
        c_bar, r_path, w_path, p_c_path, p_tilde_path, n,
        np.append(beg_wealth, b_path))
    c_path, c_cstr = firm.get_c(alpha[:, :u], c_bar, c_tilde_path, p_c_path,
                                p_tilde_path)
    b_err_params = (beta, sigma)
    b_err_vec = firm.get_b_errors(b_err_params,
                                  r_path[1:],
                                  c_tilde_path,
                                  c_tilde_cstr,
                                  diff=True)
    return b_path, c_tilde_path, c_path, b_err_vec