Skip to content
Snippets Groups Projects
Verified Commit 7451e59d authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Added conversion routines for dates.

Conversion of daily dates objects to lower frequency.
parent 4ff18a3a
Branches
No related tags found
No related merge requests found
function m = dates2M(d)
% INPUTS
% - d [dates] daily frequency object with n elements.
%
% OUTPUTS
% - m [dates] monthly frequency object with n elements (with repetitions).
% Copyright © 2020 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare dates submodule is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
time = datevec(d.time(:,1));
m = dates(12, time(:,1:2));
\ No newline at end of file
function m = dates2Q(d)
% INPUTS
% - d [dates] daily frequency object with n elements.
%
% OUTPUTS
% - q [dates] quaterly frequency object with n elements (with repetitions).
% Copyright © 2020 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare dates submodule is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
time = datevec(d.time(:,1));
time = time(:,1:2);
isq1 = arrayfun( @(m) ismember(m, [1, 2, 3]), time(:,2));
isq2 = arrayfun( @(m) ismember(m, [4, 5, 6]), time(:,2));
isq3 = arrayfun( @(m) ismember(m, [7, 8, 9]), time(:,2));
isq4 = arrayfun( @(m) ismember(m, [10, 11, 12]), time(:,2));
time(isq1,2) = 1;
time(isq2,2) = 2;
time(isq3,2) = 3;
time(isq4,2) = 4;
m = dates(4, time(:,1:2));
\ No newline at end of file
function y = dates2Y(d)
% INPUTS
% - d [dates] daily frequency object with n elements.
%
% OUTPUTS
% - y [dates] annual frequency object with n elements (with repetitions).
% Copyright © 2020 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare dates submodule is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
time = datevec(d.time(:,1));
y = dates(1, time(:,1));
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment