Add new option (--method).
Possible values are cumulate (default value) or diff.kalman-mex
parent
12cca117bc
commit
33f2456acf
|
@ -18,6 +18,7 @@ function dcontrib(varargin)
|
||||||
% --database dseries object
|
% --database dseries object
|
||||||
% --baseline dseries object (path for the exogenous variables)
|
% --baseline dseries object (path for the exogenous variables)
|
||||||
% --range followed by a dates range
|
% --range followed by a dates range
|
||||||
|
% --method followed by cumulate (default) or diff.
|
||||||
%
|
%
|
||||||
% REMARKS
|
% REMARKS
|
||||||
% [1] --baseline and --range are not compatible.
|
% [1] --baseline and --range are not compatible.
|
||||||
|
@ -50,6 +51,7 @@ function dcontrib(varargin)
|
||||||
disp('--database followed by dseries object [mandatory]')
|
disp('--database followed by dseries object [mandatory]')
|
||||||
disp('--baseline followed by dseries object (path for the exogenous variables)')
|
disp('--baseline followed by dseries object (path for the exogenous variables)')
|
||||||
disp('--range followed by a dates range')
|
disp('--range followed by a dates range')
|
||||||
|
disp('--method followed by keywords cumulate or diff')
|
||||||
disp('--output followed by a name for the structure holding the results [mandatory]')
|
disp('--output followed by a name for the structure holding the results [mandatory]')
|
||||||
skipline()
|
skipline()
|
||||||
return
|
return
|
||||||
|
@ -115,6 +117,9 @@ function dcontrib(varargin)
|
||||||
baseline = dseries(baseline, firstperiod, M_.exo_names);
|
baseline = dseries(baseline, firstperiod, M_.exo_names);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
% get method for computing contributions
|
||||||
|
method = getmethod(varargin);
|
||||||
|
|
||||||
% Restrict the observations for the exogenous variables to the pertinent tim range
|
% Restrict the observations for the exogenous variables to the pertinent tim range
|
||||||
xvariables = xvariables(firstperiod:lastperiod);
|
xvariables = xvariables(firstperiod:lastperiod);
|
||||||
|
|
||||||
|
@ -126,15 +131,15 @@ function dcontrib(varargin)
|
||||||
|
|
||||||
% contributions is a dseries object holding the marginal contribution of the baseline and
|
% contributions is a dseries object holding the marginal contribution of the baseline and
|
||||||
% each exogenous variable to endogenous variable z
|
% each exogenous variable to endogenous variable z
|
||||||
% contributions.baseline = S.baseline(firstperiod:lastperiod);
|
|
||||||
|
|
||||||
|
switch method
|
||||||
|
case 'cumulate'
|
||||||
% Add exogenous variables one by one and simulate the model (-> cumulated contributions)
|
% Add exogenous variables one by one and simulate the model (-> cumulated contributions)
|
||||||
for i=1:xvariables.vobs
|
for i=1:xvariables.vobs
|
||||||
name = xvariables.name{i};
|
name = xvariables.name{i};
|
||||||
baseline{name} = xvariables{name};
|
baseline{name} = xvariables{name};
|
||||||
S.(name) = simul_backward_model(initialconditions, lastperiod-firstperiod+1, baseline);
|
S.(name) = simul_backward_model(initialconditions, lastperiod-firstperiod+1, baseline);
|
||||||
end
|
end
|
||||||
|
|
||||||
% Compute marginal contributions
|
% Compute marginal contributions
|
||||||
for j=1:length(variables)
|
for j=1:length(variables)
|
||||||
cumulatedcontribs = S.baseline{variables{j}}(firstperiod:lastperiod).data;
|
cumulatedcontribs = S.baseline{variables{j}}(firstperiod:lastperiod).data;
|
||||||
|
@ -148,6 +153,28 @@ function dcontrib(varargin)
|
||||||
end
|
end
|
||||||
contributions.(variables{j}) = contributions.(variables{j})(firstperiod:lastperiod);
|
contributions.(variables{j}) = contributions.(variables{j})(firstperiod:lastperiod);
|
||||||
end
|
end
|
||||||
|
case 'diff'
|
||||||
|
for i=1:xvariables.vobs
|
||||||
|
name = xvariables.name{i};
|
||||||
|
Baseline = baseline;
|
||||||
|
Baseline{name} = xvariables{name};
|
||||||
|
S.(name) = simul_backward_model(initialconditions, lastperiod-firstperiod+1, Baseline);
|
||||||
|
end
|
||||||
|
% Compute marginal contributions (removing baseline)
|
||||||
|
for j=1:length(variables)
|
||||||
|
cumulatedcontribs = S.baseline{variables{j}}(firstperiod:lastperiod).data;
|
||||||
|
contributions.(variables{j}) = dseries(cumulatedcontribs, firstperiod, 'baseline');
|
||||||
|
for i=1:xvariables.vobs
|
||||||
|
name = xvariables.name{i};
|
||||||
|
ts = S.(name);
|
||||||
|
data = ts{variables{j}}(firstperiod:lastperiod).data;
|
||||||
|
contributions.(variables{j}) = [contributions.(variables{j}), dseries(data-cumulatedcontribs, firstperiod, name)];
|
||||||
|
end
|
||||||
|
contributions.(variables{j}) = contributions.(variables{j})(firstperiod:lastperiod);
|
||||||
|
end
|
||||||
|
otherwise
|
||||||
|
error('Unknown method (%s)', method)
|
||||||
|
end
|
||||||
|
|
||||||
% Save output in caller workspace
|
% Save output in caller workspace
|
||||||
oname = getoutputname(varargin);
|
oname = getoutputname(varargin);
|
||||||
|
@ -188,7 +215,7 @@ function eqtags = geteqtags(cellarray)
|
||||||
% OUTPUTS
|
% OUTPUTS
|
||||||
% - eqtags [char] 1×p cell array of row char arrays.
|
% - eqtags [char] 1×p cell array of row char arrays.
|
||||||
|
|
||||||
[~, vpos, ~, ~, ~, ~, indices] = positions(cellarray);
|
[~, vpos, ~, ~, ~, ~, ~, indices] = positions(cellarray);
|
||||||
|
|
||||||
lastvalue = indices(find(indices==vpos)+1)-1;
|
lastvalue = indices(find(indices==vpos)+1)-1;
|
||||||
|
|
||||||
|
@ -279,7 +306,30 @@ function oname = getoutputname(cellarray)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function [mpos, vpos, dpos, rpos, bpos, opos, indices] = positions(cellarray)
|
function method = getmethod(cellarray)
|
||||||
|
|
||||||
|
% Return the method for computing the dynaamic contributions.
|
||||||
|
%
|
||||||
|
% INPUTS
|
||||||
|
% - cellarray [char] 1×n cell array of row char arrays.
|
||||||
|
%
|
||||||
|
% OUTPUTS
|
||||||
|
% - method [char] method: 'cumulate' or 'diff'
|
||||||
|
|
||||||
|
[~, ~, ~, ~, ~, ~, kpos] = positions(cellarray);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if isempty(kpos)
|
||||||
|
method = 'cumulate';
|
||||||
|
else
|
||||||
|
method = cellarray{kpos+1};
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function [mpos, vpos, dpos, rpos, bpos, opos, kpos, indices] = positions(cellarray)
|
||||||
|
|
||||||
% Return positions of the arguments.
|
% Return positions of the arguments.
|
||||||
%
|
%
|
||||||
|
@ -293,6 +343,7 @@ function [mpos, vpos, dpos, rpos, bpos, opos, indices] = positions(cellarray)
|
||||||
% - rpos [integer] scalar, index for the --range argument.
|
% - rpos [integer] scalar, index for the --range argument.
|
||||||
% - bpos [integer] scalar. index for the --baseline argument.
|
% - bpos [integer] scalar. index for the --baseline argument.
|
||||||
% - opos [integer] scalar, index for the --output argument.
|
% - opos [integer] scalar, index for the --output argument.
|
||||||
|
% - kpos [integer] scalar, index for the --method argument.
|
||||||
|
|
||||||
% Index for --model argument
|
% Index for --model argument
|
||||||
mpos = find(strcmp('--model', cellarray));
|
mpos = find(strcmp('--model', cellarray));
|
||||||
|
@ -342,7 +393,13 @@ function [mpos, vpos, dpos, rpos, bpos, opos, indices] = positions(cellarray)
|
||||||
error('dplot::positions: Only one --periods argument is allowed.')
|
error('dplot::positions: Only one --periods argument is allowed.')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
% Index for --method argument
|
||||||
|
kpos = find(strcmp('--method', cellarray));
|
||||||
|
if length(kpos)>1
|
||||||
|
error('dplot::positions: Only one --method argument is allowed.')
|
||||||
|
end
|
||||||
|
|
||||||
% Sorted vector of indices
|
% Sorted vector of indices
|
||||||
indices = sort([mpos; vpos; dpos; rpos; bpos; opos]);
|
indices = sort([mpos; vpos; dpos; rpos; bpos; opos; kpos]);
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue