Esempio n. 1
0
def run_one(params, res_dict=None):
    """
    Once you have the parameters, this function completes one loop to get
    a dictionary of results.

    For the first loop leave res_dict as None.
    """
    pi = params['pi'][0]
    # lambda_ = params['lambda_'][0]

    np.random.seed(42)
    w_grid = params['w_grid'][0]
    z_grid = params['z_grid'][0]

    if res_dict:
        print("Reusing res_dict.")
        v = res_dict['Tv']
        out = res_dict['rigid_out']
    else:
        v = Interp(w_grid, -w_grid + 27.3, kind='linear')
        out = ss_output_flexible(params)  # ss output w/ flexible wages
    # Get close with linear first.  Then do a few cubic to finish up
    Tv, ws, rest = iter_bellman(v,
                                tol=0.005,
                                strict=False,
                                log=False,
                                params=params,
                                pi=pi,
                                aggL=out,
                                kind='linear')
    Tvc = Interp(Tv.X, Tv.Y, kind='cubic')
    Tv, ws, rest = iter_bellman(Tvc,
                                tol=0.005,
                                strict=False,
                                log=False,
                                params=params,
                                pi=pi,
                                aggL=out)
    res_dict = {'Tv': Tv, 'ws': ws, 'rest': rest}
    flex_ws = Interp(z_grid, ss_wage_flexible(params, shock=z_grid))
    #-------------------------------------------------------------------------
    pths, shks = sample_path(ws, params, nseries=1000, nperiods=30)
    pth, shocks = pths[28], shks[28]  # a period in steady state
    g = ecdf(np.sort(pth))
    shocks = np.sort(shocks)
    #-------------------------------------------------------------------------
    rigid_out = get_rigid_output(ws, params, flex_ws, g)
    res_dict['gp'] = g
    res_dict['rigid_out'] = rigid_out
    return res_dict
def run_one(params, res_dict=None):
    """
    Once you have the parameters, this function completes one loop to get
    a dictionary of results.

    For the first loop leave res_dict as None.
    """
    pi = params['pi'][0]
    # lambda_ = params['lambda_'][0]

    np.random.seed(42)
    w_grid = params['w_grid'][0]
    z_grid = params['z_grid'][0]

    if res_dict:
        print("Reusing res_dict.")
        v = res_dict['Tv']
        out = res_dict['rigid_out']
    else:
        v = Interp(w_grid, -w_grid + 27.3, kind='linear')
        out = ss_output_flexible(params)  # ss output w/ flexible wages
    # Get close with linear first.  Then do a few cubic to finish up
    Tv, ws, rest = iter_bellman(v, tol=0.005, strict=False, log=False,
                                params=params, pi=pi, aggL=out, kind='linear')
    Tvc = Interp(Tv.X, Tv.Y, kind='cubic')
    Tv, ws, rest = iter_bellman(Tvc, tol=0.005, strict=False, log=False,
                                params=params, pi=pi, aggL=out)
    res_dict = {'Tv': Tv, 'ws': ws, 'rest': rest}
    flex_ws = Interp(z_grid, ss_wage_flexible(params, shock=z_grid))
    #-------------------------------------------------------------------------
    pths, shks = sample_path(ws, params, nseries=1000, nperiods=30)
    pth, shocks = pths[28], shks[28]  # a period in steady state
    g = ecdf(np.sort(pth))
    shocks = np.sort(shocks)
    #-------------------------------------------------------------------------
    rigid_out = get_rigid_output(ws, params, flex_ws, g)
    res_dict['gp'] = g
    res_dict['rigid_out'] = rigid_out
    return res_dict
Esempio n. 3
0
            params = self.paramses[run]
            gp = g_p(g0, ws, params)
            self.gps[run] = gp

    # def diff_ws(self, l_key, r_key):
    #     left = self.res_dict[l_key][self.VF]
    #     right = self.res_dict[r_key][self.VF]

if __name__ == '__main__':
    wns = [100, 400]
    zns = [100, 400]

    paramses = setup(wns, zns)

    res_dict = {}
    for wn_zn, params in paramses.iteritems():
        w_grid = params['w_grid'][0]
        w0 = Interp(w_grid, -w_grid+28)
        strt = datetime.datetime.now()
        Tv, ws, rest = iter_bellman(w0, tol=0.1, strict=False, log=False,
                                    params=params)
        time_delta = datetime.datetime.now() - strt
        print(wn_zn, str(time_delta))

        w_max = w_grid[-1]
        g0 = Interp(w_grid, w_grid/w_max, kind='pchip')
        gp = g_p(g0, ws, params)
        res_dict[wn_zn] = (Tv, ws, rest, time_delta, gp)

    res = Results(res_dict, paramses)