• Matlab Toolbox Heterogeneous Agents Dynamic Programming
  • Preface
  • 1 Savings Dynamic Programming
    • 1.1 FF_VFI_AZ_LOOP Savings Loop Grid Examples
      • 1.1.1 Test FF_VFI_AZ_LOOP Defaults
      • 1.1.2 Test FF_VFI_AZ_BISEC_VEC Speed Tests
      • 1.1.3 Test FF_VFI_AZ_LOOP Control Outputs
      • 1.1.4 Test FF_VFI_AZ_LOOP Change Interest Rate and Discount
      • 1.1.5 Test FF_VFI_AZ_LOOP Changing Risk Aversion
      • 1.1.6 Test FF_VFI_AZ_LOOP with Higher Uncertainty
    • 1.2 FF_VFI_AZ_VEC Savings Vectorized Grid Examples
      • 1.2.1 Test FF_VFI_AZ_VEC Defaults
      • 1.2.2 Test FF_VFI_AZ_BISEC_VEC Speed Tests
      • 1.2.3 Test FF_VFI_AZ_VEC Control Outputs
      • 1.2.4 Test FF_VFI_AZ_VEC Change Interest Rate and Discount
      • 1.2.5 Test FF_VFI_AZ_VEC Changing Risk Aversion
      • 1.2.6 Test FF_VFI_AZ_VEC with Higher Uncertainty
    • 1.3 FF_VFI_AZ_BISEC_LOOP Savings Loop Exact (FOC) Examples
      • 1.3.1 Test FF_VFI_AZ_BISEC_LOOP Defaults
      • 1.3.2 Test FF_VFI_AZ_BISEC_LOOP Speed Tests
      • 1.3.3 Test FF_VFI_AZ_BISEC_LOOP Control Outputs
      • 1.3.4 Test FF_VFI_AZ_BISEC_LOOP Change Interest Rate and Discount
      • 1.3.5 Test FF_VFI_AZ_BISEC_LOOP Changing Risk Aversion
      • 1.3.6 Test FF_VFI_AZ_BISEC_LOOP with Higher Uncertainty
    • 1.4 FF_VFI_AZ_BISEC_VEC Savings Vectorized Exact (FOC) Examples
      • 1.4.1 Test FF_VFI_AZ_BISEC_VEC Defaults
      • 1.4.2 Test FF_VFI_AZ_BISEC_VEC Speed Tests
      • 1.4.3 Test FF_VFI_AZ_BISEC_VEC Control Outputs
      • 1.4.4 Test FF_VFI_AZ_BISEC_VEC Change Interest Rate and Discount
      • 1.4.5 Test FF_VFI_AZ_BISEC_VEC Changing Risk Aversion
      • 1.4.6 Test FF_VFI_AZ_BISEC_VEC with Higher Uncertainty
    • 1.5 FF_VFI_AZ_MZOOM_LOOP Savings Loop Exact (VALUE) Examples
      • 1.5.1 Test FF_VFI_AZ_MZOOM_LOOP Defaults
      • 1.5.2 Test FF_VFI_AZ_MZOOM_LOOP Speed Tests
      • 1.5.3 Test FF_VFI_AZ_MZOOM_LOOP Control Outputs
      • 1.5.4 Test FF_VFI_AZ_MZOOM_LOOP Change Interest Rate and Discount
      • 1.5.5 Test FF_VFI_AZ_MZOOM_LOOP Changing Risk Aversion
      • 1.5.6 Test FF_VFI_AZ_MZOOM_LOOP with Higher Uncertainty
    • 1.6 FF_VFI_AZ_MZOOM_VEC Savings Vectorized Exact (VALUE) Examples
      • 1.6.1 Test FF_VFI_AZ_MZOOM_VEC Defaults
      • 1.6.2 Test FF_VFI_AZ_MZOOM_VEC Speed Tests
      • 1.6.3 Test FF_VFI_AZ_MZOOM_VEC Control Outputs
      • 1.6.4 Test FF_VFI_AZ_MZOOM_VEC Change Interest Rate and Discount
      • 1.6.5 Test FF_VFI_AZ_MZOOM_VEC Changing Risk Aversion
      • 1.6.6 Test FF_VFI_AZ_MZOOM_VEC with Higher Uncertainty
  • 2 Stationary Distribution
    • 2.1 FF_DS_AZ_LOOP Dynamic Savings Loop Discrete Distribution
      • 2.1.1 Test FF_DS_AZ_LOOP Defaults
      • 2.1.2 Test FF_DS_AZ_LOOP Speed Tests
      • 2.1.3 Test FF_DS_AZ_LOOP A grid 100 Shock grid 7
      • 2.1.4 Test FF_DS_AZ_LOOP A grid 300 Shock Grid 25
      • 2.1.5 Test FF_DS_AZ_LOOP A grid 300 Shock Grid 50
    • 2.2 FF_DS_AZ_CTS_LOOP Dynamic Savings Loop Continuous Distribution
      • 2.2.1 Test FF_DS_AZ_CTS_LOOP Defaults
      • 2.2.2 Test FF_DS_AZ_CTS_LOOP Speed Tests
      • 2.2.3 Test FF_DS_AZ_CTS_LOOP A grid 100 Shock grid 7
      • 2.2.4 Test FF_DS_AZ_CTS_LOOP A grid 300 Shock grid 25
      • 2.2.5 Test FF_DS_AZ_CTS_LOOP A grid 300 Shock grid 50
    • 2.3 FF_DS_AZ_CTS_VEC Dynamic Savings Vectorized Continuous Distribution
      • 2.3.1 Test FF_DS_AZ_CTS_VEC Defaults
      • 2.3.2 Test FF_DS_AZ_CTS_VEC Speed Tests
      • 2.3.3 Test FF_DS_AZ_CTS_VEC A grid 100 Shock grid 7
      • 2.3.4 Test FF_DS_AZ_CTS_VEC A grid 300 Shock grid 25
      • 2.3.5 Test FF_DS_AZ_CTS_VEC A grid 300 Shock grid 50
  • 3 Summarize Policy and Value
    • 3.1 FF_SUMM_ND_ARRAY Examples
      • 3.1.1 Test FF_SUMM_ND_ARRAY Defaults
      • 3.1.2 Test FF_SUMM_ND_ARRAY with Random 2 Dimensional Matrix
      • 3.1.3 Test FF_SUMM_ND_ARRAY with Random 6 Dimensional Matrix
      • 3.1.4 Test FF_SUMM_ND_ARRAY with Random 7 Dimensional Matrix with All Parameters
  • 4 Distributional Analysis
    • 4.1 FF_SIMU_STATS Examples
      • 4.1.1 Test FF_SIMU_STATS Defaults
      • 4.1.2 Test FF_SIMU_STATS Four States-Points Matrix
      • 4.1.3 Test FF_SIMU_STATS Four States-Points Matrix Single Column Inputs
      • 4.1.4 Test FF_SIMU_STATS Print Many Details
    • 4.2 FF_DISC_RAND_VAR_STATS Examples
      • 4.2.1 Test FF_DISC_RAND_VAR_STATS Defaults
      • 4.2.2 Test FF_DISC_RAND_VAR_STATS 0 and 1 Random Variable
      • 4.2.3 Test FF_DISC_RAND_VAR_STATS with Poisson
    • 4.3 FF_DISC_RAND_VAR_MASS2OUTCOMES Examples
      • 4.3.1 Test FF_DISC_RAND_VAR_MASS2OUTCOMES Defaults
      • 4.3.2 Test FF_DISC_RAND_VAR_MASS2OUTCOMES Four States-Points
      • 4.3.3 Test FF_DISC_RAND_VAR_MASS2OUTCOMES Conditional Mass Outputs
    • 4.4 FF_DISC_RAND_VAR_MASS2COVCOR Examples
      • 4.4.1 Test FF_DISC_RAND_VAR_MASS2COVCOR Defaults
      • 4.4.2 Test FF_DISC_RAND_VAR_MASS2COVCOR Four States-Points
      • 4.4.3 Test FF_DISC_RAND_VAR_MASS2COVCOR Two Random Vectors
      • 4.4.4 Test FF_DISC_RAND_VAR_MASS2COVCOR Provide Mean and SD
  • 5 Optimizers
    • 5.1 faFF_OPTIM_BISEC_SAVEZRONE Derivative Bisection
      • 5.1.1 Test FF_OPTIM_BISEC_SAVEZRONE Defaults
      • 5.1.2 Test FF_OPTIM_BISEC_SAVEZRONE One Individual
      • 5.1.3 Test FF_OPTIM_BISEC_SAVEZRONE Six Individual States
      • 5.1.4 Test FF_OPTIM_BISEC_SAVEZRONE Speed
      • 5.1.5 Define Two Period Intertemporal FOC Log Utility No Shock
    • 5.2 FF_OPTIM_MLSEC_SAVEZRONE Derivative Multisection
      • 5.2.1 Test FF_OPTIM_MLSEC_SAVEZRONE One Individual
      • 5.2.2 Test FF_OPTIM_MLSEC_SAVEZRONE 5 Individuals 5 Iterations 5 Points Per Iteration
      • 5.2.3 Test FF_OPTIM_MLSEC_SAVEZRONE 8 Individuals 3 Iterations 10 Points Per Iteration
      • 5.2.4 Test FF_OPTIM_MLSEC_SAVEZRONE Speed
      • 5.2.5 Define Two Period Intertemporal FOC Log Utility No Shock
    • 5.3 FF_OPTIM_MZOOM_SAVEZRONE Derivative Multisection
      • 5.3.1 Test FF_OPTIM_MZOOM_SAVEZRONE One Individual
      • 5.3.2 Test FF_OPTIM_MZOOM_SAVEZRONE 4 Individuals 3 Iterations 50 Points Per Iteration
      • 5.3.3 Test FF_OPTIM_MZOOM_SAVEZRONE 8 Individuals 3 Iterations 10 Points Per Iteration, 0.25 zoom in ratio
      • 5.3.4 Test FF_OPTIM_MZOOM_SAVEZRONE Speed
      • 5.3.5 Define Two Period Intertemporal Log Utility No Shock Utility Function
  • 6 Graphs
    • 6.1 FF_GRAPH_GRID Examples: X, Y and Color Line Plots
      • 6.1.1 Test FF_GRAPH_GRID Defaults
      • 6.1.2 Test FF_GRAPH_GRID Random Matrix Pick Markers and Colors
      • 6.1.3 Test FF_GRAPH_GRID Two Random Normal Lines and Labels
      • 6.1.4 Test FF_GRAPH_GRID 6 Lines Pick Marker and Colors
      • 6.1.5 Test FF_GRAPH_GRID Many Lines
      • 6.1.6 Test FF_GRAPH_GRID Many Lines Legend Exogenous
      • 6.1.7 Test FF_GRAPH_GRID Joint Probability Mass Output as Scatter Size
  • 7 Support Tools
    • 7.1 FF_CONTAINER_MAP_DISPLAY Examples
      • 7.1.1 Test FF_CONTAINER_MAP_DISPLAY Defaults
      • 7.1.2 Test FF_CONTAINER_MAP_DISPLAY summarize Matrix Only
      • 7.1.3 Test FF_CONTAINER_MAP_DISPLAY Show Matrix Subset
  • 8 Data Structures
    • 8.1 FF_SAVEBORR_GRID Example for Generating Asset Grid
      • 8.1.1 Test FF_SAVEBORR_GRID Defaults
      • 8.1.2 Test FF_SAVEBORR_GRID Default Linear Grid, Log Grid, Power Grid, Threshold Grid
      • 8.1.3 Test FF_SAVEBORR_GRID Log Grid Changing Parameters
      • 8.1.4 Test FF_SAVEBORR_GRID Power Grid Changing Parameters
      • 8.1.5 Test FF_SAVEBORR_GRID Threshold Grid Changing Parameters
    • 8.2 FX_PERTURB_LOGN Perturb Parameter with Logn Scalar
      • 8.2.1 Test FX_PERTURB_LOGN Defaults
      • 8.2.2 Test FX_PERTURB_LOGN with Different Draws and How much to Perturb
    • 8.3 FF_SAVEBORR_GRID Example for Generating Asset Grid
      • 8.3.1 Test FF_NONIMG_POSNEGBD Defaults
      • 8.3.2 Test FF_NONIMG_POSNEGBD with Log(x)
  • 9 Common Functions
    • 9.1 FFY_TAUCHEN AR1 Shock Discretization Example
      • 9.1.1 Test FFY_TAUCHEN Defaults
      • 9.1.2 Test FFY_TAUCHEN Specify Parameters
      • 9.1.3 Test FFY_TAUCHEN High Persistence, Low SD
      • 9.1.4 Test FFY_TAUCHEN Low Persistence, Low SD
      • 9.1.5 Test FFY_TAUCHEN High Persistence, High SD
      • 9.1.6 Test FFY_TAUCHEN Low Persistence, Low SD
    • 9.2 FFY_ROUWENHORST AR1 Shock Discretization Example
      • 9.2.1 Test FFY_ROUWENHORST Defaults
      • 9.2.2 Test FFY_ROUWENHORST Specify Parameters
      • 9.2.3 Test FFY_ROUWENHORST High Persistence, Low SD
      • 9.2.4 Test FFY_ROUWENHORST Low Persistence, Low SD
      • 9.2.5 Test FFY_ROUWENHORST High Persistence, High SD
      • 9.2.6 Test FFY_ROUWENHORST Low Persistence, Low SD
  • 10 System
    • 10.1 FF_FIND_FILES Examples
      • 10.1.1 Test FF_FIND_FILES Defaults
      • 10.1.2 Test FF_FIND_FILES search for files in subfolders
    • 10.2 FF_MLX2HTMLPDF_RUNANDEXPORT Examples
      • 10.2.1 Test FF_MLX2HTMLPDF_RUNANDEXPORT search for MLX files and Convert to HTML
      • 10.2.2 Test FF_MLX2HTMLPDF_RUNANDEXPORT re-run MLX
  • Appendix
  • A Index and Code Links
    • A.1 Savings Dynamic Programming links
    • A.2 Stationary Distribution links
    • A.3 Summarize Policy and Value links
    • A.4 Distributional Analysis links
    • A.5 Optimizers links
    • A.6 Graphs links
    • A.7 Support Tools links
    • A.8 Data Structures links
    • A.9 Common Functions links
    • A.10 System links
  • M4Econ Bookdown

Matlab Toolbox Heterogeneous Agents Dynamic Programming

A Index and Code Links

A.1 Savings Dynamic Programming links

  1. Looped Grid Infinite Horizon Dynamic Savings Problem: mlx | m | pdf | html
    • Infinite horizon constrained dynamic savings problem with persistent shock.
    • The state-space and choice-space share the same asset grid.
    • Looped algorithm, slow but easy to modify, useful for developing new models.
    • MEconTools: ff_vfi_az_loop()
  2. Vectorized Grid Infinite Horizon Dynamic Savings Problem: mlx | m | pdf | html
    • Vectorized version of ff_vfi_az_loop(), fast and sufficiently approximate value(a,z), but choices not precise.
    • Broadcast and vectorized evaluation and maximization.
    • Solve u(c) once, and retrieve with cell arrays.
    • MEconTools: ff_vfi_az_vec()
  3. Looped Exact FOC Infinite Horizon Dynamic Savings Problem: mlx | m | pdf | html
    • Infinite horizon constrained dynamic savings problem with persistent shock.
    • The state-space is on a grid, the choice space are continuous percentages of cash-on-hand.
    • Looped exact savings-percentage algorithm, slow but high precision at low grid size.
    • Solves for EV(ap,z) given shock state and for a savings choice. Bisection based on FOC with analytical du(c(ap))/dap and spline slopes dEV(ap,z)/dap.
    • MEconTools: ff_vfi_az_bisec_loop() + ff_optim_bisec_savezrone()
  4. Vectorized Exact FOC Infinite Horizon Dynamic Savings Problem: mlx | m | pdf | html
    • Vectorized version of ff_vfi_az_bisec_loop() exact savings-percentage algorithm, high precision and high speed.
    • MEconTools: ff_vfi_az_bisec_vec() + ff_optim_bisec_savezrone()
  5. Looped Exact Value Infinite Horizon Dynamic Savings Problem: mlx | m | pdf | html
    • Looped infinite horizon constrained dynamic savings problem with persistent shock.
    • The state-space is on a grid, the choice space are continuous percentages of cash-on-hand.
    • Evaluate value at choice grid iteratively by zooming-in to construct finer savings percentages.
    • MEconTools: ff_vfi_az_mzoom_loop() + ff_optim_mzoom_savezrone()
  6. Vectorized Exact Value Infinite Horizon Dynamic Savings Problem: mlx | m | pdf | html
    • Vectorized version of ff_vfi_az_mzoom_loop() exact savings-percentage algorithm.
    • MEconTools: ff_vfi_az_mzoom_vec() + ff_optim_mzoom_savezrone()

A.2 Stationary Distribution links

  1. Looped Grid Stationary Distribution Dynamic Savings Problem: mlx | m | pdf | html
    • Stationary distribution for infinite horizon constrained dynamic savings problem with persistent shock.
    • The state-space and choice-space share the same asset grid.
    • Looped algorithm.
    • MEconTools: ff_ds_az_loop()
  2. Looped Exact Stationary Distribution Dynamic Savings Problem: mlx | m | pdf | html
    • Stationary distribution for infinite horizon constrained dynamic savings problem with persistent shock.
    • The state-space is on a grid, the choice space are continuous percentages of cash-on-hand.
    • Looped algorithm.
    • MEconTools: ff_ds_az_cts_loop()
  3. Vectorized Exact Stationary Distribution Dynamic Savings Problem: mlx | m | pdf | html
    • This is the vectorized version of ff_ds_az_cts_loop().
    • MEconTools: ff_ds_az_cts_vec(8)

A.3 Summarize Policy and Value links

  1. Summarize ND Array Policy and Value Functions: mlx | m | pdf | html
    • Given an NDarray matrix with N1, N2, …, ND dimensions. Generate average and standard deviation for the 3rd dimension, grouping by the other dimensions.
    • For example, show the 5th dimension as the column groups, and the other variables generate combinations shown as rows.
    • The resulting summary statistics table contains mean and standard deviation among other statistics over the policy or value contained in the ND array.
    • MEconTools: ff_summ_nd_array()

A.4 Distributional Analysis links

  1. Gateway Joint Probability Mass Statistics: mlx | m | pdf | html
    • Given model policy functions and stationary distribution, compute distributional statistics.
    • Given discrete probability mass function f(s), and information y(s), x(s), z(s) at each element of the state-space, compute statistics for each variable, y, x, z, which are all discrete random variables.
    • Compute correlation and covariance betwen input discrete random variables.
    • MEconTools: ff_simu_stats()
  2. Discrete Random Variable Distributional Statistics: mlx | m | pdf | html
    • Model simulation generates discrete random variables, calculate mean, standard deviation, min, max, percentiles, and proportion of outcomes held by x percentiles, etc.
    • MEconTools: ff_disc_rand_var_stats()
  3. Generate Discrete Random Variable: mlx | m | pdf | html
    • Given mass at state space points, and y, c, a, z and other outcomes or other information at each corresponding state space points, generate discrete random variable, with unique sorted values, and mass for each unique sorted values.
    • Generate additional joint distributions: if initial distribution is over f(a,z), generate joint distribution of f(y,a) or f(y,z).
    • MEconTools: ff_disc_rand_var_mass2outcomes()
  4. Discrete Random Variable Correlation and Covariance: mlx | m | pdf | html
    • Given probability mass function f(s), X(s), and Y(s), compute the covariance and correlation betwen X and Y.
    • MEconTools: ff_disc_rand_var_mass2covcor()

A.5 Optimizers links

  1. Bisection Exact Optimal Savings Share Multiple States: mlx | m | pdf | html
    • Given a First Order Condition function handle that takes the fraction of resources (cash-on-hand) saved as the input, solve for the optimal savings fraction via bisection. Solve this concurrently for many elements of the state-space. The function handle contains the FOC with parameters and state-space elements embeded.
    • MEconTools: ff_optim_bisec_savezrone()
  2. Multisection Exact Optimal Savings Share Multiple States: mlx | m | pdf | html
    • Given a First Order Condition function handle that takes the fraction of resources (cash-on-hand) saved as the input, solve for the optimal savings fraction via multisection where there are multiple evaluations per iteration of the FOC. Solve this concurrently for many elements of the state-space. The function handle contains the FOC with parameters and state-space elements embeded.
    • MEconTools: ff_optim_mlsec_savezrone()
  3. Vectorized Zooming Exact Optimal Savings Share Multiple States: mlx | m | pdf | html
    • Given a Utility (not FOC) function handle that takes the fraction of resources (cash-on-hand) saved as the input, solve for the optimal savings fraction via iterative zooming where there are multiple evaluations per iteration of the utility function. Solve this concurrently for many elements of the state-space. The function handle contains the utilty function with parameters and state-space elements embeded.
    • MEconTools: ff_optim_mzoom_savezrone()

A.6 Graphs links

  1. Multiple Line Graph Function: mlx | m | pdf | html
    • Policy and Value Function graphs, x-axis one state, color another state, y-axis are value and policies.
    • Distributional graphs, x-axis one state, y-axis and color another state, size show distributional mass.
    • MEconTools: ff_graph_grid()

A.7 Support Tools links

  1. Organizes and Prints Container Map Key and Values: mlx | m | pdf | html
    • Summarizes the contents of a map container by data types. Includes, scalar, array, matrix, string, functions, tensors (3-tuples), tesseracts (4-tuples).
    • MEconTools: ff_container_map_display()

A.8 Data Structures links

  1. Log and Power Spaced Asset and Choice Grids: mlx | m | pdf | html
    • Generate linear, log-space, power-space, or threshold-cut asset or choice grids.
    • MEconTools: ff_saveborr_grid()
  2. Randomly Perturb Some Parameter Value with Varying Magnitudes: mlx | m | pdf | html
    • There is a starting estimation parameter value, perturb this initial starting points. Use a scalar so that 0 means almost no change, and 1 means maximum change to control how much to perturb the parameter. This is used for multi-start estimation
    • MEconTools: ff_perturb_logn()
  3. Find Real-valued Domain of a Function: mlx | m | pdf | html
    • Checks for valid domain for function that generates real-valued outcomes, and identifies values along the domain that generates positive and negative Values.
    • MEconTools: ff_nonimg_posnegbd()

A.9 Common Functions links

  1. Discretize AR1 Normal Shock Tauchen (1986): mlx | m | pdf | html
    • Mean zero AR(1) shock discretize following Tauchen (1986).
    • MEconTools: ffy_tauchen()
  2. Discretize AR1 Normal Shock Rouwenhorst (1995): mlx | m | pdf | html
    • Mean zero AR(1) shock discretize following Rouwenhorst (1995).
    • MEconTools: ffy_rouwenhorst()

A.10 System links

  1. Search and Find File Names: mlx | m | pdf | html
    • Search and find file names.
    • MEconTools: ff_find_files()
  2. Execute and Export Livescript Files: mlx | m | pdf | html
    • Find livescript (mlx) files, execute MLX files, and export MLX files to HTML in a different folder.
    • MEconTools: ff_mlx2htmlpdf_runandexport()
The MathWorks Inc. 2019. MATLAB. https://www.mathworks.com/products/matlab.html.
Xie, Yihui. 2020. Bookdown: Authoring Books and Technical Documents with r Markdown. https://CRAN.R-project.org/package=bookdown.