Chapter 2 Stationary Distribution
2.1 FF_DS_AZ_LOOP Dynamic Savings Loop Discrete Distribution
Go back to fan’s MEconTools Toolbox (bookdown), Matlab Code Examples Repository (bookdown), or Math for Econ with Matlab Repository (bookdown).
Examples](https://fanwangecon.github.io/M4Econ/), or** Dynamic Asset This is the example vignette for function: ff_ds_az_loop from the MEconTools Package. F(a,z) discrete probability mass function given policy function solution with discretized savings choices.
Distribution for Common Choice and States Grid Loop: ff_ds_az_cts_loop
Distribution for States Grid + Continuous Exact Savings as Share of Cash-on-Hand Loop: ff_ds_az_cts_loop
Distribution for States Grid + Continuous Exact Savings as Share of Cash-on-Hand Vectorized: ff_ds_az_cts_vec
2.1.1 Test FF_DS_AZ_LOOP Defaults
Call the function with defaults. By default, shows the asset policy function summary. Model parameters can be changed by the mp_params.
%mp_params
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('fl_crra') = 1.5;
mp_params('fl_beta') = 0.94;
% call function
ff_ds_az_loop(mp_params);
Elapsed time is 0.191238 seconds.
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CONTAINER NAME: mp_ffcmd ND Array (Matrix etc)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx ndim numel rowN colN sum mean std coefvari min max
_ ___ ____ _____ ____ ____ ______ ______ ______ ________ ___ ___
ap 1 1 2 700 100 7 9855.1 14.079 14.408 1.0234 0 50
xxx TABLE:ap xxxxxxxxxxxxxxxxxx
c1 c2 c3 c4 c5 c6 c7
______ ______ ______ ________ _______ _______ ______
r1 0 0 0 0.045213 0.25576 0.61095 1.0362
r2 0 0 0 0.045213 0.25576 0.61095 1.0362
r3 0 0 0 0.045213 0.25576 0.61095 1.0362
r4 0 0 0 0.06647 0.25576 0.61095 1.0362
r5 0 0 0 0.06647 0.25576 0.61095 1.164
r96 43.924 43.924 43.924 43.924 43.924 45.102 45.102
r97 45.102 45.102 45.102 45.102 45.102 46.298 46.298
r98 46.298 46.298 46.298 46.298 46.298 47.513 47.513
r99 47.513 47.513 47.513 47.513 47.513 48.747 48.747
r100 48.747 48.747 48.747 48.747 48.747 50 50
FF_DS_AZ_LOOP finished. Distribution took = 0.14487
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CONTAINER NAME: mp_ddcmd ND Array (Matrix etc)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx ndim numel rowN colN sum mean std coefvari min max
_ ___ ____ _____ ____ ____ ___ _________ _________ ________ ________ ________
fa 1 1 2 100 100 1 1 0.01 0.016114 1.6114 0 0.121
faz 2 2 2 700 100 7 1 0.0014286 0.0035847 2.5093 0 0.052693
fz 3 3 2 7 7 1 1 0.14286 0.11742 0.82196 0.015625 0.3125
xxx TABLE:fa xxxxxxxxxxxxxxxxxx
c1
__________
r1 0.121
r2 0.00034068
r3 0
r4 0.010458
r5 0.0048751
r96 1.1148e-21
r97 3.227e-22
r98 7.9165e-23
r99 1.4982e-23
r100 1.7037e-24
xxx TABLE:faz xxxxxxxxxxxxxxxxxx
c1 c2 c3 c4 c5 c6 c7
__________ __________ __________ __________ __________ __________ __________
r1 0.0084023 0.03778 0.052693 0.018985 0.0029243 0.00020787 5.6301e-06
r2 0.00018105 0.0001207 3.3528e-05 4.9671e-06 4.1392e-07 1.8397e-08 3.4068e-10
r3 0 0 0 0 0 0 0
r4 0.00016518 0.002081 0.005593 0.0022334 0.00035834 2.6032e-05 7.146e-07
r5 0.00021881 0.00067299 0.0026761 0.0011123 0.00018127 1.3278e-05 3.6641e-07
r96 1.7183e-25 2.8942e-24 2.2565e-23 1.0675e-22 3.1764e-22 4.9586e-22 1.6895e-22
r97 3.2228e-26 6.111e-25 5.3384e-24 2.7969e-23 9.0055e-23 1.4769e-22 5.1004e-23
r98 4.5065e-27 1.0023e-25 1.0174e-24 6.0677e-24 2.15e-23 3.7371e-23 1.3103e-23
r99 3.8775e-28 1.0954e-26 1.38e-25 9.8022e-25 3.9213e-24 7.3193e-24 2.6118e-24
r100 1.1692e-29 5.3148e-28 9.7109e-27 8.9563e-26 4.2252e-25 8.6574e-25 3.1562e-25
xxx TABLE:fz xxxxxxxxxxxxxxxxxx
c1
________
r1 0.015625
r2 0.09375
r3 0.23438
r4 0.3125
r5 0.23438
r6 0.09375
r7 0.015625
2.1.2 Test FF_DS_AZ_LOOP Speed Tests
Call the function with different a and z grid size, print out speed:
mp_support = containers.Map('KeyType','char', 'ValueType','any');
mp_support('bl_timer') = true;
mp_support('ls_ffcmd') = {};
mp_support('ls_ddcmd') = {};
mp_support('ls_ddgrh') = {};
mp_support('bl_show_stats_table') = false;
% A grid 50, shock grid 5:
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 50;
mp_params('it_z_n') = 5;
ff_ds_az_loop(mp_params, mp_support);
Elapsed time is 0.021787 seconds.
FF_DS_AZ_LOOP finished. Distribution took = 0.046636
% A grid 100, shock grid 7:
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 100;
mp_params('it_z_n') = 7;
ff_ds_az_loop(mp_params, mp_support);
Elapsed time is 0.218465 seconds.
FF_DS_AZ_LOOP finished. Distribution took = 0.13608
% A grid 200, shock grid 9:
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 200;
mp_params('it_z_n') = 9;
ff_ds_az_loop(mp_params, mp_support);
Elapsed time is 0.489370 seconds.
FF_DS_AZ_LOOP finished. Distribution took = 0.35393
2.1.3 Test FF_DS_AZ_LOOP A grid 100 Shock grid 7
Call the function with different a and z grid size, print out speed:
mp_support = containers.Map('KeyType','char', 'ValueType','any');
mp_support('bl_timer') = true;
mp_support('ls_ffcmd') = {};
mp_support('ls_ddcmd') = {};
mp_support('ls_ddgrh') = {'faz','fa'};
mp_support('bl_show_stats_table') = true;
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 100;
mp_params('it_z_n') = 7;
ff_ds_az_loop(mp_params, mp_support);
Elapsed time is 0.217312 seconds.
FF_DS_AZ_LOOP finished. Distribution took = 0.1105
xxx tb_outcomes: all stats xxx
OriginalVariableNames ap v c y coh savefraccoh
______________________ __________ __________ __________ __________ __________ ___________
{'mean' } 2.7094 6.6576 1.5089 1.5084 4.2183 0.48487
{'unweighted_sum' } 1439.4 7299.4 1545.9 1473.6 11549 479.94
{'sd' } 2.8976 2.0599 0.35843 0.52611 3.2096 0.25477
{'coefofvar' } 1.0694 0.3094 0.23755 0.34879 0.76088 0.52544
{'gini' } 0.53346 0.17414 0.13326 0.19097 0.39103 0.29771
{'min' } 0 1.6927 0.58543 0.58543 0.58543 0
{'max' } 50 19.139 4.9969 4.9969 54.997 0.93121
{'pYis0' } 0.070216 0 0 0 0 0.070216
{'pYls0' } 0 0 0 0 0 0
{'pYgr0' } 0.92978 1 1 1 1 0.92978
{'pYisMINY' } 0.070216 0.0057675 0.0057675 0.0057675 0.0057675 0.070216
{'pYisMAXY' } 2.1143e-10 3.7149e-11 3.7149e-11 3.7149e-11 3.7149e-11 2.065e-11
{'p0_01' } 0 1.6927 0.58543 0.58543 0.58543 0
{'p0_1' } 0 1.6927 0.58543 0.58543 0.58543 0
{'p1' } 0 2.7674 0.76855 0.61362 0.76855 0
{'p5' } 0 3.273 0.91608 0.77504 1.009 0
{'p10' } 0.06647 4.0961 1.0308 0.92803 1.1055 0.067651
{'p20' } 0.37601 4.8781 1.2371 1.0319 1.555 0.22796
{'p25' } 0.52503 5.2636 1.2781 1.0731 1.8354 0.28067
{'p30' } 0.7048 5.4822 1.3424 1.1472 2.0866 0.35907
{'p40' } 1.3008 6.0574 1.3953 1.3424 2.6774 0.48584
{'p50' } 1.9422 6.542 1.4931 1.4023 3.3444 0.54915
{'p60' } 2.5275 7.1265 1.6174 1.4954 4.1208 0.60499
{'p70' } 3.456 7.657 1.6502 1.7803 5.1554 0.67918
{'p75' } 3.9869 8.0469 1.733 1.824 5.7555 0.69673
{'p80' } 4.564 8.4125 1.8179 1.8875 6.1793 0.72076
{'p90' } 6.5844 9.3821 1.9734 2.3349 8.568 0.76882
{'p95' } 8.1844 10.225 2.1388 2.4776 10.358 0.80411
{'p99' } 13.136 11.834 2.3359 3.1677 15.511 0.85404
{'p99_9' } 18.839 13.486 2.7733 3.4782 21.332 0.88316
{'p99_99' } 21.778 14.354 3.0939 3.7505 24.78 0.89063
{'fl_cov_ap' } 8.396 5.2587 0.88866 0.93721 9.2847 0.58458
{'fl_cor_ap' } 1 0.88106 0.85565 0.61478 0.99833 0.7919
{'fl_cov_v' } 5.2587 4.243 0.71989 0.93806 5.9786 0.453
{'fl_cor_v' } 0.88106 1 0.97505 0.86559 0.90428 0.86321
{'fl_cov_c' } 0.88866 0.71989 0.12847 0.15253 1.0171 0.079518
{'fl_cor_c' } 0.85565 0.97505 1 0.80886 0.88413 0.8708
{'fl_cov_y' } 0.93721 0.93806 0.15253 0.2768 1.0897 0.080824
{'fl_cor_y' } 0.61478 0.86559 0.80886 1 0.64534 0.603
{'fl_cov_coh' } 9.2847 5.9786 1.0171 1.0897 10.302 0.6641
{'fl_cor_coh' } 0.99833 0.90428 0.88413 0.64534 1 0.81215
{'fl_cov_savefraccoh'} 0.58458 0.453 0.079518 0.080824 0.6641 0.064906
{'fl_cor_savefraccoh'} 0.7919 0.86321 0.8708 0.603 0.81215 1
{'fracByP0_01' } 0 0.0014664 0.0022377 0.0022385 0.00080043 0
{'fracByP0_1' } 0 0.0014664 0.0022377 0.0022385 0.00080043 0
{'fracByP1' } 0 0.0029302 0.01567 0.00403 0.0055106 0
{'fracByP5' } 0 0.021763 0.026172 0.02466 0.015702 0
{'fracByP10' } 0.0004071 0.050764 0.058937 0.05144 0.022123 0.0021411
{'fracByP20' } 0.0096198 0.1171 0.13549 0.11855 0.05416 0.033082
{'fracByP25' } 0.017608 0.15851 0.17677 0.15694 0.074837 0.057303
{'fracByP30' } 0.02761 0.19906 0.21973 0.19018 0.09783 0.092029
{'fracByP40' } 0.071719 0.28454 0.3135 0.28477 0.15542 0.18016
{'fracByP50' } 0.15388 0.38017 0.40577 0.38385 0.23227 0.28549
{'fracByP60' } 0.21684 0.48325 0.51534 0.46249 0.31381 0.4039
{'fracByP70' } 0.32573 0.59393 0.62048 0.57438 0.42716 0.54543
{'fracByP75' } 0.39815 0.65416 0.68002 0.63899 0.4882 0.60905
{'fracByP80' } 0.48482 0.72413 0.732 0.69931 0.55881 0.6822
{'fracByP90' } 0.6819 0.84902 0.85906 0.8281 0.73338 0.83355
{'fracByP95' } 0.79123 0.91664 0.92592 0.90812 0.83969 0.91574
{'fracByP99' } 0.9433 0.98136 0.98418 0.97889 0.95655 0.98225
{'fracByP99_9' } 0.99595 0.99805 0.99819 0.99776 0.99501 0.99858
{'fracByP99_99' } 0.99934 0.99982 0.99985 0.9998 0.99938 0.99984
2.1.4 Test FF_DS_AZ_LOOP A grid 300 Shock Grid 25
mp_support = containers.Map('KeyType','char', 'ValueType','any');
mp_support('bl_timer') = true;
mp_support('ls_ffcmd') = {};
mp_support('ls_ddcmd') = {};
mp_support('ls_ddgrh') = {'faz','fa'};
mp_support('bl_show_stats_table') = true;
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 300;
mp_params('it_z_n') = 25;
ff_ds_az_loop(mp_params, mp_support);
Elapsed time is 1.356902 seconds.
FF_DS_AZ_LOOP finished. Distribution took = 1.3706
xxx tb_outcomes: all stats xxx
OriginalVariableNames ap v c y coh savefraccoh
______________________ __________ __________ __________ __________ __________ ___________
{'mean' } 3.1835 6.9106 1.5286 1.5274 4.7121 0.52236
{'unweighted_sum' } 4296.5 79518 16864 19751 1.2716e+05 5295.3
{'sd' } 3.2831 2.152 0.35175 0.53521 3.5973 0.25161
{'coefofvar' } 1.0313 0.31141 0.2301 0.35041 0.76341 0.48168
{'gini' } 0.52466 0.17565 0.12887 0.19155 0.39536 0.26998
{'min' } 0 -2.7621 0.25871 0.25871 0.25871 0
{'max' } 50 20.027 8.7798 8.7798 58.78 0.93152
{'pYis0' } 0.050267 0 0 0 0 0.050267
{'pYls0' } 0 7.4299e-05 0 0 0 0
{'pYgr0' } 0.94973 0.99993 1 1 1 0.94973
{'pYisMINY' } 0.050267 3.1587e-08 3.1587e-08 3.1587e-08 3.1587e-08 0.050267
{'pYisMAXY' } 2.3964e-09 9.6288e-14 9.6288e-14 9.6288e-14 9.6288e-14 2.6173e-22
{'p0_01' } 0 0.33524 0.44588 0.42089 0.44588 0
{'p0_1' } 0 1.0281 0.51088 0.51088 0.51088 0
{'p1' } 0 2.3294 0.67069 0.67069 0.67069 0
{'p5' } 0 3.531 0.9348 0.80006 1.0088 0
{'p10' } 0.10107 4.1808 1.0877 0.90775 1.2209 0.086874
{'p20' } 0.48982 5.0629 1.248 1.0638 1.7564 0.28154
{'p25' } 0.7256 5.3749 1.3048 1.157 2.0452 0.35473
{'p30' } 0.97897 5.7085 1.3561 1.192 2.3425 0.4186
{'p40' } 1.5756 6.2702 1.4389 1.3331 2.9951 0.51678
{'p50' } 2.2184 6.8025 1.5235 1.4352 3.7422 0.59639
{'p60' } 2.9972 7.3608 1.6237 1.5724 4.6044 0.65168
{'p70' } 4.012 7.977 1.7017 1.7487 5.6899 0.7051
{'p75' } 4.5871 8.3254 1.7349 1.8191 6.3522 0.72563
{'p80' } 5.3173 8.7116 1.8227 1.9222 7.1504 0.74857
{'p90' } 7.5009 9.7584 1.9829 2.2334 9.526 0.79537
{'p95' } 9.6743 10.633 2.1133 2.5088 11.809 0.82382
{'p99' } 14.854 12.286 2.3901 3.1545 17.176 0.86207
{'p99_9' } 21.166 14.023 2.7913 3.9726 23.779 0.88709
{'p99_99' } 26.803 15.357 3.0931 4.7968 29.914 0.89989
{'fl_cov_ap' } 10.779 6.2944 1.019 1.0643 11.798 0.64446
{'fl_cor_ap' } 1 0.89089 0.88234 0.60566 0.99894 0.78015
{'fl_cov_v' } 6.2944 4.6311 0.7528 0.97564 7.0472 0.46366
{'fl_cor_v' } 0.89089 1 0.9945 0.84708 0.91033 0.85631
{'fl_cov_c' } 1.019 0.7528 0.12373 0.15568 1.1427 0.077608
{'fl_cor_c' } 0.88234 0.9945 1 0.82696 0.90306 0.8769
{'fl_cov_y' } 1.0643 0.97564 0.15568 0.28645 1.2199 0.077311
{'fl_cor_y' } 0.60566 0.84708 0.82696 1 0.63363 0.57411
{'fl_cov_coh' } 11.798 7.0472 1.1427 1.2199 12.941 0.72207
{'fl_cor_coh' } 0.99894 0.91033 0.90306 0.63363 1 0.79776
{'fl_cov_savefraccoh'} 0.64446 0.46366 0.077608 0.077311 0.72207 0.063308
{'fl_cor_savefraccoh'} 0.78015 0.85631 0.8769 0.57411 0.79776 1
{'fracByP0_01' } 0 7.366e-06 9.1288e-05 2.5324e-05 2.9613e-05 0
{'fracByP0_1' } 0 0.00015226 0.00040756 0.00048297 0.00013202 0
{'fracByP1' } 0 0.0031657 0.0040997 0.0058265 0.0013172 0
{'fracByP5' } 0 0.020854 0.026015 0.023308 0.010613 0
{'fracByP10' } 0.0007829 0.049187 0.059665 0.051833 0.020313 0.0040897
{'fracByP20' } 0.010458 0.1169 0.13673 0.11782 0.052147 0.04121
{'fracByP25' } 0.020375 0.15489 0.17838 0.15407 0.072616 0.071271
{'fracByP30' } 0.033945 0.19501 0.22212 0.1924 0.09561 0.10878
{'fracByP40' } 0.076084 0.28102 0.3131 0.2752 0.15182 0.19951
{'fracByP50' } 0.13323 0.3766 0.41016 0.36618 0.22332 0.30599
{'fracByP60' } 0.21876 0.4783 0.51311 0.46472 0.31143 0.42495
{'fracByP70' } 0.32789 0.58936 0.62182 0.57246 0.4201 0.55532
{'fracByP75' } 0.39329 0.64823 0.67676 0.63063 0.48449 0.62358
{'fracByP80' } 0.47094 0.70976 0.73532 0.69204 0.55555 0.694
{'fracByP90' } 0.66575 0.84269 0.85851 0.82742 0.72907 0.84261
{'fracByP95' } 0.8001 0.91584 0.92543 0.90488 0.84038 0.91895
{'fracByP99' } 0.94734 0.98115 0.98337 0.97713 0.95746 0.98325
{'fracByP99_9' } 0.99324 0.99789 0.99809 0.99717 0.99445 0.9983
{'fracByP99_99' } 0.99909 0.99977 0.99979 0.99967 0.99931 0.99983
2.1.5 Test FF_DS_AZ_LOOP A grid 300 Shock Grid 50
mp_support = containers.Map('KeyType','char', 'ValueType','any');
mp_support('bl_timer') = true;
mp_support('ls_ffcmd') = {};
mp_support('ls_ddcmd') = {};
mp_support('ls_ddgrh') = {'faz','fa'};
mp_support('bl_show_stats_table') = true;
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 300;
mp_params('it_z_n') = 50;
ff_ds_az_loop(mp_params, mp_support);
Elapsed time is 3.256673 seconds.
FF_DS_AZ_LOOP finished. Distribution took = 3.3311
xxx tb_outcomes: all stats xxx
OriginalVariableNames ap v c y coh savefraccoh
______________________ __________ __________ __________ __________ __________ ___________
{'mean' } 3.26 6.9484 1.5319 1.5305 4.7919 0.52772
{'unweighted_sum' } 4296.5 1.6217e+05 35821 53309 2.6813e+05 10814
{'sd' } 3.3166 2.1606 0.35167 0.5364 3.6315 0.25217
{'coefofvar' } 1.0174 0.31094 0.22956 0.35048 0.75783 0.47785
{'gini' } 0.52112 0.17551 0.12829 0.19134 0.39468 0.26727
{'min' } 0 -7.6871 0.12843 0.12843 0.12843 0
{'max' } 50 20.751 15.657 15.657 65.657 0.93164
{'pYis0' } 0.049546 0 0 0 0 0.049546
{'pYls0' } 0 0.00011924 0 0 0 0
{'pYgr0' } 0.95045 0.99988 1 1 1 0.95045
{'pYisMINY' } 0.049546 1.1021e-15 1.1021e-15 1.1021e-15 1.1021e-15 0.049546
{'pYisMAXY' } 5.1436e-09 3.0978e-19 3.0978e-19 3.0978e-19 3.0978e-19 7.4151e-23
{'p0_01' } 0 -0.20486 0.40271 0.40271 0.40271 0
{'p0_1' } 0 1.2135 0.53589 0.488 0.53589 0
{'p1' } 0 2.3687 0.71312 0.64833 0.71312 0
{'p5' } 0.00050419 3.5428 0.94895 0.8071 0.96945 0.00055062
{'p10' } 0.11149 4.2401 1.0944 0.93681 1.2484 0.095151
{'p20' } 0.51629 5.0791 1.255 1.072 1.7729 0.28687
{'p25' } 0.75904 5.4237 1.3033 1.1504 2.067 0.36257
{'p30' } 1.0189 5.7339 1.3518 1.2006 2.3841 0.42942
{'p40' } 1.6286 6.2919 1.446 1.3198 3.0593 0.53021
{'p50' } 2.2834 6.8389 1.5355 1.4423 3.8053 0.59978
{'p60' } 3.0751 7.4137 1.613 1.5765 4.7113 0.65858
{'p70' } 4.1046 8.0318 1.7011 1.7318 5.8286 0.70939
{'p75' } 4.7891 8.3723 1.7435 1.8266 6.5055 0.73443
{'p80' } 5.5379 8.765 1.8035 1.9295 7.3201 0.75699
{'p90' } 7.6355 9.7879 1.9921 2.2457 9.6214 0.79808
{'p95' } 9.8311 10.68 2.1096 2.5308 11.976 0.82663
{'p99' } 14.653 12.305 2.407 3.1554 17.087 0.86199
{'p99_9' } 21.166 14.067 2.7771 4.0255 23.953 0.88705
{'p99_99' } 27.382 15.467 3.1325 4.887 30.554 0.90105
{'fl_cov_ap' } 11 6.3988 1.032 1.0771 12.032 0.65387
{'fl_cor_ap' } 1 0.89298 0.88481 0.60546 0.99898 0.78182
{'fl_cov_v' } 6.3988 4.668 0.75538 0.97839 7.1542 0.46619
{'fl_cor_v' } 0.89298 1 0.99418 0.84423 0.91183 0.85567
{'fl_cov_c' } 1.032 0.75538 0.12367 0.15613 1.1557 0.077331
{'fl_cor_c' } 0.88481 0.99418 1 0.82768 0.90493 0.87203
{'fl_cov_y' } 1.0771 0.97839 0.15613 0.28772 1.2333 0.076912
{'fl_cor_y' } 0.60546 0.84423 0.82768 1 0.63312 0.56861
{'fl_cov_coh' } 12.032 7.1542 1.1557 1.2333 13.188 0.7312
{'fl_cor_coh' } 0.99898 0.91183 0.90493 0.63312 1 0.79848
{'fl_cov_savefraccoh'} 0.65387 0.46619 0.077331 0.076912 0.7312 0.063589
{'fl_cor_savefraccoh'} 0.78182 0.85567 0.87203 0.56861 0.79848 1
{'fracByP0_01' } 0 -7.082e-06 2.6291e-05 3.0744e-05 8.4044e-06 0
{'fracByP0_1' } 0 8.1705e-05 0.00058298 0.00029929 0.00018591 0
{'fracByP1' } 0 0.0025872 0.0055744 0.0043199 0.0017463 0
{'fracByP5' } 5.9482e-08 0.02063 0.028475 0.023256 0.0085179 3.9707e-07
{'fracByP10' } 0.00083251 0.049013 0.059787 0.051875 0.020182 0.004399
{'fracByP20' } 0.01069 0.11692 0.13707 0.11785 0.051473 0.041367
{'fracByP25' } 0.021006 0.15459 0.17869 0.15432 0.071586 0.072106
{'fracByP30' } 0.034297 0.19493 0.22235 0.19226 0.095063 0.10998
{'fracByP40' } 0.076942 0.2811 0.31433 0.27537 0.15173 0.20135
{'fracByP50' } 0.13547 0.37553 0.41049 0.36597 0.22294 0.30799
{'fracByP60' } 0.21688 0.47822 0.51321 0.46464 0.31179 0.42743
{'fracByP70' } 0.32617 0.58918 0.6213 0.57279 0.42106 0.55684
{'fracByP75' } 0.40001 0.64825 0.67795 0.6311 0.48455 0.62544
{'fracByP80' } 0.47816 0.71036 0.73507 0.69272 0.55654 0.69664
{'fracByP90' } 0.67319 0.84299 0.85862 0.82739 0.73089 0.84294
{'fracByP95' } 0.80347 0.91616 0.92515 0.90483 0.84244 0.91987
{'fracByP99' } 0.94675 0.98117 0.98325 0.97691 0.95831 0.98345
{'fracByP99_9' } 0.99284 0.99789 0.9981 0.99713 0.99445 0.99831
{'fracByP99_99' } 0.99909 0.99977 0.99979 0.99966 0.9993 0.99983
2.2 FF_DS_AZ_CTS_LOOP Dynamic Savings Loop Continuous Distribution
Go back to fan’s MEconTools Toolbox (bookdown), Matlab Code Examples Repository (bookdown), or Math for Econ with Matlab Repository (bookdown).
Examples](https://fanwangecon.github.io/M4Econ/), or** Dynamic Asset This is the example vignette for function: ff_ds_az_cts_loop from the MEconTools Package. F(a,z) discrete probability mass function given policy function solution with continuous savings choices.
Distribution for Common Choice and States Grid Loop: ff_ds_az_cts_loop
Distribution for States Grid + Continuous Exact Savings as Share of Cash-on-Hand Loop: ff_ds_az_cts_loop
Distribution for States Grid + Continuous Exact Savings as Share of Cash-on-Hand Vectorized: ff_ds_az_cts_vec
2.2.1 Test FF_DS_AZ_CTS_LOOP Defaults
Call the function with defaults. By default, shows the asset policy function summary. Model parameters can be changed by the mp_params.
%mp_params
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('fl_crra') = 1.5;
mp_params('fl_beta') = 0.94;
% call function
ff_ds_az_cts_loop(mp_params);
Elapsed time is 1.912182 seconds.
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CONTAINER NAME: mp_ffcmd ND Array (Matrix etc)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx ndim numel rowN colN sum mean std coefvari min max
_ ___ ____ _____ ____ ____ _____ ______ ______ ________ ___ ______
ap 1 1 2 3000 200 15 42703 14.234 14.307 1.0051 0 51.591
xxx TABLE:ap xxxxxxxxxxxxxxxxxx
c1 c2 c3 c4 c5 c11 c12 c13 c14 c15
______ ______ ______ ______ ______ _______ _______ ______ ______ ______
r1 0 0 0 0 0 0.58655 0.89911 1.2884 1.7803 2.3861
r2 0 0 0 0 0 0.58671 0.89914 1.2885 1.7804 2.3862
r3 0 0 0 0 0 0.5871 0.89961 1.2888 1.7808 2.3867
r4 0 0 0 0 0 0.58803 0.90058 1.2898 1.7817 2.3877
r5 0 0 0 0 0 0.58953 0.90208 1.2914 1.7831 2.3891
r196 45.655 45.699 45.725 45.798 45.889 47.025 47.404 47.828 48.358 49.028
r197 46.257 46.303 46.326 46.401 46.492 47.626 48.005 48.432 48.965 49.651
r198 46.863 46.91 46.931 47.007 47.097 48.232 48.611 49.041 49.59 50.294
r199 47.472 47.521 47.542 47.617 47.711 48.843 49.222 49.658 50.235 50.94
r200 48.088 48.134 48.157 48.232 48.326 49.459 49.841 50.311 50.885 51.591
FF_DS_AZ_CTS_LOOP finished. Distribution took = 0.69766
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CONTAINER NAME: mp_ddcmd ND Array (Matrix etc)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx ndim numel rowN colN sum mean std coefvari min max
_ ___ ____ _____ ____ ____ ___ __________ _________ ________ __________ ________
fa 1 1 2 200 200 1 1 0.005 0.0096174 1.9235 0 0.11604
faz 2 2 2 3000 200 15 1 0.00033333 0.0011636 3.4908 0 0.032295
fz 3 3 2 15 15 1 1 0.066667 0.076895 1.1534 6.1035e-05 0.20947
xxx TABLE:fa xxxxxxxxxxxxxxxxxx
c1
__________
r1 0.11604
r2 0
r3 0.0004751
r4 0.00026799
r5 0.0029727
r196 3.5618e-14
r197 2.1735e-14
r198 1.329e-14
r199 8.3938e-15
r200 8.2751e-15
xxx TABLE:faz xxxxxxxxxxxxxxxxxx
c1 c2 c3 c4 c5 c11 c12 c13 c14 c15
__________ __________ __________ __________ __________ __________ __________ __________ __________ __________
r1 4.1559e-05 0.00053618 0.0031141 0.010616 0.023097 9.8338e-05 8.1894e-06 4.3385e-07 1.3284e-08 1.7934e-10
r2 0 0 0 0 0 0 0 0 0 0
r3 2.0452e-10 1.1226e-08 2.5837e-07 3.2065e-06 2.2865e-05 1.2294e-06 1.0693e-07 5.8481e-09 1.8347e-10 2.5249e-12
r4 8.6656e-10 2.8074e-08 3.684e-07 2.7287e-06 1.4098e-05 6.831e-07 5.9408e-08 3.249e-09 1.0193e-10 1.4026e-12
r5 9.2776e-08 2.9148e-06 3.479e-05 0.00019689 0.00056423 2.3628e-06 1.9305e-07 1.0072e-08 3.0458e-10 4.0697e-12
r196 1.6685e-22 7.5909e-21 1.5483e-19 1.8762e-18 1.5117e-17 7.3723e-15 8.1882e-15 6.5347e-15 3.3448e-15 8.2909e-16
r197 4.6363e-23 2.3916e-21 5.523e-20 7.5562e-19 6.8327e-18 4.5113e-15 5.0046e-15 4.0053e-15 2.0624e-15 5.148e-16
r198 8.2487e-24 4.9336e-22 1.3328e-20 2.1488e-19 2.2991e-18 2.8157e-15 3.0885e-15 2.4579e-15 1.2688e-15 3.1814e-16
r199 6.6913e-25 5.3279e-23 1.9003e-21 4.0019e-20 5.5219e-19 1.9017e-15 2.0244e-15 1.5281e-15 7.7436e-16 1.9614e-16
r200 2.8381e-26 2.725e-24 1.1911e-22 3.1319e-21 5.5136e-20 1.4819e-15 2.2618e-15 2.1457e-15 1.1964e-15 3.1409e-16
xxx TABLE:fz xxxxxxxxxxxxxxxxxx
c1
__________
r1 6.1035e-05
r2 0.00085449
r3 0.0055542
r4 0.022217
r5 0.061096
r11 0.061096
r12 0.022217
r13 0.0055542
r14 0.00085449
r15 6.1035e-05
xxx tb_outcomes: all stats xxx
OriginalVariableNames ap v c y coh savefraccoh
______________________ __________ ___________ __________ __________ __________ ___________
{'mean' } 1.675 5.0913 1.4673 1.467 3.1423 0.37474
{'unweighted_sum' } 42703 26797 7295.8 6979.8 49998 1657.9
{'sd' } 2.0062 1.7215 0.36267 0.51485 2.3189 0.24932
{'coefofvar' } 1.1977 0.33813 0.24717 0.35095 0.73794 0.66532
{'gini' } 0.59404 0.19113 0.13962 0.19161 0.37632 0.39022
{'min' } 0 -1.2641 0.38052 0.38052 0.38052 0
{'max' } 51.591 16.787 5.0209 6.6099 56.61 0.91805
{'pYis0' } 0.11606 0 0 0 0 0.11606
{'pYls0' } 0 0.00066766 0 0 0 0
{'pYgr0' } 0.88394 0.99933 1 1 1 0.88394
{'pYisMINY' } 0.11606 4.1559e-05 4.1559e-05 4.1559e-05 4.1559e-05 0.11606
{'pYisMAXY' } 3.1409e-16 3.1409e-16 5.148e-16 3.1409e-16 3.1409e-16 2.8381e-26
{'p0_01' } 0 -0.34507 0.45473 0.45473 0.45473 0
{'p0_1' } 0 0.52204 0.54342 0.54342 0.54342 0
{'p1' } 0 1.3412 0.6494 0.6494 0.6494 0
{'p5' } 0 2.1813 0.85431 0.77605 0.88697 0
{'p10' } 0 2.8514 0.96477 0.92741 1.002 0
{'p20' } 0.10665 3.5986 1.1516 1.0358 1.3244 0.083657
{'p25' } 0.21483 3.8501 1.2354 1.1105 1.4524 0.14274
{'p30' } 0.32994 4.2218 1.284 1.129 1.6395 0.20194
{'p40' } 0.60561 4.5759 1.3788 1.3244 1.999 0.30454
{'p50' } 0.9866 5.0443 1.4671 1.363 2.4484 0.39896
{'p60' } 1.4331 5.4957 1.5615 1.5828 2.9924 0.48032
{'p70' } 2.0261 5.9595 1.6562 1.6429 3.671 0.556
{'p75' } 2.4055 6.2377 1.7089 1.7094 4.0981 0.59225
{'p80' } 2.8929 6.5441 1.7669 1.9106 4.6329 0.62436
{'p90' } 4.3431 7.3623 1.9254 2.123 6.2699 0.69668
{'p95' } 5.7881 8.0262 2.0625 2.4019 7.7831 0.74075
{'p99' } 8.9453 9.2776 2.3421 2.9539 11.327 0.79763
{'p99_9' } 13.367 10.599 2.6636 3.7357 15.962 0.83767
{'p99_99' } 17.333 11.639 2.9483 4.3328 20.294 0.85903
{'fl_cov_ap' } 4.0248 2.8944 0.61038 0.64355 4.6352 0.41772
{'fl_cor_ap' } 1 0.83807 0.83891 0.62307 0.99637 0.83512
{'fl_cov_v' } 2.8944 2.9636 0.62238 0.79332 3.5168 0.36874
{'fl_cor_v' } 0.83807 1 0.99685 0.89507 0.88097 0.85912
{'fl_cov_c' } 0.61038 0.62238 0.13153 0.16405 0.74192 0.079746
{'fl_cor_c' } 0.83891 0.99685 1 0.87859 0.8822 0.88192
{'fl_cov_y' } 0.64355 0.79332 0.16405 0.26507 0.80761 0.079867
{'fl_cor_y' } 0.62307 0.89507 0.87859 1 0.67647 0.6222
{'fl_cov_coh' } 4.6352 3.5168 0.74192 0.80761 5.3771 0.49746
{'fl_cor_coh' } 0.99637 0.88097 0.8822 0.67647 1 0.86045
{'fl_cov_savefraccoh'} 0.41772 0.36874 0.079746 0.079867 0.49746 0.062162
{'fl_cor_savefraccoh'} 0.83512 0.85912 0.88192 0.6222 0.86045 1
{'fracByP0_01' } 0 -4.8153e-05 0.00017799 0.00018159 8.3115e-05 0
{'fracByP0_1' } 0 0.00027167 0.0013548 0.0014279 0.00063242 0
{'fracByP1' } 0 0.0032852 0.0063125 0.0069982 0.0029338 0
{'fracByP5' } 0 0.016969 0.025021 0.024262 0.011819 0
{'fracByP10' } 0 0.044207 0.05664 0.064855 0.026579 0
{'fracByP20' } 0.0026834 0.1115 0.13073 0.11733 0.067668 0.0099043
{'fracByP25' } 0.0076113 0.14492 0.17311 0.15549 0.086 0.025483
{'fracByP30' } 0.015302 0.19105 0.21762 0.19333 0.11182 0.048984
{'fracByP40' } 0.043894 0.27218 0.30467 0.27748 0.16912 0.11643
{'fracByP50' } 0.089861 0.36738 0.40369 0.36807 0.23805 0.21205
{'fracByP60' } 0.16112 0.46928 0.50828 0.46652 0.3263 0.32962
{'fracByP70' } 0.26525 0.58046 0.61519 0.57507 0.4298 0.46793
{'fracByP75' } 0.33325 0.64122 0.67431 0.63025 0.49166 0.54754
{'fracByP80' } 0.41265 0.70474 0.73277 0.69273 0.56293 0.62653
{'fracByP90' } 0.62139 0.84051 0.85792 0.82668 0.73375 0.80195
{'fracByP95' } 0.77085 0.91406 0.9245 0.90615 0.84324 0.89716
{'fracByP99' } 0.93558 0.98098 0.98317 0.97729 0.95807 0.97822
{'fracByP99_9' } 0.99103 0.99787 0.99814 0.9972 0.99438 0.99775
{'fracByP99_99' } 0.99886 0.99977 0.99979 0.99969 0.99931 0.99977
2.2.2 Test FF_DS_AZ_CTS_LOOP Speed Tests
Call the function with different a and z grid size, print out speed:
mp_support = containers.Map('KeyType','char', 'ValueType','any');
mp_support('bl_timer') = true;
mp_support('ls_ffcmd') = {};
mp_support('ls_ddcmd') = {};
mp_support('ls_ddgrh') = {};
mp_support('bl_show_stats_table') = false;
% A grid 50, shock grid 5:
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 50;
mp_params('it_z_n') = 5;
ff_ds_az_cts_loop(mp_params, mp_support);
Elapsed time is 0.466529 seconds.
FF_DS_AZ_CTS_LOOP finished. Distribution took = 0.065434
% A grid 100, shock grid 7:
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 100;
mp_params('it_z_n') = 7;
ff_ds_az_cts_loop(mp_params, mp_support);
Elapsed time is 0.930211 seconds.
FF_DS_AZ_CTS_LOOP finished. Distribution took = 0.20136
% A grid 200, shock grid 9:
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 200;
mp_params('it_z_n') = 9;
ff_ds_az_cts_loop(mp_params, mp_support);
Elapsed time is 1.614469 seconds.
FF_DS_AZ_CTS_LOOP finished. Distribution took = 0.52925
2.2.3 Test FF_DS_AZ_CTS_LOOP A grid 100 Shock grid 7
Call the function with different a and z grid size, print out speed:
mp_support = containers.Map('KeyType','char', 'ValueType','any');
mp_support('bl_timer') = true;
mp_support('ls_ffcmd') = {};
mp_support('ls_ddcmd') = {};
mp_support('ls_ddgrh') = {'faz','fa'};
mp_support('bl_show_stats_table') = true;
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 100;
mp_params('it_z_n') = 7;
ff_ds_az_cts_loop(mp_params, mp_support);
Elapsed time is 0.899597 seconds.
FF_DS_AZ_CTS_LOOP finished. Distribution took = 0.25939
xxx tb_outcomes: all stats xxx
OriginalVariableNames ap v c y coh savefraccoh
______________________ __________ __________ __________ __________ __________ ___________
{'mean' } 3.2216 6.9329 1.5295 1.5289 4.7511 0.52357
{'unweighted_sum' } 10019 7323.6 1530.6 1473.6 11549 457.17
{'sd' } 3.2562 2.1508 0.34914 0.5307 3.5687 0.25504
{'coefofvar' } 1.0107 0.31024 0.22827 0.34711 0.75113 0.48712
{'gini' } 0.52352 0.17526 0.12797 0.19065 0.3936 0.2723
{'min' } 0 1.7008 0.58543 0.58543 0.58543 0
{'max' } 50.789 19.213 4.21 4.9969 54.997 0.92702
{'pYis0' } 0.062608 0 0 0 0 0.062608
{'pYls0' } 0 0 0 0 0 0
{'pYgr0' } 0.93739 1 1 1 1 0.93739
{'pYisMINY' } 0.062608 0.0049772 0.0049772 0.0049772 0.0049772 0.062608
{'pYisMAXY' } 2.9501e-11 2.9501e-11 3.1223e-11 2.9501e-11 2.9501e-11 1.494e-14
{'p0_01' } 0 1.7008 0.58543 0.58543 0.58543 0
{'p0_1' } 0 1.7008 0.58543 0.58543 0.58543 0
{'p1' } 0 2.9492 0.76855 0.62688 0.76855 0
{'p5' } 0 3.4945 0.97884 0.78105 1.009 0
{'p10' } 0.092835 4.1716 1.0603 0.97609 1.223 0.078835
{'p20' } 0.47609 5.1938 1.2588 1.0456 1.7419 0.27652
{'p25' } 0.7311 5.3812 1.3008 1.094 2.0576 0.35312
{'p30' } 0.97803 5.6276 1.351 1.188 2.3618 0.42581
{'p40' } 1.5512 6.3139 1.4528 1.349 3.0158 0.51932
{'p50' } 2.233 6.8328 1.5245 1.4175 3.7588 0.59714
{'p60' } 3.0801 7.416 1.6192 1.5453 4.6604 0.66085
{'p70' } 4.105 8.0461 1.7025 1.7909 5.7649 0.70987
{'p75' } 4.6992 8.4292 1.7544 1.84 6.4292 0.73355
{'p80' } 5.4329 8.7432 1.8159 1.9097 7.3478 0.75277
{'p90' } 7.7004 9.7559 1.9663 2.3407 9.5263 0.79745
{'p95' } 9.7011 10.662 2.1066 2.5036 11.722 0.82522
{'p99' } 14.279 12.148 2.3613 3.1795 16.608 0.85983
{'p99_9' } 19.899 13.734 2.6792 3.5223 22.615 0.8829
{'p99_99' } 25.265 14.885 2.9563 3.7789 28.175 0.8962
{'fl_cov_ap' } 10.603 6.2617 1.0053 1.0453 11.608 0.65544
{'fl_cor_ap' } 1 0.89408 0.8843 0.60489 0.99896 0.78925
{'fl_cov_v' } 6.2617 4.626 0.74802 0.96794 7.0097 0.47179
{'fl_cor_v' } 0.89408 1 0.99613 0.848 0.91325 0.86007
{'fl_cov_c' } 1.0053 0.74802 0.1219 0.15425 1.1272 0.078595
{'fl_cor_c' } 0.8843 0.99613 1 0.83252 0.9047 0.88265
{'fl_cov_y' } 1.0453 0.96794 0.15425 0.28164 1.1995 0.078136
{'fl_cor_y' } 0.60489 0.848 0.83252 1 0.63337 0.57729
{'fl_cov_coh' } 11.608 7.0097 1.1272 1.1995 12.735 0.73404
{'fl_cor_coh' } 0.99896 0.91325 0.9047 0.63337 1 0.8065
{'fl_cov_savefraccoh'} 0.65544 0.47179 0.078595 0.078136 0.73404 0.065046
{'fl_cor_savefraccoh'} 0.78925 0.86007 0.88265 0.57729 0.8065 1
{'fracByP0_01' } 0 0.001221 0.0019051 0.0019058 0.00061329 0
{'fracByP0_1' } 0 0.001221 0.0019051 0.0019058 0.00061329 0
{'fracByP1' } 0 0.011511 0.013437 0.0039104 0.0042425 0
{'fracByP5' } 0 0.021279 0.026546 0.024488 0.012268 0
{'fracByP10' } 0.0006892 0.05109 0.059758 0.051739 0.020676 0.0036864
{'fracByP20' } 0.0099846 0.12278 0.1366 0.12131 0.052438 0.038521
{'fracByP25' } 0.019425 0.15429 0.17945 0.15485 0.072434 0.070039
{'fracByP30' } 0.032212 0.19399 0.22206 0.19029 0.094665 0.10974
{'fracByP40' } 0.0737 0.28144 0.31482 0.27941 0.15063 0.20042
{'fracByP50' } 0.1321 0.3768 0.41124 0.37234 0.22365 0.30981
{'fracByP60' } 0.21336 0.48025 0.51513 0.4642 0.31463 0.42631
{'fracByP70' } 0.3254 0.59015 0.62157 0.57794 0.42288 0.55601
{'fracByP75' } 0.39769 0.65462 0.67967 0.6363 0.48537 0.62983
{'fracByP80' } 0.47503 0.71232 0.73844 0.70062 0.56134 0.69967
{'fracByP90' } 0.67403 0.84445 0.86104 0.82867 0.73331 0.84375
{'fracByP95' } 0.80886 0.92029 0.92647 0.90776 0.84668 0.92112
{'fracByP99' } 0.95057 0.98162 0.98401 0.97831 0.96163 0.98352
{'fracByP99_9' } 0.99336 0.99797 0.99826 0.99778 0.99494 0.99833
{'fracByP99_99' } 0.99924 0.99979 0.99981 0.99977 0.9994 0.99984
2.2.4 Test FF_DS_AZ_CTS_LOOP A grid 300 Shock grid 25
mp_support = containers.Map('KeyType','char', 'ValueType','any');
mp_support('bl_timer') = true;
mp_support('ls_ffcmd') = {};
mp_support('ls_ddcmd') = {};
mp_support('ls_ddgrh') = {'faz','fa'};
mp_support('bl_show_stats_table') = true;
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 300;
mp_params('it_z_n') = 25;
ff_ds_az_cts_loop(mp_params, mp_support);
Elapsed time is 7.769713 seconds.
FF_DS_AZ_CTS_LOOP finished. Distribution took = 2.2408
xxx tb_outcomes: all stats xxx
OriginalVariableNames ap v c y coh savefraccoh
______________________ __________ __________ __________ __________ __________ ___________
{'mean' } 3.2612 6.9497 1.5318 1.5305 4.793 0.52715
{'unweighted_sum' } 1.1043e+05 79555 16733 19751 1.2716e+05 3442.8
{'sd' } 3.3352 2.1663 0.35078 0.5359 3.6495 0.25199
{'coefofvar' } 1.0227 0.31171 0.229 0.35014 0.76143 0.47803
{'gini' } 0.52534 0.17597 0.12824 0.19145 0.39608 0.26748
{'min' } 0 -2.7616 0.25871 0.25871 0.25871 0
{'max' } 54.451 20.418 4.3301 8.7798 58.78 0.92837
{'pYis0' } 0.04941 0 0 0 0 0.04941
{'pYls0' } 0 7.3281e-05 0 0 0 0
{'pYgr0' } 0.95059 0.99993 1 1 1 0.95059
{'pYisMINY' } 0.04941 3.1163e-08 3.1163e-08 3.1163e-08 3.1163e-08 0.04941
{'pYisMAXY' } 2.8477e-13 2.8477e-13 1.121e-13 2.8477e-13 2.8477e-13 3.6157e-25
{'p0_01' } 0 0.33584 0.44588 0.42374 0.44588 0
{'p0_1' } 0 1.0287 0.51088 0.51088 0.51088 0
{'p1' } 0 2.33 0.67226 0.67069 0.67505 0
{'p5' } 0.0027154 3.5353 0.94151 0.8016 1.0088 0.002787
{'p10' } 0.11496 4.1978 1.0921 0.9095 1.2356 0.093483
{'p20' } 0.51133 5.096 1.2504 1.0657 1.779 0.28788
{'p25' } 0.75298 5.4004 1.3077 1.1577 2.0685 0.36173
{'p30' } 1.004 5.7312 1.3565 1.1951 2.3792 0.42532
{'p40' } 1.5834 6.298 1.4458 1.3352 3.0372 0.52408
{'p50' } 2.2686 6.8433 1.5287 1.441 3.7996 0.59884
{'p60' } 3.0898 7.4098 1.6132 1.5764 4.6904 0.65811
{'p70' } 4.0971 8.0297 1.7037 1.7526 5.7899 0.70877
{'p75' } 4.7228 8.3787 1.7552 1.8223 6.462 0.73135
{'p80' } 5.4827 8.7742 1.8144 1.9267 7.2769 0.75357
{'p90' } 7.7718 9.8224 1.9746 2.2406 9.6945 0.79922
{'p95' } 9.9683 10.704 2.1148 2.5163 12.048 0.82675
{'p99' } 14.759 12.325 2.3956 3.157 17.176 0.86245
{'p99_9' } 21.215 14.066 2.7525 3.9803 23.946 0.88686
{'p99_99' } 27.205 15.415 3.0759 4.7968 30.277 0.90047
{'fl_cov_ap' } 11.123 6.4528 1.0361 1.0808 12.16 0.65691
{'fl_cor_ap' } 1 0.89313 0.88563 0.60472 0.999 0.78162
{'fl_cov_v' } 6.4528 4.6928 0.75717 0.98035 7.21 0.46786
{'fl_cor_v' } 0.89313 1 0.99643 0.84447 0.91198 0.85705
{'fl_cov_c' } 1.0361 0.75717 0.12304 0.15594 1.1592 0.07767
{'fl_cor_c' } 0.88563 0.99643 1 0.82954 0.90548 0.87868
{'fl_cov_y' } 1.0808 0.98035 0.15594 0.28718 1.2368 0.077234
{'fl_cor_y' } 0.60472 0.84447 0.82954 1 0.63237 0.57192
{'fl_cov_coh' } 12.16 7.21 1.1592 1.2368 13.319 0.73458
{'fl_cor_coh' } 0.999 0.91198 0.90548 0.63237 1 0.79876
{'fl_cov_savefraccoh'} 0.65691 0.46786 0.07767 0.077234 0.73458 0.063501
{'fl_cor_savefraccoh'} 0.78162 0.85705 0.87868 0.57192 0.79876 1
{'fracByP0_01' } 0 7.2341e-06 8.9677e-05 2.5415e-05 2.8657e-05 0
{'fracByP0_1' } 0 0.00014925 0.00040034 0.00047536 0.00012777 0
{'fracByP1' } 0 0.0031002 0.004056 0.0057421 0.0012982 0
{'fracByP5' } 4.4271e-07 0.020663 0.026101 0.023318 0.010275 3.7554e-06
{'fracByP10' } 0.00081444 0.049128 0.059669 0.051817 0.020124 0.0043579
{'fracByP20' } 0.010142 0.11647 0.13733 0.1174 0.051401 0.041452
{'fracByP25' } 0.0197 0.15487 0.17845 0.15395 0.07176 0.07241
{'fracByP30' } 0.033115 0.19474 0.22243 0.19298 0.095014 0.11033
{'fracByP40' } 0.07268 0.28138 0.31442 0.27544 0.15079 0.20152
{'fracByP50' } 0.13241 0.3756 0.41097 0.36527 0.22198 0.30736
{'fracByP60' } 0.21444 0.47892 0.51282 0.46572 0.31091 0.42746
{'fracByP70' } 0.323 0.58868 0.62139 0.57261 0.41949 0.55675
{'fracByP75' } 0.39061 0.6478 0.67743 0.63129 0.48319 0.62572
{'fracByP80' } 0.46952 0.70943 0.73587 0.6919 0.55532 0.69697
{'fracByP90' } 0.66831 0.84297 0.85906 0.82754 0.72955 0.84259
{'fracByP95' } 0.80219 0.91616 0.92541 0.90507 0.84194 0.91979
{'fracByP99' } 0.94613 0.98125 0.98339 0.97711 0.95822 0.98365
{'fracByP99_9' } 0.9927 0.9979 0.99812 0.99719 0.99443 0.99831
{'fracByP99_99' } 0.99909 0.99977 0.99979 0.99967 0.99932 0.99983
2.2.5 Test FF_DS_AZ_CTS_LOOP A grid 300 Shock grid 50
mp_support = containers.Map('KeyType','char', 'ValueType','any');
mp_support('bl_timer') = true;
mp_support('ls_ffcmd') = {};
mp_support('ls_ddcmd') = {};
mp_support('ls_ddgrh') = {'faz','fa'};
mp_support('bl_show_stats_table') = true;
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 300;
mp_params('it_z_n') = 50;
ff_ds_az_cts_loop(mp_params, mp_support);
Elapsed time is 13.966894 seconds.
FF_DS_AZ_CTS_LOOP finished. Distribution took = 5.0619
xxx tb_outcomes: all stats xxx
OriginalVariableNames ap v c y coh savefraccoh
______________________ __________ ___________ __________ __________ __________ ___________
{'mean' } 3.2794 6.957 1.5328 1.5312 4.8122 0.52801
{'unweighted_sum' } 2.3346e+05 1.6237e+05 34668 53309 2.6813e+05 5324.8
{'sd' } 3.3623 2.1722 0.35142 0.53693 3.6772 0.25195
{'coefofvar' } 1.0253 0.31224 0.22927 0.35065 0.76415 0.47717
{'gini' } 0.52595 0.17618 0.12829 0.19144 0.3969 0.26705
{'min' } 0 -7.6866 0.12843 0.12843 0.12843 0
{'max' } 61.275 22.164 4.3849 15.657 65.657 0.93325
{'pYis0' } 0.049376 0 0 0 0 0.049376
{'pYls0' } 0 0.00011917 0 0 0 0
{'pYgr0' } 0.95062 0.99988 1 1 1 0.95062
{'pYisMINY' } 0.049376 1.1048e-15 1.1048e-15 1.1048e-15 1.1048e-15 0.049376
{'pYisMAXY' } 1.584e-18 1.584e-18 5.0847e-19 1.584e-18 1.584e-18 1.584e-18
{'p0_01' } 0 -0.20427 0.40271 0.40271 0.40271 0
{'p0_1' } 0 1.2141 0.53589 0.48816 0.53589 0
{'p1' } 0 2.3693 0.71312 0.64833 0.71312 0
{'p5' } 0.001023 3.5435 0.94895 0.80724 0.96945 0.0010781
{'p10' } 0.11645 4.2417 1.0917 0.93681 1.2501 0.095192
{'p20' } 0.50875 5.08 1.2515 1.072 1.7735 0.2902
{'p25' } 0.75899 5.4247 1.3061 1.1504 2.0649 0.36356
{'p30' } 1.0156 5.7325 1.3564 1.2011 2.3741 0.42667
{'p40' } 1.6036 6.2932 1.4459 1.3198 3.0387 0.52518
{'p50' } 2.2768 6.8406 1.5297 1.4423 3.8053 0.59933
{'p60' } 3.0945 7.4051 1.6122 1.5771 4.7002 0.6586
{'p70' } 4.113 8.0338 1.7042 1.7334 5.8225 0.70999
{'p75' } 4.7604 8.3794 1.7554 1.8278 6.4985 0.73226
{'p80' } 5.5142 8.7771 1.8143 1.9295 7.3239 0.75424
{'p90' } 7.8048 9.8378 1.9756 2.2476 9.7629 0.80013
{'p95' } 10.007 10.714 2.1161 2.5336 12.107 0.82766
{'p99' } 14.9 12.348 2.407 3.1578 17.285 0.86312
{'p99_9' } 21.501 14.13 2.7694 4.0322 24.216 0.88766
{'p99_99' } 27.735 15.514 3.1037 4.8946 30.851 0.90127
{'fl_cov_ap' } 11.305 6.5234 1.0466 1.0907 12.352 0.66084
{'fl_cor_ap' } 1 0.89316 0.88579 0.60415 0.99902 0.78009
{'fl_cov_v' } 6.5234 4.7186 0.76066 0.98362 7.2841 0.46879
{'fl_cor_v' } 0.89316 1 0.99645 0.84334 0.9119 0.85658
{'fl_cov_c' } 1.0466 0.76066 0.1235 0.15645 1.1701 0.077707
{'fl_cor_c' } 0.88579 0.99645 1 0.82914 0.9055 0.87766
{'fl_cov_y' } 1.0907 0.98362 0.15645 0.2883 1.2471 0.0772
{'fl_cor_y' } 0.60415 0.84334 0.82914 1 0.63165 0.57067
{'fl_cov_coh' } 12.352 7.2841 1.1701 1.2471 13.522 0.73855
{'fl_cor_coh' } 0.99902 0.9119 0.9055 0.63165 1 0.79716
{'fl_cov_savefraccoh'} 0.66084 0.46879 0.077707 0.0772 0.73855 0.063478
{'fl_cor_savefraccoh'} 0.78009 0.85658 0.87766 0.57067 0.79716 1
{'fracByP0_01' } 0 -7.0657e-06 2.6272e-05 3.0716e-05 8.3673e-06 0
{'fracByP0_1' } 0 8.1733e-05 0.00058172 0.0003 0.00018482 0
{'fracByP1' } 0 0.0025825 0.0055755 0.0043105 0.0017358 0
{'fracByP5' } 1.3446e-07 0.020553 0.028388 0.023343 0.0084443 1.165e-06
{'fracByP10' } 0.00082822 0.048923 0.059616 0.051792 0.020041 0.0045383
{'fracByP20' } 0.010119 0.11678 0.1368 0.1176 0.051426 0.041679
{'fracByP25' } 0.019764 0.15445 0.17846 0.15402 0.071298 0.07291
{'fracByP30' } 0.033198 0.19437 0.22195 0.19279 0.094487 0.11072
{'fracByP40' } 0.072799 0.28088 0.31405 0.27516 0.15079 0.20093
{'fracByP50' } 0.13186 0.37535 0.41129 0.36559 0.22202 0.30846
{'fracByP60' } 0.21318 0.47748 0.51316 0.46495 0.30966 0.42828
{'fracByP70' } 0.32222 0.58845 0.62103 0.57307 0.41837 0.55682
{'fracByP75' } 0.39045 0.64744 0.67785 0.63075 0.48233 0.62537
{'fracByP80' } 0.46786 0.7092 0.73555 0.69205 0.55399 0.69588
{'fracByP90' } 0.66756 0.84275 0.8587 0.82726 0.72947 0.84385
{'fracByP95' } 0.80166 0.91607 0.92521 0.90478 0.84112 0.91991
{'fracByP99' } 0.94602 0.98111 0.98335 0.97699 0.95791 0.98349
{'fracByP99_9' } 0.99264 0.99789 0.9981 0.99714 0.99438 0.99831
{'fracByP99_99' } 0.99908 0.99977 0.99979 0.99966 0.9993 0.99983
2.3 FF_DS_AZ_CTS_VEC Dynamic Savings Vectorized Continuous Distribution
Go back to fan’s MEconTools Toolbox (bookdown), Matlab Code Examples Repository (bookdown), or Math for Econ with Matlab Repository (bookdown).
Examples](https://fanwangecon.github.io/M4Econ/), or** Dynamic Asset This is the example vignette for function: ff_ds_az_cts_vec from the MEconTools Package. F(a,z) discrete probability mass function given policy function solution with continuous savings choices, vectorized.
Distribution for Common Choice and States Grid Loop: ff_ds_az_cts_loop
Distribution for States Grid + Continuous Exact Savings as Share of Cash-on-Hand Loop: ff_ds_az_cts_loop
Distribution for States Grid + Continuous Exact Savings as Share of Cash-on-Hand Vectorized: ff_ds_az_cts_vec
2.3.1 Test FF_DS_AZ_CTS_VEC Defaults
Call the function with defaults. By default, shows the asset policy function summary. Model parameters can be changed by the mp_params.
%mp_params
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('fl_crra') = 1.5;
mp_params('fl_beta') = 0.94;
% call function
ff_ds_az_cts_vec(mp_params);
Elapsed time is 2.185467 seconds.
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CONTAINER NAME: mp_ffcmd ND Array (Matrix etc)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx ndim numel rowN colN sum mean std coefvari min max
_ ___ ____ _____ ____ ____ _____ ______ ______ ________ ___ ______
ap 1 1 2 3000 200 15 42703 14.234 14.307 1.0051 0 51.591
xxx TABLE:ap xxxxxxxxxxxxxxxxxx
c1 c2 c3 c4 c5 c11 c12 c13 c14 c15
______ ______ ______ ______ ______ _______ _______ ______ ______ ______
r1 0 0 0 0 0 0.58655 0.89911 1.2884 1.7803 2.3861
r2 0 0 0 0 0 0.58671 0.89914 1.2885 1.7804 2.3862
r3 0 0 0 0 0 0.5871 0.89961 1.2888 1.7808 2.3867
r4 0 0 0 0 0 0.58803 0.90058 1.2898 1.7817 2.3877
r5 0 0 0 0 0 0.58953 0.90208 1.2914 1.7831 2.3891
r196 45.655 45.699 45.725 45.798 45.889 47.025 47.404 47.828 48.358 49.028
r197 46.257 46.303 46.326 46.401 46.492 47.626 48.005 48.432 48.965 49.651
r198 46.863 46.91 46.931 47.007 47.097 48.232 48.611 49.041 49.59 50.294
r199 47.472 47.521 47.542 47.617 47.711 48.843 49.222 49.658 50.235 50.94
r200 48.088 48.134 48.157 48.232 48.326 49.459 49.841 50.311 50.885 51.591
FF_DS_AZ_CTS_LOOP finished. Distribution took = 0.13145
----------------------------------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CONTAINER NAME: mp_ddcmd ND Array (Matrix etc)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
i idx ndim numel rowN colN sum mean std coefvari min max
_ ___ ____ _____ ____ ____ ___ __________ _________ ________ __________ ________
fa 1 1 2 200 200 1 1 0.005 0.0096174 1.9235 0 0.11604
faz 2 2 2 3000 200 15 1 0.00033333 0.0011636 3.4908 0 0.032295
fz 3 3 2 15 15 1 1 0.066667 0.076895 1.1534 6.1035e-05 0.20947
xxx TABLE:fa xxxxxxxxxxxxxxxxxx
c1
__________
r1 0.11604
r2 0
r3 0.0004751
r4 0.00026799
r5 0.0029727
r196 3.5618e-14
r197 2.1735e-14
r198 1.329e-14
r199 8.3938e-15
r200 8.2751e-15
xxx TABLE:faz xxxxxxxxxxxxxxxxxx
c1 c2 c3 c4 c5 c11 c12 c13 c14 c15
__________ __________ __________ __________ __________ __________ __________ __________ __________ __________
r1 4.1559e-05 0.00053618 0.0031141 0.010616 0.023097 9.8338e-05 8.1894e-06 4.3385e-07 1.3284e-08 1.7934e-10
r2 0 0 0 0 0 0 0 0 0 0
r3 2.0452e-10 1.1226e-08 2.5837e-07 3.2065e-06 2.2865e-05 1.2294e-06 1.0693e-07 5.8481e-09 1.8347e-10 2.5249e-12
r4 8.6656e-10 2.8074e-08 3.684e-07 2.7287e-06 1.4098e-05 6.831e-07 5.9408e-08 3.249e-09 1.0193e-10 1.4026e-12
r5 9.2776e-08 2.9148e-06 3.479e-05 0.00019689 0.00056423 2.3628e-06 1.9305e-07 1.0072e-08 3.0458e-10 4.0697e-12
r196 1.6685e-22 7.5909e-21 1.5483e-19 1.8762e-18 1.5117e-17 7.3723e-15 8.1882e-15 6.5347e-15 3.3448e-15 8.2909e-16
r197 4.6363e-23 2.3916e-21 5.523e-20 7.5562e-19 6.8327e-18 4.5113e-15 5.0046e-15 4.0053e-15 2.0624e-15 5.148e-16
r198 8.2487e-24 4.9336e-22 1.3328e-20 2.1488e-19 2.2991e-18 2.8157e-15 3.0885e-15 2.4579e-15 1.2688e-15 3.1814e-16
r199 6.6913e-25 5.3279e-23 1.9003e-21 4.0019e-20 5.5219e-19 1.9017e-15 2.0244e-15 1.5281e-15 7.7436e-16 1.9614e-16
r200 2.8381e-26 2.725e-24 1.1911e-22 3.1319e-21 5.5136e-20 1.4819e-15 2.2618e-15 2.1457e-15 1.1964e-15 3.1409e-16
xxx TABLE:fz xxxxxxxxxxxxxxxxxx
c1
__________
r1 6.1035e-05
r2 0.00085449
r3 0.0055542
r4 0.022217
r5 0.061096
r11 0.061096
r12 0.022217
r13 0.0055542
r14 0.00085449
r15 6.1035e-05
xxx tb_outcomes: all stats xxx
OriginalVariableNames ap v c y coh savefraccoh
______________________ __________ ___________ __________ __________ __________ ___________
{'mean' } 1.675 5.0913 1.4673 1.467 3.1423 0.37474
{'unweighted_sum' } 42703 26797 7295.8 6979.8 49998 1657.9
{'sd' } 2.0062 1.7215 0.36267 0.51485 2.3189 0.24932
{'coefofvar' } 1.1977 0.33813 0.24717 0.35095 0.73794 0.66532
{'gini' } 0.59404 0.19113 0.13962 0.19161 0.37632 0.39022
{'min' } 0 -1.2641 0.38052 0.38052 0.38052 0
{'max' } 51.591 16.787 5.0209 6.6099 56.61 0.91805
{'pYis0' } 0.11606 0 0 0 0 0.11606
{'pYls0' } 0 0.00066766 0 0 0 0
{'pYgr0' } 0.88394 0.99933 1 1 1 0.88394
{'pYisMINY' } 0.11606 4.1559e-05 4.1559e-05 4.1559e-05 4.1559e-05 0.11606
{'pYisMAXY' } 3.1409e-16 3.1409e-16 5.148e-16 3.1409e-16 3.1409e-16 2.8381e-26
{'p0_01' } 0 -0.34507 0.45473 0.45473 0.45473 0
{'p0_1' } 0 0.52204 0.54342 0.54342 0.54342 0
{'p1' } 0 1.3412 0.6494 0.6494 0.6494 0
{'p5' } 0 2.1813 0.85431 0.77605 0.88697 0
{'p10' } 0 2.8514 0.96477 0.92741 1.002 0
{'p20' } 0.10665 3.5986 1.1516 1.0358 1.3244 0.083657
{'p25' } 0.21483 3.8501 1.2354 1.1105 1.4524 0.14274
{'p30' } 0.32994 4.2218 1.284 1.129 1.6395 0.20194
{'p40' } 0.60561 4.5759 1.3788 1.3244 1.999 0.30454
{'p50' } 0.9866 5.0443 1.4671 1.363 2.4484 0.39896
{'p60' } 1.4331 5.4957 1.5615 1.5828 2.9924 0.48032
{'p70' } 2.0261 5.9595 1.6562 1.6429 3.671 0.556
{'p75' } 2.4055 6.2377 1.7089 1.7094 4.0981 0.59225
{'p80' } 2.8929 6.5441 1.7669 1.9106 4.6329 0.62436
{'p90' } 4.3431 7.3623 1.9254 2.123 6.2699 0.69668
{'p95' } 5.7881 8.0262 2.0625 2.4019 7.7831 0.74075
{'p99' } 8.9453 9.2776 2.3421 2.9539 11.327 0.79763
{'p99_9' } 13.367 10.599 2.6636 3.7357 15.962 0.83767
{'p99_99' } 17.333 11.639 2.9483 4.3328 20.294 0.85903
{'fl_cov_ap' } 4.0248 2.8944 0.61038 0.64355 4.6352 0.41772
{'fl_cor_ap' } 1 0.83807 0.83891 0.62307 0.99637 0.83512
{'fl_cov_v' } 2.8944 2.9636 0.62238 0.79332 3.5168 0.36874
{'fl_cor_v' } 0.83807 1 0.99685 0.89507 0.88097 0.85912
{'fl_cov_c' } 0.61038 0.62238 0.13153 0.16405 0.74192 0.079746
{'fl_cor_c' } 0.83891 0.99685 1 0.87859 0.8822 0.88192
{'fl_cov_y' } 0.64355 0.79332 0.16405 0.26507 0.80761 0.079867
{'fl_cor_y' } 0.62307 0.89507 0.87859 1 0.67647 0.6222
{'fl_cov_coh' } 4.6352 3.5168 0.74192 0.80761 5.3771 0.49746
{'fl_cor_coh' } 0.99637 0.88097 0.8822 0.67647 1 0.86045
{'fl_cov_savefraccoh'} 0.41772 0.36874 0.079746 0.079867 0.49746 0.062162
{'fl_cor_savefraccoh'} 0.83512 0.85912 0.88192 0.6222 0.86045 1
{'fracByP0_01' } 0 -4.8153e-05 0.00017799 0.00018159 8.3115e-05 0
{'fracByP0_1' } 0 0.00027167 0.0013548 0.0014279 0.00063242 0
{'fracByP1' } 0 0.0032852 0.0063125 0.0069982 0.0029338 0
{'fracByP5' } 0 0.016969 0.025021 0.024262 0.011819 0
{'fracByP10' } 0 0.044207 0.05664 0.064855 0.026579 0
{'fracByP20' } 0.0026834 0.1115 0.13073 0.11733 0.067668 0.0099043
{'fracByP25' } 0.0076113 0.14492 0.17311 0.15549 0.086 0.025483
{'fracByP30' } 0.015302 0.19105 0.21762 0.19333 0.11182 0.048984
{'fracByP40' } 0.043894 0.27218 0.30467 0.27748 0.16912 0.11643
{'fracByP50' } 0.089861 0.36738 0.40369 0.36807 0.23805 0.21205
{'fracByP60' } 0.16112 0.46928 0.50828 0.46652 0.3263 0.32962
{'fracByP70' } 0.26525 0.58046 0.61519 0.57507 0.4298 0.46793
{'fracByP75' } 0.33325 0.64122 0.67431 0.63025 0.49166 0.54754
{'fracByP80' } 0.41265 0.70474 0.73277 0.69273 0.56293 0.62653
{'fracByP90' } 0.62139 0.84051 0.85792 0.82668 0.73375 0.80195
{'fracByP95' } 0.77085 0.91406 0.9245 0.90615 0.84324 0.89716
{'fracByP99' } 0.93558 0.98098 0.98317 0.97729 0.95807 0.97822
{'fracByP99_9' } 0.99103 0.99787 0.99814 0.9972 0.99438 0.99775
{'fracByP99_99' } 0.99886 0.99977 0.99979 0.99969 0.99931 0.99977
2.3.2 Test FF_DS_AZ_CTS_VEC Speed Tests
Call the function with different a and z grid size, print out speed:
mp_support = containers.Map('KeyType','char', 'ValueType','any');
mp_support('bl_timer') = true;
mp_support('ls_ffcmd') = {};
mp_support('ls_ddcmd') = {};
mp_support('ls_ddgrh') = {};
mp_support('bl_show_stats_table') = false;
% A grid 50, shock grid 5:
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 50;
mp_params('it_z_n') = 5;
ff_ds_az_cts_vec(mp_params, mp_support);
Elapsed time is 0.459956 seconds.
FF_DS_AZ_CTS_LOOP finished. Distribution took = 0.015748
% A grid 100, shock grid 7:
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 100;
mp_params('it_z_n') = 7;
ff_ds_az_cts_vec(mp_params, mp_support);
Elapsed time is 0.938024 seconds.
FF_DS_AZ_CTS_LOOP finished. Distribution took = 0.046035
% A grid 200, shock grid 9:
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 200;
mp_params('it_z_n') = 9;
ff_ds_az_cts_vec(mp_params, mp_support);
Elapsed time is 1.696573 seconds.
FF_DS_AZ_CTS_LOOP finished. Distribution took = 0.12795
2.3.3 Test FF_DS_AZ_CTS_VEC A grid 100 Shock grid 7
Call the function with different a and z grid size, print out speed:
mp_support = containers.Map('KeyType','char', 'ValueType','any');
mp_support('bl_timer') = true;
mp_support('ls_ffcmd') = {};
mp_support('ls_ddcmd') = {};
mp_support('ls_ddgrh') = {'faz','fa'};
mp_support('bl_show_stats_table') = true;
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 100;
mp_params('it_z_n') = 7;
ff_ds_az_cts_vec(mp_params, mp_support);
Elapsed time is 0.931254 seconds.
FF_DS_AZ_CTS_LOOP finished. Distribution took = 0.069571
xxx tb_outcomes: all stats xxx
OriginalVariableNames ap v c y coh savefraccoh
______________________ __________ __________ __________ __________ __________ ___________
{'mean' } 3.2216 6.9329 1.5295 1.5289 4.7511 0.52357
{'unweighted_sum' } 10019 7323.6 1530.6 1473.6 11549 457.17
{'sd' } 3.2562 2.1508 0.34914 0.5307 3.5687 0.25504
{'coefofvar' } 1.0107 0.31024 0.22827 0.34711 0.75113 0.48712
{'gini' } 0.52352 0.17526 0.12797 0.19065 0.3936 0.2723
{'min' } 0 1.7008 0.58543 0.58543 0.58543 0
{'max' } 50.789 19.213 4.21 4.9969 54.997 0.92702
{'pYis0' } 0.062608 0 0 0 0 0.062608
{'pYls0' } 0 0 0 0 0 0
{'pYgr0' } 0.93739 1 1 1 1 0.93739
{'pYisMINY' } 0.062608 0.0049772 0.0049772 0.0049772 0.0049772 0.062608
{'pYisMAXY' } 2.9501e-11 2.9501e-11 3.1223e-11 2.9501e-11 2.9501e-11 1.494e-14
{'p0_01' } 0 1.7008 0.58543 0.58543 0.58543 0
{'p0_1' } 0 1.7008 0.58543 0.58543 0.58543 0
{'p1' } 0 2.9492 0.76855 0.62688 0.76855 0
{'p5' } 0 3.4945 0.97884 0.78105 1.009 0
{'p10' } 0.092835 4.1716 1.0603 0.97609 1.223 0.078835
{'p20' } 0.47609 5.1938 1.2588 1.0456 1.7419 0.27652
{'p25' } 0.7311 5.3812 1.3008 1.094 2.0576 0.35312
{'p30' } 0.97803 5.6276 1.351 1.188 2.3618 0.42581
{'p40' } 1.5512 6.3139 1.4528 1.349 3.0158 0.51932
{'p50' } 2.233 6.8328 1.5245 1.4175 3.7588 0.59714
{'p60' } 3.0801 7.416 1.6192 1.5453 4.6604 0.66085
{'p70' } 4.105 8.0461 1.7025 1.7909 5.7649 0.70987
{'p75' } 4.6992 8.4292 1.7544 1.84 6.4292 0.73355
{'p80' } 5.4329 8.7432 1.8159 1.9097 7.3478 0.75277
{'p90' } 7.7004 9.7559 1.9663 2.3407 9.5263 0.79745
{'p95' } 9.7011 10.662 2.1066 2.5036 11.722 0.82522
{'p99' } 14.279 12.148 2.3613 3.1795 16.608 0.85983
{'p99_9' } 19.899 13.734 2.6792 3.5223 22.615 0.8829
{'p99_99' } 25.265 14.885 2.9563 3.7789 28.175 0.8962
{'fl_cov_ap' } 10.603 6.2617 1.0053 1.0453 11.608 0.65544
{'fl_cor_ap' } 1 0.89408 0.8843 0.60489 0.99896 0.78925
{'fl_cov_v' } 6.2617 4.626 0.74802 0.96794 7.0097 0.47179
{'fl_cor_v' } 0.89408 1 0.99613 0.848 0.91325 0.86007
{'fl_cov_c' } 1.0053 0.74802 0.1219 0.15425 1.1272 0.078595
{'fl_cor_c' } 0.8843 0.99613 1 0.83252 0.9047 0.88265
{'fl_cov_y' } 1.0453 0.96794 0.15425 0.28164 1.1995 0.078136
{'fl_cor_y' } 0.60489 0.848 0.83252 1 0.63337 0.57729
{'fl_cov_coh' } 11.608 7.0097 1.1272 1.1995 12.735 0.73404
{'fl_cor_coh' } 0.99896 0.91325 0.9047 0.63337 1 0.8065
{'fl_cov_savefraccoh'} 0.65544 0.47179 0.078595 0.078136 0.73404 0.065046
{'fl_cor_savefraccoh'} 0.78925 0.86007 0.88265 0.57729 0.8065 1
{'fracByP0_01' } 0 0.001221 0.0019051 0.0019058 0.00061329 0
{'fracByP0_1' } 0 0.001221 0.0019051 0.0019058 0.00061329 0
{'fracByP1' } 0 0.011511 0.013437 0.0039104 0.0042425 0
{'fracByP5' } 0 0.021279 0.026546 0.024488 0.012268 0
{'fracByP10' } 0.0006892 0.05109 0.059758 0.051739 0.020676 0.0036864
{'fracByP20' } 0.0099846 0.12278 0.1366 0.12131 0.052438 0.038521
{'fracByP25' } 0.019425 0.15429 0.17945 0.15485 0.072434 0.070039
{'fracByP30' } 0.032212 0.19399 0.22206 0.19029 0.094665 0.10974
{'fracByP40' } 0.0737 0.28144 0.31482 0.27941 0.15063 0.20042
{'fracByP50' } 0.1321 0.3768 0.41124 0.37234 0.22365 0.30981
{'fracByP60' } 0.21336 0.48025 0.51513 0.4642 0.31463 0.42631
{'fracByP70' } 0.3254 0.59015 0.62157 0.57794 0.42288 0.55601
{'fracByP75' } 0.39769 0.65462 0.67967 0.6363 0.48537 0.62983
{'fracByP80' } 0.47503 0.71232 0.73844 0.70062 0.56134 0.69967
{'fracByP90' } 0.67403 0.84445 0.86104 0.82867 0.73331 0.84375
{'fracByP95' } 0.80886 0.92029 0.92647 0.90776 0.84668 0.92112
{'fracByP99' } 0.95057 0.98162 0.98401 0.97831 0.96163 0.98352
{'fracByP99_9' } 0.99336 0.99797 0.99826 0.99778 0.99494 0.99833
{'fracByP99_99' } 0.99924 0.99979 0.99981 0.99977 0.9994 0.99984
2.3.4 Test FF_DS_AZ_CTS_VEC A grid 300 Shock grid 25
mp_support = containers.Map('KeyType','char', 'ValueType','any');
mp_support('bl_timer') = true;
mp_support('ls_ffcmd') = {};
mp_support('ls_ddcmd') = {};
mp_support('ls_ddgrh') = {'faz','fa'};
mp_support('bl_show_stats_table') = true;
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 300;
mp_params('it_z_n') = 25;
ff_ds_az_cts_vec(mp_params, mp_support);
Elapsed time is 7.884421 seconds.
FF_DS_AZ_CTS_LOOP finished. Distribution took = 0.34095
xxx tb_outcomes: all stats xxx
OriginalVariableNames ap v c y coh savefraccoh
______________________ __________ __________ __________ __________ __________ ___________
{'mean' } 3.2612 6.9497 1.5318 1.5305 4.793 0.52715
{'unweighted_sum' } 1.1043e+05 79555 16733 19751 1.2716e+05 3442.8
{'sd' } 3.3352 2.1663 0.35078 0.5359 3.6495 0.25199
{'coefofvar' } 1.0227 0.31171 0.229 0.35014 0.76143 0.47803
{'gini' } 0.52534 0.17597 0.12824 0.19145 0.39608 0.26748
{'min' } 0 -2.7616 0.25871 0.25871 0.25871 0
{'max' } 54.451 20.418 4.3301 8.7798 58.78 0.92837
{'pYis0' } 0.04941 0 0 0 0 0.04941
{'pYls0' } 0 7.3281e-05 0 0 0 0
{'pYgr0' } 0.95059 0.99993 1 1 1 0.95059
{'pYisMINY' } 0.04941 3.1163e-08 3.1163e-08 3.1163e-08 3.1163e-08 0.04941
{'pYisMAXY' } 2.8477e-13 2.8477e-13 1.121e-13 2.8477e-13 2.8477e-13 3.6157e-25
{'p0_01' } 0 0.33584 0.44588 0.42374 0.44588 0
{'p0_1' } 0 1.0287 0.51088 0.51088 0.51088 0
{'p1' } 0 2.33 0.67226 0.67069 0.67505 0
{'p5' } 0.0027154 3.5353 0.94151 0.8016 1.0088 0.002787
{'p10' } 0.11496 4.1978 1.0921 0.9095 1.2356 0.093483
{'p20' } 0.51133 5.096 1.2504 1.0657 1.779 0.28788
{'p25' } 0.75298 5.4004 1.3077 1.1577 2.0685 0.36173
{'p30' } 1.004 5.7312 1.3565 1.1951 2.3792 0.42532
{'p40' } 1.5834 6.298 1.4458 1.3352 3.0372 0.52408
{'p50' } 2.2686 6.8433 1.5287 1.441 3.7996 0.59884
{'p60' } 3.0898 7.4098 1.6132 1.5764 4.6904 0.65811
{'p70' } 4.0971 8.0297 1.7037 1.7526 5.7899 0.70877
{'p75' } 4.7228 8.3787 1.7552 1.8223 6.462 0.73135
{'p80' } 5.4827 8.7742 1.8144 1.9267 7.2769 0.75357
{'p90' } 7.7718 9.8224 1.9746 2.2406 9.6945 0.79922
{'p95' } 9.9683 10.704 2.1148 2.5163 12.048 0.82675
{'p99' } 14.759 12.325 2.3956 3.157 17.176 0.86245
{'p99_9' } 21.215 14.066 2.7525 3.9803 23.946 0.88686
{'p99_99' } 27.205 15.415 3.0759 4.7968 30.277 0.90047
{'fl_cov_ap' } 11.123 6.4528 1.0361 1.0808 12.16 0.65691
{'fl_cor_ap' } 1 0.89313 0.88563 0.60472 0.999 0.78162
{'fl_cov_v' } 6.4528 4.6928 0.75717 0.98035 7.21 0.46786
{'fl_cor_v' } 0.89313 1 0.99643 0.84447 0.91198 0.85705
{'fl_cov_c' } 1.0361 0.75717 0.12304 0.15594 1.1592 0.07767
{'fl_cor_c' } 0.88563 0.99643 1 0.82954 0.90548 0.87868
{'fl_cov_y' } 1.0808 0.98035 0.15594 0.28718 1.2368 0.077234
{'fl_cor_y' } 0.60472 0.84447 0.82954 1 0.63237 0.57192
{'fl_cov_coh' } 12.16 7.21 1.1592 1.2368 13.319 0.73458
{'fl_cor_coh' } 0.999 0.91198 0.90548 0.63237 1 0.79876
{'fl_cov_savefraccoh'} 0.65691 0.46786 0.07767 0.077234 0.73458 0.063501
{'fl_cor_savefraccoh'} 0.78162 0.85705 0.87868 0.57192 0.79876 1
{'fracByP0_01' } 0 7.2341e-06 8.9677e-05 2.5415e-05 2.8657e-05 0
{'fracByP0_1' } 0 0.00014925 0.00040034 0.00047536 0.00012777 0
{'fracByP1' } 0 0.0031002 0.004056 0.0057421 0.0012982 0
{'fracByP5' } 4.4271e-07 0.020663 0.026101 0.023318 0.010275 3.7554e-06
{'fracByP10' } 0.00081444 0.049128 0.059669 0.051817 0.020124 0.0043579
{'fracByP20' } 0.010142 0.11647 0.13733 0.1174 0.051401 0.041452
{'fracByP25' } 0.0197 0.15487 0.17845 0.15395 0.07176 0.07241
{'fracByP30' } 0.033115 0.19474 0.22243 0.19298 0.095014 0.11033
{'fracByP40' } 0.07268 0.28138 0.31442 0.27544 0.15079 0.20152
{'fracByP50' } 0.13241 0.3756 0.41097 0.36527 0.22198 0.30736
{'fracByP60' } 0.21444 0.47892 0.51282 0.46572 0.31091 0.42746
{'fracByP70' } 0.323 0.58868 0.62139 0.57261 0.41949 0.55675
{'fracByP75' } 0.39061 0.6478 0.67743 0.63129 0.48319 0.62572
{'fracByP80' } 0.46952 0.70943 0.73587 0.6919 0.55532 0.69697
{'fracByP90' } 0.66831 0.84297 0.85906 0.82754 0.72955 0.84259
{'fracByP95' } 0.80219 0.91616 0.92541 0.90507 0.84194 0.91979
{'fracByP99' } 0.94613 0.98125 0.98339 0.97711 0.95822 0.98365
{'fracByP99_9' } 0.9927 0.9979 0.99812 0.99719 0.99443 0.99831
{'fracByP99_99' } 0.99909 0.99977 0.99979 0.99967 0.99932 0.99983
2.3.5 Test FF_DS_AZ_CTS_VEC A grid 300 Shock grid 50
mp_support = containers.Map('KeyType','char', 'ValueType','any');
mp_support('bl_timer') = true;
mp_support('ls_ffcmd') = {};
mp_support('ls_ddcmd') = {};
mp_support('ls_ddgrh') = {'faz','fa'};
mp_support('bl_show_stats_table') = true;
mp_params = containers.Map('KeyType','char', 'ValueType','any');
mp_params('it_a_n') = 300;
mp_params('it_z_n') = 50;
ff_ds_az_cts_vec(mp_params, mp_support);
Elapsed time is 14.233149 seconds.
FF_DS_AZ_CTS_LOOP finished. Distribution took = 1.2257
xxx tb_outcomes: all stats xxx
OriginalVariableNames ap v c y coh savefraccoh
______________________ __________ ___________ __________ __________ __________ ___________
{'mean' } 3.2794 6.957 1.5328 1.5312 4.8122 0.52801
{'unweighted_sum' } 2.3346e+05 1.6237e+05 34668 53309 2.6813e+05 5324.8
{'sd' } 3.3623 2.1722 0.35142 0.53693 3.6772 0.25195
{'coefofvar' } 1.0253 0.31224 0.22927 0.35065 0.76415 0.47717
{'gini' } 0.52595 0.17618 0.12829 0.19144 0.3969 0.26705
{'min' } 0 -7.6866 0.12843 0.12843 0.12843 0
{'max' } 61.275 22.164 4.3849 15.657 65.657 0.93325
{'pYis0' } 0.049376 0 0 0 0 0.049376
{'pYls0' } 0 0.00011917 0 0 0 0
{'pYgr0' } 0.95062 0.99988 1 1 1 0.95062
{'pYisMINY' } 0.049376 1.1048e-15 1.1048e-15 1.1048e-15 1.1048e-15 0.049376
{'pYisMAXY' } 1.584e-18 1.584e-18 5.0847e-19 1.584e-18 1.584e-18 1.584e-18
{'p0_01' } 0 -0.20427 0.40271 0.40271 0.40271 0
{'p0_1' } 0 1.2141 0.53589 0.48816 0.53589 0
{'p1' } 0 2.3693 0.71312 0.64833 0.71312 0
{'p5' } 0.001023 3.5435 0.94895 0.80724 0.96945 0.0010781
{'p10' } 0.11645 4.2417 1.0917 0.93681 1.2501 0.095192
{'p20' } 0.50875 5.08 1.2515 1.072 1.7735 0.2902
{'p25' } 0.75899 5.4247 1.3061 1.1504 2.0649 0.36356
{'p30' } 1.0156 5.7325 1.3564 1.2011 2.3741 0.42667
{'p40' } 1.6036 6.2932 1.4459 1.3198 3.0387 0.52518
{'p50' } 2.2768 6.8406 1.5297 1.4423 3.8053 0.59933
{'p60' } 3.0945 7.4051 1.6122 1.5771 4.7002 0.6586
{'p70' } 4.113 8.0338 1.7042 1.7334 5.8225 0.70999
{'p75' } 4.7604 8.3794 1.7554 1.8278 6.4985 0.73226
{'p80' } 5.5142 8.7771 1.8143 1.9295 7.3239 0.75424
{'p90' } 7.8048 9.8378 1.9756 2.2476 9.7629 0.80013
{'p95' } 10.007 10.714 2.1161 2.5336 12.107 0.82766
{'p99' } 14.9 12.348 2.407 3.1578 17.285 0.86312
{'p99_9' } 21.501 14.13 2.7694 4.0322 24.216 0.88766
{'p99_99' } 27.735 15.514 3.1037 4.8946 30.851 0.90127
{'fl_cov_ap' } 11.305 6.5234 1.0466 1.0907 12.352 0.66084
{'fl_cor_ap' } 1 0.89316 0.88579 0.60415 0.99902 0.78009
{'fl_cov_v' } 6.5234 4.7186 0.76066 0.98362 7.2841 0.46879
{'fl_cor_v' } 0.89316 1 0.99645 0.84334 0.9119 0.85658
{'fl_cov_c' } 1.0466 0.76066 0.1235 0.15645 1.1701 0.077707
{'fl_cor_c' } 0.88579 0.99645 1 0.82914 0.9055 0.87766
{'fl_cov_y' } 1.0907 0.98362 0.15645 0.2883 1.2471 0.0772
{'fl_cor_y' } 0.60415 0.84334 0.82914 1 0.63165 0.57067
{'fl_cov_coh' } 12.352 7.2841 1.1701 1.2471 13.522 0.73855
{'fl_cor_coh' } 0.99902 0.9119 0.9055 0.63165 1 0.79716
{'fl_cov_savefraccoh'} 0.66084 0.46879 0.077707 0.0772 0.73855 0.063478
{'fl_cor_savefraccoh'} 0.78009 0.85658 0.87766 0.57067 0.79716 1
{'fracByP0_01' } 0 -7.0657e-06 2.6272e-05 3.0716e-05 8.3673e-06 0
{'fracByP0_1' } 0 8.1733e-05 0.00058172 0.0003 0.00018482 0
{'fracByP1' } 0 0.0025825 0.0055755 0.0043105 0.0017358 0
{'fracByP5' } 1.3446e-07 0.020553 0.028388 0.023343 0.0084443 1.165e-06
{'fracByP10' } 0.00082822 0.048923 0.059616 0.051792 0.020041 0.0045383
{'fracByP20' } 0.010119 0.11678 0.1368 0.1176 0.051426 0.041679
{'fracByP25' } 0.019764 0.15445 0.17846 0.15402 0.071298 0.07291
{'fracByP30' } 0.033198 0.19437 0.22195 0.19279 0.094487 0.11072
{'fracByP40' } 0.072799 0.28088 0.31405 0.27516 0.15079 0.20093
{'fracByP50' } 0.13186 0.37535 0.41129 0.36559 0.22202 0.30846
{'fracByP60' } 0.21318 0.47748 0.51316 0.46495 0.30966 0.42828
{'fracByP70' } 0.32222 0.58845 0.62103 0.57307 0.41837 0.55682
{'fracByP75' } 0.39045 0.64744 0.67785 0.63075 0.48233 0.62537
{'fracByP80' } 0.46786 0.7092 0.73555 0.69205 0.55399 0.69588
{'fracByP90' } 0.66756 0.84275 0.8587 0.82726 0.72947 0.84385
{'fracByP95' } 0.80166 0.91607 0.92521 0.90478 0.84112 0.91991
{'fracByP99' } 0.94602 0.98111 0.98335 0.97699 0.95791 0.98349
{'fracByP99_9' } 0.99264 0.99789 0.9981 0.99714 0.99438 0.99831
{'fracByP99_99' } 0.99908 0.99977 0.99979 0.99966 0.9993 0.99983