Skip to content

Latest commit

 

History

History
782 lines (567 loc) · 133 KB

README.md

File metadata and controls

782 lines (567 loc) · 133 KB

This is a work-in-progress (updated: 2019-07-27) website for solving several infinite-horizon exogenously-incomplete dynamic assets models in discrete-time. Section (1) solves the savings problem. Section (2) solves the borrowing and savings problem. Section (3) solve the risky and safe asset problem (risky entrepreneur). Section (4) solves the same problem as (3) with percentage choice grids and interpolation. Section (5) and (6) is an application/extension of the earlier models: models from (1) through (4) are augmented following A Choice Amongst Many: Household Borrowing in a Setting with Multiple Providers (Robert M. Townsend and Fan Wang 2019).

Key elements for solution algorithms from (1) through (5) are described in Wang (2019). Generally, looped, vectorized, and optimized-vectorized implementations of the same solution algorithm with tabular, graphical and profiling results are shown. Separate subsections show files that solve policy functions and derive asset distributions. Looped codes are shown for clarity, vectorized codes are shown for speed. Codes are designed to not require special hardware or explicit parallelization. Codes are tested on Windows 10 with Matlab 2019a for replicability. The algorithms here are platform agnostic and could be implemented in alternative languages, but speed variations across languages is generally small for the algorithms described here. Please contact FanWangEcon for problems.

Functions are written with default parameters and are directly callable. See Set-Up Instructions for instructions and folder descriptions. On this webpage, there are three types of files:

  1. m: matlab m file
  2. publish html: html files generated by matlab publish
  3. profile: html files generated by profiling the m file with timing results

For an introduction to savings and borrowing problems, see Fan's Intro Math for Econ.

1. The Savings Problem (AZ)

Files for this section are in the /m_az/ folder in the CodeDynaAsset repository. links: (1) savings problem (2) borrowing and savings problem (3) risky and safe asset problem (risky entrepreneur) (4) percentage choice grids and interpolation (5) Townsend and Wang 2019 Single Asset (6) Townsend and Wang 2019 Safe + Risky Asset.

This section solves the standard household-side problem of the Bewley/Aiyagari type heterogeneous agent model. The supply of credit in Aiygari (1994) can be derived by invoking 1.1 and 1.2 with different interest rates.

1.1 Dynamic Programming Files (AZ)

Price (wage and interest rate) taking households arrive in a period with accumulated savings and a possibly persistent income shock. Households decide on optimal savings to carry forward to the next period in order to smooth consumption given rational expectation of the income process. Parameters can be adjusted here, for the benchmark simulation:

  • savings only with minimum income
  • 750 grid points for asset states/choices
  • 15 grid points for the AR1 shock
  • other parameters

Algorithms below provide identical solutions:

  1. az model looped solution: m | publish html | profile
    • speed: 8634.5 seconds, small grid demonstration in HTML
    • loops: 1 for VFI, 1 for shocks, 1 for asset state, 1 for asset choice, 1 for future shocks
  2. az model vectorized solution: m | publish html | profile
    • speed: 32.3 seconds
    • loops: 1 for VFI, 1 for shocks, vectorize remaining 3 loops
  3. az model optimized vectorized solution: m | publish html | profile
    • speed: 1.3 seconds
    • loops: 1 for VFI, 1 for shocks, vectorize remaining 3 loops, reuse u(c)
    • reuse u(c) in cells, speed improvements described here

1.2 Asset Distributions (AZ)

1.2.a Deriving Asset Distributions

Solve for the stationary probability mass function over states using non-simulation methods. The first two methods below involve iteration, the third is semi-analytical and iteration-free (see appendix in Wang 2019 for details). The semi-analytical approach has three implementations, eigenvector or projection or nth-power. The eigenvector approach, when implemented with sparse matrix, is potentially faster (but not always). The codes compute, with benchmark parameters and after invoking the optimized-vectorized code from above, for each outcome y:

  • joint and marginal probability mass functions: P(y,z), P(y,a) and P(y)
  • E(Y), var(Y), P(Y=0), P(Y=max(Y)), etc
  • percentiles and fraction of y held by households up to percentiles

Algorithms 1 and 2 approximate 3 (speed does not include 1.1 speed), the vectorized and semi-analytical programs work for the risky and safe asset problems in section 3.1 and 3.2 as well:

  1. az asset distribution looped: m | publish html | profile
    • speed: 5.0 seconds
    • loops: 1 for pmf iteration, 1 for shocks, 1 for asset state, 1 for future shocks
  2. az+akz+wkz asset distribution vectorized: m | publish html | profile
    • speed: 0.8 seconds
    • loops: 1 for pmf iteration, 1 for shocks, policy index match
  3. az+akz+wkz asset distribution semi-analytical: m | publish html | profile
    • speed: 0.2 seconds sparse eigenvector approach
    • iteration free, construct full-states markov, sparse matrix, eigenvector/projection/Nth-power

1.2.b Statistics Support Functions

Deriving asset distributions relies on two functions from the /tools/ folder for computing pmf for choice/outcome as well as distributional statistics based on pmf which apply to all models in later sections as well:

  1. all model f(y) from f(a,z) and y(a,z): m | publish html
    • from pmf f(a,z) and outcome/policy y(a,z), derive f(y,z), f(y,a) and f(y)
  2. all model covariance and correlations: m | publish html
    • given E(y1), E(y2), sd(y1), sd(y2), f(a,z), y1(a,z), y2(a,z), compute cor(y1,y2)
  3. all model distributional statistics: m | publish html
    • table: mean, sd, percentiles, fraction of outcome/asset held by household up to x percentile
  4. all model store statistics to container: m | publish html
    • This is a manager file

1.3 Solution Support (AZ)

Parameters and Function Definitions:

  1. az model set default parameters: m | publish html
    • param_map: container map for carrying parameters across functions
    • support_map: container map for carrying programming instructions etc across functions
  2. az model set functions: m | publish html
    • functions: centrally define functions as function handles
  3. az model generate states, choices, and shocks grids: m | publish html
    • func_map: container map containing all function handles
    • armt_map: container map containing matrixes for states and choices.

Output Analysis:

  1. az model solution results processing: m | publish html
    • table: value and policy function by states and shocks
    • table: iteration convergence and percentage policy function change by shock
    • graph: value + policy functions with levels, logged levels and percentages
    • mat: store all workspace matrixes, arrays, scalar values to matrixes
  2. az model solution results graphing: m | publish html
    • graph: value function by asset and shock
    • graph: consumption and asset choice levels
    • graph: consumption and asset logged levels
    • graph: consumption and asset as percentages of coh and assets

1.4 Parameter Testing (AZ)

Test model outcomes as parameters given parameter adjustments.

  1. az model value and policy functions precision
  2. az model overall speed test for asset distribution simulation
  3. az preference parameters and asset distributions
  4. az model shock process and asset distributions

1.5 Simulations (AZ)

Simulate and graph effects of changing parameters on outcomes. Compare against simulation in 2.5 for the effects of allowing for borrowing on distributional outcomes. And compare against simulations in 3.7 as well as 4.8 for the effects of including a risky capital investment on distributional outcomes.

Simulation Functions:

  1. az model simulate model: m | publish html
    • cross vs full grid vs random simulation
    • outputs to table where columns are statistics, rows are variables, groups of rows are different simulations
  2. az model graph simulation results: m | publish html
    • graph various aggregate and distributional outcomes

Simulation Results:

  1. az the effects preference parameters on distributional outcomes
  2. az the effects shock parameters on distributional outcomes
  3. az the effects prices on distributional outcomes
  4. az the effects preference + shocks + prices on distributional outcomes

2. The Savings + Borrowing Problem (ABZ)

Files for this section are in the /m_abz/ folder in the CodeDynaAsset repository. links: (1) savings problem (2) borrowing and savings problem (3) risky and safe asset problem (risky entrepreneur) (4) percentage choice grids and interpolation (5) Townsend and Wang 2019 Single Asset (6) Townsend and Wang 2019 Safe + Risky Asset.

Codes from 1.1-1.3 are adjusted slightly to deal with both savings as well as borrowing with default. Additionally, there is an additional shock for interest rate.

2.1 Dynamic Programming Files (ABZ)

Parameters can be adjusted here, for the benchmark simulation:

  • savings and borrowing (with default) with minimum income
  • 750 grid points for asset states/choices
  • 55 grid points for shocks: 11 wage, 5 borrow interest
  • other parameters

Using three algorithm that provide identical solutions:

  1. abz model looped solution: m | publish html | profile
    • small grid demonstration
  2. abz model vectorized solution: m | publish html | profile
    • speed: 281.0 seconds
  3. abz model optimized vectorized solution: m | publish html | profile
    • speed: 14.0 seconds

2.2 Asset Distributions (ABZ)

This is the wrapper file for abz that invokes the looped, vectorized, and semi-analytical distributional programs from 1.2:

2.3 Solution Support (ABZ)

Add parameters bl_default and fl_default_aprime, which control if default is allowed and next period asset level for defaulters.

Parameters and Function Definitions:

  1. abz model set default parameters: m | publish html
  2. abz model set functions: m | publish html
  3. abz model borrowing and savings grid: m | publish html
  4. abz model generate states, choices, and shocks grids: m | publish html

Output Analysis: shared files with az.

2.4 Parameter Testing (ABZ)

We solved the exogenously incomplete borrowing and savings problem in 1.4. Now we analyze model features by adjusting parameters.

Policy Function Testing

  1. abz borrowing and savings choice grid with default
  2. abz model solution precision
  3. abz model compare saving vs borrowing with and without default

Asset Distribution Testing

  1. abz model overall speed test
  2. abz borrowing interest rates, bounds, and minimum c
  3. abz preference parameters
  4. abz model shock process

2.5 Simulations (ABZ)

Simulate and graph effects of changing parameters on outcomes. Compare against simulation in 1.5 for the effects of allowing for borrowing on distributional outcomes. And compare against simulations in 3.7 as well as 4.8 for the effects of including a risky capital investment on distributional outcomes.

Simulation Functions:

Share functions with az from 1.5 above, model (1) simulate model (2) graph simulation results

Simulation Results:

  1. abz the effects borrowing parameters on distributional outcomes
  2. abz the effects preference parameters on distributional outcomes
  3. abz the effects shock parameters on distributional outcomes
  4. abz the effects min inc and save r on outcomes
  5. abz the effects preference + shocks + prices on distributional outcomes

3. The Risky + Safe Asset Problem (Part 1)

Files for this section are in the /m_akz/ folder in the CodeDynaAsset repository. links: (1) savings problem (2) borrowing and savings problem (3) risky and safe asset problem (risky entrepreneur) (4) percentage choice grids and interpolation (5) Townsend and Wang 2019 Single Asset (6) Townsend and Wang 2019 Safe + Risky Asset.

Two endogenous assets, one safe one risky. Risky asset could be stocks with constant return to scale, or physical capital investment with depreciation and decreasing return to scale (risky entrepreneur). The risky asset choice is made ex-ante the realization of the shock for that risky asset, hence risky. This contrasts with a firm's within period optimal physical capital choice problem, which is made after the realization of shocks. Note that the utility function is CRRA, however, households do not have constant share of risky investment for any wealth (cash-on-hand) levels when risky asset has decreasing return to scale and/or shock is persistent and/or there is minimum income.

There are more analytical ways of solving the basic version of this problem. Here we stick to using this grid based solution algorithm which allows for flexibly solving non-differentiable and non-continuous problems. The grid based solution algorithm now with 2 endogenous choices and states requires exponentially more computation time than the az model. Here I provide three sets of solution algorithms at increasing speeds:

  • In 3.1, solve the problem with the two asset choice concurrently
  • In 3.2, solve the problem in two stages
  • In 3.3, two stage solution with interpolation

3.1 Concurrent Dynamic Programming (AKZ)

Files for this section have the akz in file names and are in the /m_akz/ folder in the CodeDynaAsset repository.

The akz problem. Parameters can be adjusted here, for the benchmark simulation:

  • savings problem with alternative safe and risky assets and minimum income
  • 50 aggregate savings grid points, 50 risky investment grid points, 1274 valid choice combinations in upper triangle. Note that the benchmark parameters for the az model has 750 grid points of choices/states, the benchmark problem here is larger and hence takes more time.
  • 15 grid points for the AR1 shock
  • other parameters
  1. akz model looped solution: m | publish html | profile
    • speed: 32764.7 seconds
    • loops: 1 for VFI, 1 for shocks, 1 for coh(b,k,z), 1 for (b',k') choices, 1 for future shocks
  2. akz model vectorized solution: m | publish html | profile
    • speed: 93.2 seconds
    • loops: 1 for VFI, 1 for shocks, vectorize remaining
  3. akz model optimized vectorized solution: m | publish html | profile
    • speed: 2.7 seconds
    • loops: 1 for VFI, 1 for shocks, vectorize remaining
    • reuse u(c) in cells, speed improvements described here

3.2 Two-Stage Dynamic Programming (WKZ)

Files for this section have the wkz in file names and are in the /m_akz/ folder in the CodeDynaAsset repository.

The wkz problem, w=k'+b'. Takes significantly less time than 3.1, produces identical results. Rather than solving the two asset problem in one shot. We can separate the problem into two stages. In the second stage, we find the optimal k' choice given w=k'+b': max_{k'}(E(V(coh(k',b'=w-k'),z')) given w and z. The second stage optimal risky asset allocation problem is not a function of cash-on-hand in the current period conditional on the aggregate savings choice w=k'+b'. In the first stage, households optimized only over aggregate savings. This significantly reduces the dimensionality of the problem.

Parameters can be adjusted here, for the benchmark simulation, same grid sizes as 3.1.

  1. wkz model 2nd stage solution: m | publish html
    • solving for k(w,z) = argmax_{k'}(E(V(coh(k',b'=w-k'),z')) given z and w.
  2. wkz model looped solution: m | publish html | profile
    • speed: 581.0 seconds
    • loops: 1 for VFI, 1 for shocks, 1 for coh(b,k,z), 1 for w(z)=k'+b'
  3. wkz model vectorized solution: m | publish html | profile
    • speed: 5.6 seconds
    • loops: 1 for VFI, 1 for shocks, vectorize remaining
  4. wkz model optimized vectorized solution: m | publish html | profile
    • speed: 0.9 seconds
    • Step One solve k(w,z); Step Two solve w(z,coh(b,k,z)) given k(w,z)
    • loops: 1 for VFI, 1 for shocks, vectorize remaining
    • store u(c) in cells, update when k*(w,z) changes, speed improvements described here

3.3 Two-Stage DP with Interpolation (iWKZ)

Files for this section have the iwkz in file names and are in the /m_akz/ folder in the CodeDynaAsset repository.

Algorithm Description

The iwkz problem, interpolated version of 2.2. Takes significantly less time than 3.2 at larger choice grids, produces approximately identical results as 3.2. Simulations below are at the same grid points as 3.2 and 3.1 for comparison, but at these low accuracy grid points, iwkz is not necessarily faster than 3.2.

The reason that iWKZ is faster then 3.2 is that when we increase aggregate savings grid points, we do not need to reduce the two interpolation grid gaps. COH is the endogenous state, and its size is determined by the cash-on-hand interpolation grid gap. The choice grid increases in size as we increase aggregate savings grid points, but since we are solving in two stages, the dimensionality of the problem increases proportionally (but not exponentially). The total number of safe and risky asset choice is determined by assuming equi-distance grid gap for aggregate savings as well as both risky and safe investments. Speed up achieved via interpolation as described here.

In section 3.6 below, I show how solution results change for iwkz as we increase aggregate savings grid points, shock grid points, reduce the interpolation gaps, or change production function parameters from decreasing to constant return to scale.

Algorithm Implementation

Parameters can be adjusted here, for the benchmark simulation, same grid size parameters as 3.1 and 3.2, but we introduce two additional measures of precision:

  • 0.0001 consumption interpolation grid gap
  • 0.1 value function cash-on-hand interpolation grid gap
  • other parameters
  1. Use same wkz 2nd stage solution as in 3.2
  2. iwkz model looped solution: m | publish html | profile
    • speed: 577.8 seconds
    • loops: 1 for VFI, 1 for shocks, 1 for coh(b,k,z), 1 for w(z)=k'+b'
  3. iwkz model vectorized solution: m | publish html | profile
    • speed: 2.3 seconds
    • loops: 1 for VFI, 1 for shocks, vectorize remaining
  4. iwkz model optimized vectorized solution: m | publish html | profile
    • speed: 0.8 seconds
    • Step One solve k(w,z); Step Two solve w(z,coh(b,k,z)) given k(w,z)
    • loops: 1 for VFI, 1 for shocks, vectorize remaining
    • interpolate u(c), interpolate v(coh,z)
    • store u(c) in cells, update when k*(w,z) changes

3.4 Asset Distributions

3.4.a Distributions for AKZ and WKZ models

Solve for the stationary probability mass function over states using non-simulation methods. The algorithms in this section works for situations where (1) state-space grid is identical to the choice-space grid, and (2) the endogenous element of the state-space are last period choices. The second point means that we are interested in f(y,z), where y'(y,z), but not y'(y,z,z').

The looped program is new but very similar to the looped code from 1.2.a earlier. The vectorized and semi-analytical programs invoke the corresponding programs from 1.2.a. The codes compute, with benchmark parameters and after invoking the optimized-vecotrized dynamic programming code from above for akz or wkz, for each outcome y various distributional statistics of interest, including: P(y,z), P(y), etc.

Algorithms 1 and 2 approximate 3 (speed does not include 3.1 and 3.2 speed):

  1. akz+wkz asset distribution looped: m | publish html | profile
    • speed: 18.8 seconds
  2. akz+wkz asset distribution vectorized: m | publish html | profile
    • speed: 1.9 seconds
  3. akz+wkz asset distribution semi-analytical: m | publish html | profile
    • speed: 0.9 seconds sparse eigenvector approach

3.4.b Distributions for iWKZ model

Solve for the stationary probability mass function over states using non-simulation methods. The algorithms in this section works for iwkz from 3.3. For this problem, we are interested in f(y,z), where y'(y,z,z'). Unlike for 3.4.a, here, z' also matters.

The programs here are significantly different from programs from 1.2 and 3.4.a above. The codes compute, with benchmark parameters and after invoking the optimized-vecotrized dynamic programming code from above for iwkz, for each outcome y various distributional statistics of interest, including: P(y,z), P(y), etc.

Algorithms 1 and 2 approximate 3 (speed does not include 3.3 speed):

  1. iwkz asset distribution looped: m | publish html | profile
    • speed: 104.4 seconds
  2. iwkz asset distribution vectorized: m | publish html | profile
    • speed: 0.8 seconds
  3. iwkz asset distribution semi-analytical: m | publish html | profile
    • speed: 0.4 seconds sparse eigenvector approach

3.5 Solution Support

All solution algorithms share the same support files.

Parameters and Function Definitions:

  1. akz+wkz+iwkz model set default parameters: m | publish html
  2. akz+wkz+iwkz model set functions: m | publish html
  3. akz+wkz+iwkz model generate states, choices, and shocks grids: m | publish html

Output Analysis:

  1. akz+wkz+iwkz model solution results processing: m | publish html
  2. akz+wkz+iwkz model solution results graphing: m | publish html

3.6 Parameter Testing (iWKZ)

We solve the joint asset choice problem using the optimized-vectorized method for iwkz algorithm from 3.3. Now we analyze model features by adjusting parameters.

  1. iwkz model solution precision
  2. iwkz model shift minimum income
  3. iwkz model shift shock persistence

3.7 Simulations (iWKZ)

Simulate and graph effects of changing parameters on outcomes. The results here should be compared against results in section 4.8. In 4.8, by adopting percentage grid rather than level grid, there is a significant improvement in the precision of simulations for the same number of grid points. Results in 4.8 and 3.7 should be compared about simulations from az and abz models in 1.5 and 2.5.

Simulation Functions:

Share functions with az from 1.5 above, model (1) simulate model (2) graph simulation results

Simulation Results:

  1. iwkz the effects preference parameters on distributional outcomes
  2. iwkz the effects production function shock parameters on distributional outcomes
  3. iwkz the effects production function elasticity and depreciation parameters on distributional outcomes
  4. iwkz the effects price parameters on distributional outcomes
  5. iwkz the effects preference + shocks + prices on distributional outcomes

4. The Risky + Safe Asset Problem (Part 2)

Files for this section are in the /m_ipwkz/ folder in the CodeDynaAsset repository. links: (1) savings problem (2) borrowing and savings problem (3) risky and safe asset problem (risky entrepreneur) (4) percentage choice grids and interpolation (5) Townsend and Wang 2019 Single Asset (6) Townsend and Wang 2019 Safe + Risky Asset.

In Section 3, we solved the two asset problem in levels. Here, the same model is solved, but using an alternative algorithm. Now the model is solved in percentages. Households choose the percentage of cash-on-hand to allocate to aggregate savings, and then given that the percentage of total savings to allocate to safe vs risky asset.

4.1 Two Stage Percentage Interpolation Algorithm Description

In the levels solution above, households at different state space points face the same choice set, but almost half of the choice points are invalid because they would lead to negative consumption today. Solving the problem in percentages allow all households to have the same choice grid in terms of percentage levels. This potentially offers much more precise solutions under some model parameters combinations. One could compare testing results from 3.6 above and 4.4 below. Additionally, the levels based grid solution might lead to degenerate steady state asset distributions. This is because at low levels of cash-on-hand, if the risky asset's lowest level of choice is invalid, then an individual could be stuck in that state. (see appendix in Wang 2019 for details)

This is the ipWKZ problem: i stands for interpolation, p stands for percentage, wk stand for two stage w=k'+b' first then k' given w. For the ipWKZ model, while there is still very substantial gains from the looped to the vectorized algorithm implementation, the speed improvements from moving to the efficient-vectorized implementation is much less substantial. For the small benchmark grids, the speed is actually slower when we use the efficient-vectorized implementation.

We have three sets of interpolations now:

  • interpolate 1: As before, we interpolate over u(c).
  • interpolate 2: As before, interpolation of the value function over cash-on-hand and shocks is needed because the solution grid for cash-on-hand in the first stage is not the same as the reachable cash-on-hand levels given percentage second stage choices.
  • interpolate 3: In addition to before, interpolation of the optimal 2nd stage risky investment choice over aggregate savings and shocks is needed because the 2nd stage solution grid for aggregate-savings in the second stage is the not the same as the percentage based first stage aggregate-savings choices. The second interpolation makes the efficiency gain from reusing u(c) through cells when k*(w,z) does not change much less substantial.

In section 3.4 below, I show how solution results change for ipwkz as we increase aggregate savings grid points, shock grid points, reduce the interpolation gaps, or change production function parameters from decreasing to constant return to scale.

4.2 Perc. Interp. Savings DP (IPWKZ)

Parameters can be adjusted here, for the benchmark simulation, same as 3.3, but we introduce several additional measures of precision:

  • savings problem with alternative safe and risky assets
  • 50 aggregate savings percentage grid points, 50 risky investment percentage grid points, 2500 valid choice combinations in triangular choice matrix
  • 15 grid points for the AR1 shock
  • interpolate 1: 0.0001 consumption interpolation grid gap
  • interpolate 2: 0.1 value function cash-on-hand interpolation grid gap
  • interpolate 3: 0.1 expected value function aggregate savings interpolation grid gap
  • other parameters
  1. Use again ipwkz 2nd stage solution: m | publish html
    • solving for kperc(w,z) = argmax_{kperc'}(E(V(coh(kperc',b'=w-w*kperc'),z')) given z and w.
  2. ipwkz model loop: m | publish html | profile
    • small grid demonstration
  3. ipwkz model vectorized: m | publish html | profile
    • speed: 4.2 seconds
  4. ipwkz model optimized vectorized solution: m | publish html | profile
    • speed: 1.6 seconds
    • Step One solve kperc(w,z); Step Two solve wperc(z,coh(b,k,z)) given kperc(w,z)
    • loops: 1 for VFI, 1 for shocks, vectorize remaining
    • interpolate u(c), interpolate v(coh,z), interpolate EV(w,z)
    • store u(c) in cells, update when k*(w,z) changes

4.3 Perc. Interp. Save + Borrow DP (IPWKBZ)

The code from 4.1 are modified to allow for default. Set up for default is the same as in the abz model discussed in section 2. Parameters can be adjusted here, for the benchmark simulation, same parameters as 4.1.

  1. Second Stage with borrowing ipwkbz 2nd stage solution: m | publish html
  2. ipwkbz model optimized vectorized solution: m | publish html | profile
    • speed: 2.5 seconds

4.4 Perc. Interp. Borrow R Shock DP (IPWKBZR)

The code from 4.2 are modified to allow for interest rate shock for borrowing. Set up for default and interest rate shock is the same as in the abz model discussed in section 2. Parameters can be adjusted here, for the benchmark simulation, same parameters as 4.1.

  • 55 grid points for shocks: 11 wage, 5 borrow interest
  1. Second Stage with borrowing ipwkbzr 2nd stage solution: m | publish html
  2. ipwkbzr model optimized vectorized solution: m | publish html | profile
    • speed: 19.6 seconds

4.5 Asset Distributions

This is the wrapper file for abz that invokes the looped, vectorized, and semi-analytical distributional programs from 3.4.b:

  1. ipWKZ distributional wrapper: m | publish html | profile
    • speed (dynamic programming + distribution): 2.5 seconds
  2. ipWKBZ distributional wrapper: m | publish html | profile
    • speed (dynamic programming + distribution): 4.2 seconds
  3. ipWKBZR distributional wrapper: m | publish html | profile
    • speed (dynamic programming + distribution): 51.1 seconds

4.6 Solution Support (ipWKZ + ipWKBZ + ipWKBZR)

All solution algorithms share the same support files.

Parameters and Function Definitions (ipwkz):

  1. ipwkz model set default parameters: m | publish html
  2. ipwkz model set functions: m | publish html
  3. ipwkz model generate states, choices, and shocks grids: m | publish html

Parameters and Function Definitions (ipwkbz):

  1. ipwkbz model set default parameters: m | publish html
  2. ipwkbz model set functions: m | publish html
  3. ipwkbz model generate states, choices, and shocks grids: m | publish html

Parameters and Function Definitions (ipwkbzr):

  1. ipwkbzr model set default parameters: m | publish html
  2. ipwkbzr model set functions: m | publish html
  3. ipwkbzr model generate states, choices, and shocks grids: m | publish html

Output Analysis:

  1. ipwkz+ipwkbz+ipwkbzr shares with akz+wkz+iwkz models solution results processing codes.
  2. ipwkz+ipwkbz+ipwkbzr shares with akz+wkz+iwkz models solution results graphing codes.

4.7 Parameter Testing (ipWKZ + ipWKBZ)

Savings Testing (ipWKZ)

We solve the joint asset choice problem using the optimized-vectorized method for ipwkz algorithm from 3.3. Now we analyze model features by adjusting parameters.

  1. ipwkz 2nd stage optimal k given w percentage vs level
  2. ipwkz model solution precision
  3. ipwkz model shift minimum income
  4. ipwkz model shift shock persistence

Savings + Borrowing Testing (ipWKBZ)

We solve the joint asset choice problem using the optimized-vectorized method for ipwkbz algorithm from 3.3. Now we analyze model features by adjusting parameters.

  1. ipwkbz borrowing and savings grid
  2. ipwkbz model solution precision
  3. ipwkbz model shift minimum income
  4. ipwkbz model shift shock persistence

4.8 Simulations (ipWKZ + ipWKBZR)

Simulate and graph effects of changing parameters on outcomes. The results here should be compared against results in section 3.7. In 4.8, by adopting percentage grid rather than level grid, there is a significant improvement in the precision of simulations for the same number of grid points. Results in 4.8 and 3.7 should be compared about simulations from az and abz models in 1.5 and 2.5.

Simulation Functions:

Share functions with az from 1.5 above, model (1) simulate model (2) graph simulation results

Savings Simulation Results (ipWKZ):

  1. ipwkz the effects preference parameters on distributional outcomes
  2. ipwkz the effects production function shock parameters on distributional outcomes
  3. ipwkz the effects production function elasticity and depreciation parameters
  4. ipwkz the effects price parameters on distributional outcomes
  5. ipwkz the effects preference + shocks + prices on distributional outcomes

Savings + Borrowing Simulation Results (ipWKBZR):

  1. ipwkbzr the effects preference parameters on distributional outcomes
  2. ipwkbzr the effects production function shock parameters on distributional outcomes
  3. ipwkbzr the effects production function elasticity and depreciation parameters
  4. ipwkbzr the effects price parameters on distributional outcomes
  5. ipwkbzr the effects preference + shocks + prices on distributional outcomes
  6. ipwkbzr the effects borrowing parameters on distributional outcomes

5. One Asset Formal + Informal

Files for this section are in the /m_fibs/ folder in the CodeDynaAsset repository. links: (1) savings problem (2) borrowing and savings problem (3) risky and safe asset problem (risky entrepreneur) (4) percentage choice grids and interpolation (5) Townsend and Wang 2019 Single Asset (6) Townsend and Wang 2019 Safe + Risky Asset.

An application of the codes developed in sections (1) through (5) is the paper: A Choice Amongst Many: Household Borrowing in a Setting with Multiple Providers (Robert M. Townsend and Fan Wang 2019). Below, earlier models are augmented to allow for (a) formal borrowing choice menu, (b) bridge loans, and (c) defaults. This section solves the model in the single asset setting.

5.1 Formal and Informal Choices (ABZ+FIBS)

We have a sequence of files that are specific to solving the joint formal and informal problem.

Choice Generation

  1. Formal Borrowing Grid: m | publish html
    • A menu of formal borrowing choices
  2. Informal Interest Rates: m | publish html
    • Append onto shock Z interest rate shock representing informal interest rate shocks

Formal and Informal Optimization

  1. Match Borrowing to Formal Grid: m | publish html
    • Given a level of borrowing, what items on the formal borrowing menu are the closest to it
  2. Optimize Formal and Informal, Borrowing and Savings Joint Choices: m | publish html
    • Given interest rates, choose among: formal + informal borrowing, formal borrowing + savings, informal borrowing only, formal borrowing only.
  3. Bridge Loan: m | publish html
    • When cash-on-hand is insufficient for loan repayment, households resort to informal lenders for bridge loans
  4. Overall Optimization: m | publish html
    • Overall optimization over joint options, combines ffs_fibs_inf_bridge.m and ffs_fibs_min_c_cost.m.

Results Processing

  1. Discrete Choices: m | publish html
    • Discrete choice categories from continuous choices: (1) informal only (ignore bridge loan) (2) formal only (ignore bridge loan) (3) formal + informal borrowing (ignore bridge loan) (4) formal borrowing + savings (ignore bridge loan) (5) informal only (with bridge loan) (6) formal + informal (include bridge loan) (7) formal borrowing + informal borrowing + savings (include bridge loan) (8) No borrowing or savings

5.2 Dynamic Programming (ABZ+FIBS)

Parameters can be adjusted here, for the benchmark simulation, similar to the abz model:

  • savings and borrowing (with default) with minimum income
  • 750 grid points for asset states/choices
  • 15 grid points for the AR1 shock
  • benchmark simulation with formal menu
  • other parameters

Using three algorithm that provide identical solutions:

  1. abz fibs model looped solution: m | publish html | profile
    • small grid demonstration
  2. abz fibs model vectorized solution: m | publish html | profile
    • speed: 50.2 seconds
  3. abz fibs model optimized vectorized solution: m | publish html | profile
    • speed: 2.5 seconds

5.3 For/Inf + R Shock DP (ABZR+FIBS)

Same as 5.2, but now include interest rate shock. Parameters can be adjusted here, for the benchmark simulation, similar to the abz+fibs model, except:

  • 55 grid points for shocks: 11 wage, 5 borrow interest

Using three algorithm that provide identical solutions:

  1. abzr fibs model looped solution: m | publish html | profile
    • small grid demonstration
  2. abzr fibs model vectorized solution: m | publish html | profile
    • speed: 272.5 seconds
  3. abzr fibs model optimized vectorized solution: m | publish html | profile
    • speed: 11.2 seconds

5.4 Asset Distributions

This are the wrapper files for abz+fibs and abzr+fibs that invokes the looped, vectorized, and semi-analytical distributional programs from 1.2:

5.5 Solution Support (ABZ+FIBS)

Parameters and Function Definition (abz+fibs):

  1. abz fibs model set default parameters: m | publish html
  2. abz fibs model set functions: m | publish html
  3. abz fibs model generate states, choices, and shocks grids: m | publish html

Parameters and Function Definitions (abzr+fibs):

  1. abzr fibs model set default parameters: m | publish html
  2. abzr fibs model set functions: m | publish html
  3. abzr fibs model generate states, choices, and shocks grids: m | publish html

Output Analysis:

  1. abz fibs model solution results processing: m | publish html
    • formal and informal choices policy functions
  2. abz fibs model solution results graphing: m | publish html
    • formal and informal choices levels, logged levels, and percentages

5.6 Parameter Testing (ABZ+FIBS)

We solved the exogenously incomplete borrowing and savings problem in 1.4. Now we analyze model features by adjusting parameters.

Policy Function Testing

  1. abz fibs model solution precision
  2. abz fibs model compare saving vs borrowing with and without default

Asset Distribution Testing

  1. abz fibs borrowing interest rates, bounds, and minimum c
  2. abz fibs preference parameters and asset distributions
  3. abz fibs model shock process and asset distributions

6. Two Assets Formal + Informal

Files for this section are in the /m_fibs/ folder in the CodeDynaAsset repository. links: (1) savings problem (2) borrowing and savings problem (3) risky and safe asset problem (risky entrepreneur) (4) percentage choice grids and interpolation (5) Townsend and Wang 2019 Single Asset (6) Townsend and Wang 2019 Safe + Risky Asset.

An application of the codes developed in sections (1) through (5) is the paper: A Choice Amongst Many: Household Borrowing in a Setting with Multiple Providers (Robert M. Townsend and Fan Wang 2019). Below, earlier models are augmented to allow for (a) formal borrowing choice menu, (b) bridge loans, and (c) defaults. We do this in the context of the safe and risky asset setting. We use the formal and informal choice codes developed in section 5 above here again.

6.1 Two Assets Formal Informal (ipWKBZ+FIBS)

  1. Use ipwkbz+fibs 2nd stage solution with Formal Informal and Bridge: m | publish html
  2. ipwkbz model optimized vectorized solution: m | publish html | profile
    • speed: 8.7 seconds

6.2 Two Assets For+Inf+R Shock (ipWKBZR+FIBS)

  • 55 grid points for shocks: 11 wage, 5 borrow interest
  1. Use ipwkbzr+fibs 2nd stage solution with Formal Informal and Bridge: m | publish html
  2. ipwkbzr model optimized vectorized solution: m | publish html | profile
    • speed: 102.1 seconds

6.2 Asset Distributions

This are the wrapper files for ipwkbz+fibs and ipwkbzr+fibs that invokes the looped, vectorized, and semi-analytical distributional programs from 3.4.b:

6.4 Solution Support

All solution algorithms share the same support files.

Parameters and Function Definitions (ipwkbz+fibs):

  1. ipwkbz+fibs model set default parameters: m | publish html
  2. ipwkbz+fibs model set functions: m | publish html
  3. ipwkbz+fibs model generate states, choices, and shocks grids: m | publish html

Parameters and Function Definitions (ipwkbzr+fibs):

  1. ipwkbzr+fibs model set default parameters: m | publish html
  2. ipwkbzr+fibs model set functions: m | publish html
  3. ipwkbzr+fibs model generate states, choices, and shocks grids: m | publish html

Output Analysis:

  1. ipwkbz+fibs shares with akz+wkz+iwkz models solution results processing codes.
  2. ipwkbz+fibs shares with akz+wkz+iwkz models solution results graphing codes.