if ExplicitExample.vFuncBool: pGrid = np.linspace(0.1, 3.0, 24) M = np.linspace(0.001, 5, 300) for p in pGrid: M_temp = M + ExplicitExample.solution[0].mLvlMin(p) C = ExplicitExample.solution[0].vFunc(M_temp, p * np.ones_like(M_temp)) plt.plot(M_temp, C) plt.ylim([-200, 0]) plt.xlabel('Market resource level mLvl') plt.ylabel('Value v') plt.show() # %% # Simulate many periods to get to the stationary distribution ExplicitExample.T_sim = 500 ExplicitExample.track_vars = ['mLvl', 'cLvl', 'pLvl'] ExplicitExample.initialize_sim() ExplicitExample.simulate() plt.plot(np.mean(ExplicitExample.history['mLvl'], axis=1)) plt.xlabel('Simulated time period') plt.ylabel('Average market resources mLvl') plt.show() # %% [markdown] # ## 2. Persistent income shock consumer # # # Class to solve consumption-saving models with idiosyncratic shocks to income in which shocks are persistent and transitory. This model extends `ConsGenIndShockModel` by allowing (log) persistent income to follow an AR(1) process. # # The agent's problem can be written in Bellman form as: #
pGrid = np.linspace(0.1, 3.0, 24) M = np.linspace(0.001, 5, 300) for p in pGrid: M_temp = M + ExplicitExample.solution[0].mLvlMin(p) C = ExplicitExample.solution[0].vFunc(M_temp, p * np.ones_like(M_temp)) plt.plot(M_temp, C) plt.ylim([-200, 0]) plt.xlabel("Market resource level mLvl") plt.ylabel("Value v") plt.show() # %% # Simulate some data if do_simulation: ExplicitExample.T_sim = 500 ExplicitExample.track_vars = ["mLvlNow", "cLvlNow", "pLvlNow"] ExplicitExample.makeShockHistory() # This is optional ExplicitExample.initializeSim() ExplicitExample.simulate() plt.plot(np.mean(ExplicitExample.mLvlNow_hist, axis=1)) plt.xlabel("Simulated time period") plt.ylabel("Average market resources mLvl") plt.show() # %% # Make and solve an example "persistent idisyncratic shocks" consumer PersistentExample = PersistentShockConsumerType() t_start = process_time() PersistentExample.solve() t_end = process_time() print(