time | Calls | line |
---|
| | 28 | function [ar_disc_ar1, mt_disc_ar1_trans] = ffy_rouwenhorst(varargin)
|
| | 29 |
|
< 0.001 | 1 | 30 | if (~isempty(varargin))
|
| | 31 |
|
< 0.001 | 1 | 32 | bl_verbose = false;
|
< 0.001 | 1 | 33 | it_std_bound = 0;
|
| | 34 |
|
< 0.001 | 1 | 35 | if (length(varargin) == 3)
|
< 0.001 | 1 | 36 | [fl_ar1_persistence, fl_shk_std, it_disc_points] = varargin{:};
|
| | 37 | elseif (length(varargin) == 4)
|
| | 38 | [fl_ar1_persistence, fl_shk_std, it_disc_points, ...
|
| | 39 | bl_verbose] = varargin{:};
|
| | 40 | elseif (length(varargin) == 5)
|
| | 41 | [fl_ar1_persistence, fl_shk_std, it_disc_points, ...
|
| | 42 | bl_verbose, it_std_bound] = varargin{:};
|
| | 43 | else
|
| | 44 | error('Must specify three parameters.');
|
< 0.001 | 1 | 45 | end
|
| | 46 |
|
< 0.001 | 1 | 47 | if (it_disc_points<=1)
|
| | 48 | error('Must discretize to more than 1 point.');
|
< 0.001 | 1 | 49 | end
|
| | 50 |
|
| | 51 | else
|
| | 52 |
|
| | 53 | fl_ar1_persistence = 0.60;
|
| | 54 | fl_shk_std = 0.20;
|
| | 55 | it_disc_points = 5;
|
| | 56 | it_std_bound = 0;
|
| | 57 | bl_verbose = true;
|
| | 58 |
|
< 0.001 | 1 | 59 | end
|
| | 60 |
|
| | 61 | % standard deviation of the AR1 process
|
< 0.001 | 1 | 62 | fl_sig_ar1 = sqrt(fl_shk_std^2/(1-fl_ar1_persistence^2));
|
| | 63 |
|
| | 64 | % bounds
|
< 0.001 | 1 | 65 | if (it_std_bound==0)
|
< 0.001 | 1 | 66 | fl_ar1_end = sqrt(it_disc_points-1)*fl_sig_ar1;
|
| | 67 | else
|
| | 68 | fl_ar1_end = abs(it_std_bound)*fl_sig_ar1;
|
< 0.001 | 1 | 69 | end
|
| | 70 |
|
| | 71 | % grid
|
< 0.001 | 1 | 72 | fl_ar1_beg = -fl_ar1_end;
|
< 0.001 | 1 | 73 | fl_ar1_step = (fl_ar1_end-fl_ar1_beg)/(it_disc_points-1); % Could have used the command linspace
|
< 0.001 | 1 | 74 | if it_disc_points == 1
|
| | 75 | ar_disc_ar1 = 0;
|
< 0.001 | 1 | 76 | else
|
< 0.001 | 1 | 77 | ar_disc_ar1 = (fl_ar1_beg:fl_ar1_step:fl_ar1_end)';
|
< 0.001 | 1 | 78 | end
|
| | 79 |
|
| | 80 | % get mass
|
< 0.001 | 1 | 81 | fl_p0 = 0.5*(1+fl_ar1_persistence);
|
< 0.001 | 1 | 82 | fl_q0 = fl_p0;
|
0.010 | 1 | 83 | mt_disc_ar1_trans = ffy_rouwenhorst_mkv_recursive(fl_p0,fl_q0,it_disc_points);
|
| | 84 |
|
| | 85 | % print
|
< 0.001 | 1 | 86 | if (bl_verbose)
|
| | 87 |
|
| | 88 | % gather all info
|
| | 89 | mp_container_map = containers.Map('KeyType','char', 'ValueType','any');
|
| | 90 | mp_container_map('fl_ar1_persistence') = fl_ar1_persistence;
|
| | 91 | mp_container_map('fl_shk_std') = fl_shk_std;
|
| | 92 | mp_container_map('it_std_bound') = it_std_bound;
|
| | 93 | mp_container_map('fl_sig_ar1') = fl_sig_ar1;
|
| | 94 | mp_container_map('fl_ar1_end') = fl_ar1_end;
|
| | 95 | mp_container_map('fl_ar1_beg') = fl_ar1_beg;
|
| | 96 | mp_container_map('fl_ar1_step') = fl_ar1_step;
|
| | 97 | mp_container_map('ar_disc_ar1') = ar_disc_ar1;
|
| | 98 | mp_container_map('fl_p0') = fl_p0;
|
| | 99 | mp_container_map('fl_q0') = fl_q0;
|
| | 100 | mp_container_map('mt_disc_ar1_trans') = mt_disc_ar1_trans;
|
| | 101 |
|
| | 102 | % print
|
| | 103 | ff_container_map_display(mp_container_map, 50, 50);
|
| | 104 |
|
< 0.001 | 1 | 105 | end
|
| | 106 |
|
< 0.001 | 1 | 107 | end
|