Exemple #1
0
        cycles=0)  # This is what makes the type infinite horizon
    BasicType(vFuncBool=False, cubicBool=True)
    BasicType.IncomeDstn = [
        BasicType.IncomeDstn[0]
    ]  # A "one period" infinite horizon model, so only need one period of income distributions

    # Solve the basic type and plot the results, to make sure things are working
    start_time = clock()
    BasicType.solve()
    BasicType.unpack_cFunc()
    end_time = clock()
    print('Solving the basic consumer took ' + mystr(end_time - start_time) +
          ' seconds.')
    BasicType.unpack_cFunc()
    print('Consumption function:')
    plotFunc(BasicType.cFunc[0], 0, 5)  # plot consumption
    print('Marginal consumption function:')
    plotFuncDer(BasicType.cFunc[0], 0, 5)  # plot MPC
    if BasicType.vFuncBool:
        print('Value function:')
        plotFunc(BasicType.solution[0].vFunc, 0.2, 5)

    # Make many copies of the basic type, each with a different risk aversion
    BasicType.vFuncBool = False  # just in case it was set to True above
    my_agent_list = []
    CRRA_list = np.linspace(
        1, 8, type_count)  # All the values that CRRA will take on
    for i in range(type_count):
        this_agent = deepcopy(BasicType)  # Make a new copy of the basic type
        this_agent.assignParameters(
            CRRA=CRRA_list[i])  # Give it a unique CRRA value
Exemple #2
0
Params.init_consumer_objects['beta'] = 0.96
TestType = RetiringConsumerType(**Params.init_consumer_objects)
TestType(survival_prob = 0.9,
          beta = 0.96,
          Gamma = 1.00,
          rho = 2.0,
          sigma_epsilon = [0.0001,None],
          state_grid = setupGridsExpMult(0.001, 50, 64, 3),
          a_max = 20,
          a_size = 48,
          calc_vFunc = True,
          cubic_splines = False,
          constrained = True,
          income_distrib = [None,TestType.income_distrib],
          p_zero_income = [None,TestType.p_zero_income],
          labor_supply = 0.5,
          alpha = 1.0,
          tolerance = 0.0001,
          cycles=0)
TestType.updateAssetsGrid()
transformations = makeCRRAtransformations(TestType.rho,do_Q=True,do_T=True,do_Z=True)
TestType(transformations = transformations)

t_start = time()
TestType.solve()
t_end = time()
print('Took ' + str(t_end-t_start) + ' seconds to solve retirement choice problem.')

plotFuncs(TestType.solution[1].vFunc,20,100)
plotFunc(TestType.solution[0].vFunc,20,100)
Exemple #3
0
  BasicType.assignParameters(       LivPrb = [0.98],
                                    DiscFac = [0.96],
                                    PermGroFac = [1.01],
                                    cycles = 0) # This is what makes the type infinite horizon
  BasicType(vFuncBool = False, cubicBool = True)
  BasicType.IncomeDstn = [BasicType.IncomeDstn[0]] # A "one period" infinite horizon model, so only need one period of income distributions
 
  # Solve the basic type and plot the results, to make sure things are working
  start_time = clock()
  BasicType.solve()
  BasicType.unpack_cFunc()
  end_time = clock()
  print('Solving the basic consumer took ' + mystr(end_time-start_time) + ' seconds.')
  BasicType.unpack_cFunc()
  print('Consumption function:')
  plotFunc(BasicType.cFunc[0],0,5)    # plot consumption
  print('Marginal consumption function:')
  plotFuncDer(BasicType.cFunc[0],0,5) # plot MPC
  if BasicType.vFuncBool:
      print('Value function:')
      plotFunc(BasicType.solution[0].vFunc,0.2,5)
  
  # Make many copies of the basic type, each with a different risk aversion
  BasicType.vFuncBool = False # just in case it was set to True above
  my_agent_list = []
  CRRA_list = np.linspace(1,8,type_count) # All the values that CRRA will take on
  for i in range(type_count):
      this_agent = deepcopy(BasicType)   # Make a new copy of the basic type
      this_agent.assignParameters(CRRA = CRRA_list[i]) # Give it a unique CRRA value
      my_agent_list.append(this_agent)   # Addd it to the list of agent types
      
Exemple #4
0
MarkovType = ConsumerType(**init_consumer_objects)
transition_matrix = np.array([[1.0 - base_primitives["mho"], base_primitives["mho"]], [0.0, 1.0]])
employed_income_dist = [np.ones(1), np.ones(1), np.ones(1)]
unemployed_income_dist = [np.ones(1), np.ones(1), np.zeros(1)]
p_zero_income = [np.array([0.0, 1.0])]
MarkovType.solution_terminal.cFunc = 2 * [MarkovType.solution_terminal.cFunc]
MarkovType.solution_terminal.vFunc = 2 * [MarkovType.solution_terminal.vFunc]
MarkovType.solution_terminal.vPfunc = 2 * [MarkovType.solution_terminal.vPfunc]
MarkovType.solution_terminal.vPPfunc = 2 * [MarkovType.solution_terminal.vPPfunc]
MarkovType.solution_terminal.m_underbar = 2 * [MarkovType.solution_terminal.m_underbar]
MarkovType.income_distrib = [[employed_income_dist, unemployed_income_dist]]
MarkovType.p_zero_income = p_zero_income
MarkovType.transition_matrix = transition_matrix
MarkovType.time_inv.append("transition_matrix")
MarkovType.solveAPeriod = consumptionSavingSolverMarkov
MarkovType.cycles = 0

t_start = clock()
MarkovType.solve()
t_end = clock()
MarkovType.unpack_cFunc()

print('Solving the same model "the long way" took ' + str(t_end - t_start) + " seconds.")
# plotFuncs([ExampleType.solution[0].cFunc,ExampleType.solution[0].cFunc_U],0,m_upper)
plotFuncs(MarkovType.cFunc[0], 0, m_upper)
diffFunc = lambda m: ExampleType.solution[0].cFunc(m) - MarkovType.cFunc[0][0](m)
print("Difference between the (employed) consumption functions:")
plotFunc(diffFunc, 0, 100)

plotFuncs([ExampleType.cSSfunc, ExampleType.mSSfunc, ExampleType.solution[0].cFunc], 0, 10)