# %% KinkyExample = KinkedRconsumerType(**KinkedRdict) KinkyExample.cycles = 0 # Make the example infinite horizon KinkyExample.solve() # %% [markdown] # An element of a $\texttt{KinkedRconsumerType}$'s solution will have all the same attributes as that of a $\texttt{IndShockConsumerType}$; see that notebook for details. # # We can plot the consumption function of our "kinked R" example, as well as the MPC: # %% print("Kinked R consumption function:") plotFuncs(KinkyExample.solution[0].cFunc, KinkyExample.solution[0].mNrmMin, 5) print("Kinked R marginal propensity to consume:") plotFuncsDer(KinkyExample.solution[0].cFunc, KinkyExample.solution[0].mNrmMin, 5) # %% [markdown] # ## Simulating the "kinked R" model # # In order to generate simulated data, an instance of $\texttt{KinkedRconsumerType}$ needs to know how many agents there are that share these particular parameters (and are thus *ex ante* homogeneous), the distribution of states for newly "born" agents, and how many periods to simulated. These simulation parameters are described in the table below, along with example values. # # | Description | Code | Example value | # | :---: | --- | --- | # | Number of consumers of this type | $\texttt{AgentCount}$ | $10000$ | # | Number of periods to simulate | $\texttt{T_sim}$ | $500$ | # | Mean of initial log (normalized) assets | $\texttt{aNrmInitMean}$ | $-6.0$ | # | Stdev of initial log (normalized) assets | $\texttt{aNrmInitStd}$ | $1.0$ | # | Mean of initial log permanent income | $\texttt{pLvlInitMean}$ | $0.0$ | # | Stdev of initial log permanent income | $\texttt{pLvlInitStd}$ | $0.0$ | # | Aggregrate productivity growth factor | $\texttt{PermGroFacAgg}$ | $1.0$ |
# %% {"hidden": true} print(vars(IndShockExample.solution[0])) # %% [markdown] {"hidden": true} # The single-period solution to an idiosyncratic shocks consumer's problem has all of the same attributes as in the perfect foresight model, with a couple additions. The solution can include the marginal marginal value of market resources function $\texttt{vPPfunc}$, but this is only constructed if $\texttt{CubicBool}$ is $\texttt{True}$, so that the MPC can be accurately computed; when it is $\texttt{False}$, then $\texttt{vPPfunc}$ merely returns $\texttt{NaN}$ everywhere. # # The $\texttt{solveConsIndShock}$ function calculates steady state market resources and stores it in the attribute $\texttt{mNrmSS}$. This represents the steady state level of $m_t$ if *this period* were to occur indefinitely, but with income shocks turned off. This is relevant in a "one period infinite horizon" model like we've specified here, but is less useful in a lifecycle model. # # Let's take a look at the consumption function by plotting it, along with its derivative (the MPC): # %% {"hidden": true} print('Consumption function for an idiosyncratic shocks consumer type:') plotFuncs(IndShockExample.solution[0].cFunc,IndShockExample.solution[0].mNrmMin,5) print('Marginal propensity to consume for an idiosyncratic shocks consumer type:') plotFuncsDer(IndShockExample.solution[0].cFunc,IndShockExample.solution[0].mNrmMin,5) # %% [markdown] {"hidden": true} # The lower part of the consumption function is linear with a slope of 1, representing the *constrained* part of the consumption function where the consumer *would like* to consume more by borrowing-- his marginal utility of consumption exceeds the marginal value of assets-- but he is prevented from doing so by the artificial borrowing constraint. # # The MPC is a step function, as the $\texttt{cFunc}$ itself is a piecewise linear function; note the large jump in the MPC where the borrowing constraint begins to bind. # # If you want to look at the interpolation nodes for the consumption function, these can be found by "digging into" attributes of $\texttt{cFunc}$: # %% {"hidden": true} print('mNrmGrid for unconstrained cFunc is ',IndShockExample.solution[0].cFunc.functions[0].x_list) print('cNrmGrid for unconstrained cFunc is ',IndShockExample.solution[0].cFunc.functions[0].y_list) print('mNrmGrid for borrowing constrained cFunc is ',IndShockExample.solution[0].cFunc.functions[1].x_list) print('cNrmGrid for borrowing constrained cFunc is ',IndShockExample.solution[0].cFunc.functions[1].y_list) # %% [markdown] {"hidden": true}
BasicType(aXtraMax=100, aXtraCount=64) BasicType(vFuncBool=False, CubicBool=True) BasicType.updateAssetsGrid() BasicType.timeFwd() # Solve the basic type and plot the results, to make sure things are working start_time = clock() BasicType.solve() end_time = clock() print('Solving the basic consumer took ' + mystr(end_time - start_time) + ' seconds.') BasicType.unpackcFunc() print('Consumption function:') plotFuncs(BasicType.cFunc[0], 0, 5) # plot consumption print('Marginal consumption function:') plotFuncsDer(BasicType.cFunc[0], 0, 5) # plot MPC if BasicType.vFuncBool: print('Value function:') plotFuncs(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