Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • giovanma/dynare
  • giorgiomas/dynare
  • Vermandel/dynare
  • Dynare/dynare
  • normann/dynare
  • MichelJuillard/dynare
  • wmutschl/dynare
  • FerhatMihoubi/dynare
  • sebastien/dynare
  • lnsongxf/dynare
  • rattoma/dynare
  • CIMERS/dynare
  • FredericKarame/dynare
  • SumuduK/dynare
  • MinjeJeon/dynare
  • camilomrch/dynare
  • DoraK/dynare
  • avtishin/dynare
  • selma/dynare
  • claudio_olguin/dynare
  • jeffjiang07/dynare
  • EthanSystem/dynare
  • stepan-a/dynare
  • wjgatt/dynare
  • JohannesPfeifer/dynare
  • gboehl/dynare
  • chskcau/dynare-doc-fixes
27 results
Show changes
Commits on Source (46)
Showing
with 338 additions and 130 deletions
......@@ -9709,12 +9709,6 @@ A @code{nobs}*1 cell of strings or a @code{nobs}*p character array, the names of
@item tex
A @code{nobs}*1 cell of strings or a @code{nobs}*p character array, the tex names of the variables.
@item freq
A scalar integer equal to 1, 4, 12 or 52, the frequency of the dataset.
@item init
A single element @dates object, the initial date of the sample.
@item dates
A @dates object with @code{nobs} element, the dates of the sample.
......@@ -9723,13 +9717,13 @@ A @code{nobs} by @code{vobs} array of doubles, the data.
@end table
@noindent @code{freq}, @code{nobs}, @code{vobs}, @code{data}, @code{name}, @code{tex} are private members. The following constructors are available:
@noindent @code{nobs}, @code{vobs}, @code{data}, @code{name}, @code{tex} are private members. The following constructors are available:
@deftypefn {dseries} dseries ()
@deftypefnx {dseries} dseries (@var{INITIAL_DATE})
@deftypefnx {dseries} dseries (@var{RANGE_OF_DATES})
Instantiates an empty @dseries object, with, if defined, an initial date given by the single element @dates object @var{INITIAL_DATE} or the first element of the @dates object @var{RANGE_OF_DATES} (the frequency is then set accordingly).
Instantiates an empty @dseries object, with, if defined, an initial date given by the single element @dates object @var{INITIAL_DATE} or the first element of the @dates object @var{RANGE_OF_DATES}.
@end deftypefn
......@@ -10156,6 +10150,24 @@ ans is a dseries object:
@sp 1
@deftypefn {dseries} {@var{f} =} freq (@var{B})
Returns the frequency of the variables in @dseries object @var{B}.
@examplehead
@example
>> ts = dseries(randn(3,2),'1973Q1');
>> ts.freq
ans =
4
@end example
@end deftypefn
@sp 1
@deftypefn{dseries} {@var{D} =} horzcat (@var{A}, @var{B}[, ...])
Overloads the @code{horzcat} Matlab/Octave's method for @dseries
......@@ -10273,6 +10285,21 @@ The previous code should produce something like:
@sp 1
@deftypefn {dseries} {@var{f} =} init (@var{B})
Returns the initial date in @dseries object @var{B}.
@examplehead
@example
>> ts = dseries(randn(3,2),'1973Q1');
>> ts.init
ans = <dates: 1973Q1>
@end example
@end deftypefn
@sp 1
@deftypefn {dseries} {@var{C} = } insert (@var{A}, @var{B}, @var{I})
Inserts variables contained in @dseries object @var{B} in @dseries object @var{A} at positions specified by integer scalars in vector @var{I}, returns augmented @dseries object @var{C}. The integer scalars in @var{I} must take values between @code{1} and @code{A.length()+1} and refers to @var{A}'s column numbers. The @dseries objects @var{A} and @var{B} need not to be defined over the same time ranges, but it is assumed that they have common frequency.
......@@ -10389,6 +10416,21 @@ ans is a dseries object:
@sp 1
@deftypefn {dseries} {@var{l} =} last (@var{B})
Returns the last date in @dseries object @var{B}.
@examplehead
@example
>> ts = dseries(randn(3,2),'1973Q1');
>> ts.last
ans = <dates: 1973Q3>
@end example
@end deftypefn
@sp 1
@deftypefn {dseries} {@var{B} = } lead (@var{A}[, @var{p}])
Returns leaded time series. Default value of @var{p}, the number of leads, is @code{1}. As for the @code{lag} method, the @dseries class overloads the parenthesis so that @code{ts.lead(p)} is equivalent to @code{ts(p)}.
......@@ -10844,6 +10886,40 @@ ts1 is a dseries object:
@sp 1
@deftypefn{dseries} {@var{C} =} remove (@var{A}, @var{B})
Alias for the @code {pop} method with two arguments. Removes variable @var{B} from @dseries object @var{A}.
@examplehead
@example
>> ts0 = dseries(ones(3,3));
>> ts1 = ts0.remove('Variable_2');
ts1 is a dseries object:
| Variable_1 | Variable_3
1Y | 1 | 1
2Y | 1 | 1
3Y | 1 | 1
@end example
@sp 1
A shorter syntax is available: @code{remove(ts,'Variable_2')} is
equivalent to @code{ts@{'Variable_2'@} = []} (@code{[]} can be replaced
by any empty object). This alternative syntax is usefull if more than
one variable has to be removed. For instance:
@example
ts@{'Variable_@@2,3,4@@'@} = [];
@end example
will remove @code{Variable_2}, @code{Variable_3} and @code{Variable_4}
from @dseries object @code{ts} (if these variables exist). Regular
expressions cannot be used but implicit loops can.
@end deftypefn
@sp 1
@deftypefn{dseries} {@var{B} =} rename (@var{A},@var{oldname},@var{newname})
Rename variable @var{oldname} to @var{newname} in @dseries object
......
......@@ -30,7 +30,7 @@ function C = colon(varargin) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isequal(nargin,2)
if isequal(nargin,2)
A = varargin{1};
B = varargin{2};
d = 1;
......@@ -68,23 +68,46 @@ end
C = dates();
n = (B-A)+1;
m = n;
if d>1
m = length(1:d:n);
end
C.freq = A.freq;
C.ndat = n;
C.time = NaN(n,2);
C.time(1,:) = A.time;
current_date = A;
linee = 1;
while current_date<B
linee = linee+1;
C.time(linee,:) = add_periods_to_array_of_dates(C.time(linee-1,:), C.freq, d);
current_date = current_date + d;
if isequal(C.freq,1)
C.ndat = m;
C.time = NaN(m,2);
C.time(:,1) = A.time(1)+transpose(0:d:n-1);
C.time(:,2) = 1;
else
C.time = NaN(n,2);
initperiods = min(C.freq-A.time(2)+1,n);
C.time(1:initperiods,1) = A.time(1);
C.time(1:initperiods,2) = transpose(A.time(2)-1+(1:initperiods));
if n>initperiods
p = n-initperiods;
if p<=C.freq
C.time(initperiods+(1:p),1) = A.time(1)+1;
C.time(initperiods+(1:p),2) = transpose(1:p);
else
q = fix(p/C.freq);
r = rem(p,C.freq);
C.time(initperiods+(1:C.freq*q),2) = repmat(transpose(1:C.freq),q,1);
C.time(initperiods+(1:C.freq*q),1) = kron(A.time(1)+transpose(1:q),ones(C.freq,1));
if r>0
C.time(initperiods+C.freq*q+(1:r),1) = C.time(initperiods+C.freq*q,1)+1;
C.time(initperiods+C.freq*q+(1:r),2) = transpose(1:r);
end
end
end
if d>1
C.time = C.time(1:d:n,:);
C.ndat = m;
else
C.ndat = n;
end
end
C.time = C.time(1:linee,:);
C.ndat = rows(C.time);
%@test:1
%$ % Define two dates
%$ date_1 = '1950Q2';
......@@ -149,4 +172,21 @@ C.ndat = rows(C.time);
%$ t(1) = dyn_assert(d.time,e.time);
%$ t(2) = dyn_assert(d.freq,e.freq);
%$ T = all(t);
%$ @eof:3
\ No newline at end of file
%$ @eof:3
%$ @test:4
%$ % Create an empty dates object for quaterly data
%$ qq = dates('Q');
%$
%$ % Define expected results.
%$ e.freq = 4;
%$ e.time = [1950 1; 1950 2; 1950 3];
%$
%$ % Call the tested routine.
%$ d = qq(1950,1):qq(1950,3);
%$
%$ % Check the results.
%$ t(1) = dyn_assert(d.time,e.time);
%$ t(2) = dyn_assert(d.freq,e.freq);
%$ T = all(t);
%$ @eof:4
\ No newline at end of file
......@@ -60,10 +60,16 @@ function dd = dates(varargin) % --*-- Unitary tests --*--
% 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/>.
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
dd = struct('ndat', 0, 'freq', NaN(0), 'time', NaN(0,2));
dd = class(dd,'dates');
if nargin>0 && ischar(varargin{1}) && isequal(varargin{1},'initialize')
dd = struct('ndat', 0, 'freq', NaN(0), 'time', NaN(0,2));
dd = class(dd,'dates');
assignin('base','emptydatesobject',dd);
return
end
dd = evalin('base','emptydatesobject');
switch nargin
case 0
......@@ -104,7 +110,7 @@ switch nargin
dd = subsref(dd,S);
return
else
error(['dates::dates: Wrong calling sequence!'])
error('dates::dates: Wrong calling sequence!')
end
for i=2:dd.ndat
if isdate(varargin{i})
......@@ -112,10 +118,10 @@ switch nargin
if isequal(date.freq,dd.freq)
dd.time(i,:) = date.time;
else
error(['dates::dates: Check that all the inputs have the same frequency (see input number ' str2num(i) ')!'])
error(sprintf('dates::dates: Check that all the inputs have the same frequency (see input number %i)!',i))
end
else
error(['dates::dates: Input ' str2num(i) ' has to be a string date!'])
error(sprintf('dates::dates: Input %i has to be a string date!',i))
end
end
end
......
......@@ -43,26 +43,41 @@ if isequal(A.ndat, B.ndat)
C = (A==B);
idx = find(C==0);
for i=1:length(idx)
C(idx(i)) = compare_vectors(@gt, A.time(idx(i),:), B.time(idx(i),:));
C(idx(i)) = greaterorequal(A.time(idx(i),:), B.time(idx(i),:));
end
else
if isequal(A.ndat,1) && isequal(B.ndat,1)
C = compare_vectors(@ge, A.time, B.time);
elseif isequal(A.ndat,1)
if isequal(A.ndat,1)
C = NaN(B.ndat,1);
for i=1:B.ndat
C(i) = compare_vectors(@ge, A.time, B.time(i,:));
C(i) = greaterorequal(A.time, B.time(i,:));
end
elseif isequal(B.ndat,1)
C = NaN(A.ndat,1);
for i=1:A.ndat
C(i) = compare_vectors(@ge, A.time(i,:), B.time);
C(i) = greaterorequal(A.time(i,:), B.time);
end
else
C = 0;
end
end
function c = greaterorequal(a,b)
if a(1)>b(1)
c = 1;
else
if a(1)<b(1)
c = 0;
else
if a(2)>=b(2)
c = 1;
else
c = 0;
end
end
end
%@test:1
%$ % Define some dates
%$ date_2 = '1950Q2';
......
......@@ -42,26 +42,40 @@ end
if isequal(A.ndat, B.ndat)
C = NaN(A.ndat,1);
for i=1:A.ndat
C(i) = compare_vectors(@gt, A.time(i,:), B.time(i,:));
C(i) = greaterthan(A.time(i,:), B.time(i,:));
end
else
if isequal(A.ndat,1) && isequal(B.ndat,1)
C = compare_vectors(@gt, A.time, B.time);
elseif isequal(A.ndat,1)
if isequal(A.ndat,1)
C = NaN(B.ndat,1);
for i=1:B.ndat
C(i) = compare_vectors(@gt, A.time, B.time(i,:));
C(i) = greaterthan(A.time, B.time(i,:));
end
elseif isequal(B.ndat,1)
C = NaN(A.ndat,1);
for i=1:A.ndat
C(i) = compare_vectors(@gt, A.time(i,:), B.time);
C(i) = greaterthan(A.time(i,:), B.time);
end
else
C = 0;
end
end
function c = greaterthan(a,b)
if a(1)>b(1)
c = 1;
else
if a(1)<b(1)
c = 0;
else
if a(2)>b(2)
c = 1;
else
c = 0;
end
end
end
%@test:1
%$ % Define some dates
%$ date_2 = '1950Q2';
......
......@@ -43,26 +43,41 @@ if isequal(A.ndat, B.ndat)
C = (A==B);
idx = find(C==0);
for i=1:length(idx)
C(idx(i)) = compare_vectors(@lt, A.time(idx(i),:), B.time(idx(i),:));
C(idx(i)) = lessorequal(A.time(idx(i),:), B.time(idx(i),:));
end
else
if isequal(A.ndat,1) && isequal(B.ndat,1)
C = compare_vectors(@le, A.time, B.time);
elseif isequal(A.ndat,1)
if isequal(A.ndat,1)
C = NaN(B.ndat,1);
for i=1:B.ndat
C(i) = compare_vectors(@le, A.time, B.time(i,:));
C(i) = lessorequal(A.time, B.time(i,:));
end
elseif isequal(B.ndat,1)
C = NaN(A.ndat,1);
for i=1:A.ndat
C(i) = compare_vectors(@le, A.time(i,:), B.time);
C(i) = lessorequal(A.time(i,:), B.time);
end
else
C = 0;
end
end
function c = lessorequal(a, b)
if a(1)<b(1)
c = 1;
else
if a(1)>b(1)
c = 0;
else
if a(2)<=b(2)
c = 1;
else
c = 0;
end
end
end
%@test:1
%$ % Define some dates
%$ date_2 = '1950Q2';
......@@ -79,7 +94,7 @@ end
%$ i2 = (d3<=d4);
%$ i3 = (d4<=d2);
%$ i4 = (d5<=d4);
%$ i5 = (d5<=d5);
%$ i5 = (d5<=d5);
%$
%$ % Check the results.
%$ t(1) = dyn_assert(i1,1);
......
......@@ -42,26 +42,39 @@ end
if isequal(A.ndat, B.ndat)
C = NaN(A.ndat,1);
for i=1:A.ndat
C(i) = compare_vectors(@lt, A.time(i,:), B.time(i,:));
C(i) = lessthan(A.time(i,:),B.time(i,:));
end
else
if isequal(A.ndat,1) && isequal(B.ndat,1)
C = compare_vectors(@lt, A.time, B.time);
elseif isequal(A.ndat,1)
if isequal(A.ndat,1)
C = NaN(B.ndat,1);
for i=1:B.ndat
C(i) = compare_vectors(@lt, A.time, B.time(i,:));
C(i) = lessthan(A.time,B.time(i,:));
end
elseif isequal(B.ndat,1)
C = NaN(A.ndat,1);
for i=1:A.ndat
C(i) = compare_vectors(@lt, A.time(i,:), B.time);
C(i) = lessthan(A.time(i,:),B.time);
end
else
C = 0;
end
end
function c = lessthan(a,b)
if a(1)<b(1)
c = 1;
else
if a(1)>b(1)
c = 0;
else
if a(2)<b(2)
c = 1;
else
c = 0;
end
end
end
%@test:1
%$ % Define some dates
%$ date_2 = '1950Q2';
......
......@@ -93,7 +93,7 @@ switch S(1).type
elseif isequal(m,1)
B.time = [S(1).subs{2}, ones(n,1)];
else
error(['dates::subsref: This is a bug!'])
error('dates::subsref: This is a bug!')
end
B.ndat = rows(B.time);
elseif isequal(length(S(1).subs),3)
......@@ -148,7 +148,7 @@ switch S(1).type
elseif isequal(m,1) && isequal(B.freq,1)
B.time = [S(1).subs{1}, ones(n,1)];
else
error(['dates::subsref: This is a bug!'])
error('dates::subsref: This is a bug!')
end
B.ndat = rows(B.time);
else
......@@ -267,7 +267,7 @@ end
%$
%$ % Define a ranges of dates using qq.
%$ try
%$ r1 = qq(1950,1):qq([1950, 3]);
%$ r1 = qq(1950,1):qq(1950,3);%qq([1950, 3]);
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
......
......@@ -40,10 +40,8 @@ function A = abs(B) % --*-- Unitary tests --*--
A = dseries();
A.freq = B.freq;
A.nobs = B.nobs;
A.vobs = B.vobs;
A.init = B.init;
A.dates = B.dates;
A.name = cell(A.vobs,1);
A.tex = cell(A.vobs,1);
......
......@@ -44,50 +44,50 @@ function [a,b] = align(a, b) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~isequal(a.freq,b.freq)
if ~isequal(frequency(a),frequency(b))
error(['dseries::align: ''' inputname(1) ''' and ''' inputname(2) ''' dseries objects must have common frequencies!'])
end
init = min(a.init,b.init);
init = min(firstdate(a),firstdate(b));
last = max(lastdate(a),lastdate(b));
time_range_of_a = a.init:a.init+a.nobs;
time_range_of_b = b.init:b.init+b.nobs;
last_a = time_range_of_a(a.nobs);
last_b = time_range_of_b(b.nobs);
common_time_range = intersect(time_range_of_a,time_range_of_b);
if isempty(common_time_range)
if isempty(intersect(a.dates,b.dates))
error(['dseries::align: ''' inputname(1) ''' and ''' inputname(2) ''' dseries object must have at least one common date!'])
end
if a.init<b.init
n = b.init-a.init;
a_init = init;
b_init = init;
a_last = last;
b_last = last;
if firstdate(b)>init
n = firstdate(b)-init;
b.data = [NaN(n,b.vobs); b.data];
b.nobs = b.nobs+n;
b.init = init;
b_init = init;
end
if a.init>b.init
n = a.init-b.init;
if firstdate(a)>init
n = firstdate(a)-init;
a.data = [NaN(n,a.vobs); a.data];
a.nobs = a.nobs+n;
a.init = init;
a_init = init;
end
if last_a>last_b
n = last_a-last_b;
if lastdate(b)<last
n = last-lastdate(b);
b.data = [b.data; NaN(n,b.vobs)];
b.nobs = b.nobs+n;
elseif last_a<last_b
n = last_b-last_a;
end
if lastdate(a)<last
n = last-lastdate(a);
a.data = [a.data; NaN(n,a.vobs)];
a.nobs = a.nobs+n;
end
a.dates = a.init:a.init+(a.nobs-1);
b.dates = b.init:b.init+(b.nobs-1);
a.dates = a_init:a_init+(a.nobs-1);
b.dates = b_init:b_init+(b.nobs-1);
%@test:1
%$ % Define a datasets.
......@@ -111,7 +111,7 @@ b.dates = b.init:b.init+(b.nobs-1);
%$ catch
%$ t(1) = 0;
%$ end
%$
%$
%$ if t(1)
%$ t(2) = dyn_assert(ts1.nobs,ts2.nobs);
%$ t(3) = dyn_assert(isequal(ts1.init,ts2.init),1);
......
......@@ -94,8 +94,8 @@ end
% Update dseries object.
ts.data = tmp(K+1:end-K,:);
ts.nobs = ts.nobs-2*K;
ts.init = ts.init+K;
ts.dates = ts.init:ts.init+(ts.nobs-1);
init = firstdate(ts)+K;
ts.dates = init:init+(ts.nobs-1);
%@test:1
%$ plot_flag = 0;
......
function vs = chain(ts,us)
function vs = chain(ts,us) % --*-- Unitary tests --*--
% Copyright (C) 2014 Dynare Team
%
......@@ -21,11 +21,11 @@ if ts.vobs-us.vobs
error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have the same number of variables!'])
end
if ts.freq-us.freq
if frequency(ts)-frequency(us)
error(['dseries::chain: dseries objects ' inputname(1) ' and ' inputname(2) ' must have common frequencies!'])
end
if ts.dates(end)<us.dates(1)
if lastdate(ts)<firstdate(us)
error(['dseries::chain: The last date in ' inputname(1) ' (' date2string(ts.dates(end)) ') must not preceed the first date in ' inputname(2) ' (' date2string(us.dates(1)) ')!'])
end
......@@ -37,7 +37,7 @@ vs = ts;
vs.data = [vs.data; bsxfun(@times,CumulatedGrowthFactors,vs.data(end,:))];
vs.nobs = rows(vs.data);
vs.dates = vs.init:(vs.init+vs.nobs);
vs.dates = firstdate(vs):firstdate(vs)+vs.nobs;
%@test:1
%$ try
......
......@@ -69,7 +69,7 @@ if ~isequal(numel(unique(A.name)),numel(A.name));
return
end
if ~isequa(numel(unique(A.tex)),numel(A.tex));
if ~isequal(numel(unique(A.tex)),numel(A.tex));
error_flag = 1;
if nargout>1
message = ['dseries: The variable tex names in dseries object ''' inputname(1) ''' are not unique!'];
......@@ -77,7 +77,7 @@ if ~isequa(numel(unique(A.tex)),numel(A.tex));
return
end
if ~isequal(A.dates,A.init:A.init+A.nobs)
if ~isequal(A.dates,firstdate(A):firstdate(A)+A.nobs)
error_flag = 1;
if nargout>1
message = ['dseries: Wrong definition of the dates member in dseries object ''' inputname(1) '''!'];
......
......@@ -67,7 +67,7 @@ switch nargin
B = cumprod(varargin{1});
t = find(B.dates==varargin{2});
if isempty(t)
if varargin{2}==(B.init-1)
if varargin{2}==(firstdate(B)-1)
return
else
error(['dseries::cumprod: date ' date2string(varargin{2}) ' is not in the sample!'])
......@@ -96,7 +96,7 @@ switch nargin
B = cumprod(varargin{1});
t = find(B.dates==varargin{2});
if isempty(t)
if varargin{2}==(B.init-1)
if varargin{2}==(firstdate(B)-1)
B.data = bsxfun(@times,B.data,varargin{3}.data);
return
else
......
......@@ -66,7 +66,7 @@ switch nargin
B = cumsum(varargin{1});
t = find(B.dates==varargin{2});
if isempty(t)
if varargin{2}==(B.init-1)
if varargin{2}==(firstdate(B)-1)
return
else
error(['dseries::cumsum: date ' date2string(varargin{2}) ' is not in the sample!'])
......@@ -95,7 +95,7 @@ switch nargin
B = cumsum(varargin{1});
t = find(B.dates==varargin{2});
if isempty(t)
if varargin{2}==(B.init-1)
if varargin{2}==(firstdate(B)-1)
B.data = bsxfun(@plus,B.data,varargin{3}.data);
return
else
......
......@@ -76,18 +76,20 @@ function ts = dseries(varargin) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
ts = struct;
ts.data = [];
ts.nobs = 0;
ts.vobs = 0;
ts.name = {};
ts.tex = {};
ts.freq = [];
ts.init = dates();
ts.dates = dates();
if nargin>0 && ischar(varargin{1}) && isequal(varargin{1},'initialize')
ts = struct;
ts.data = [];
ts.nobs = 0;
ts.vobs = 0;
ts.name = {};
ts.tex = {};
ts.dates = dates();
ts = class(ts,'dseries');
assignin('base','emptydseriesobject',ts);
return
end
ts = class(ts,'dseries');
ts = evalin('base','emptydseriesobject');
switch nargin
case 0
......@@ -100,13 +102,10 @@ switch nargin
error(['dseries::dseries: Input ' inputname(1) ' (identified as a dates object) must be non empty!'])
case 1
% Create an empty dseries object with an initial date.
ts.init = varargin{1};
ts.freq = varargin{1}.freq;
ts.dates = varargin{1};
otherwise
% A range of dates is passed to the constructor
ts.dates = varargin{1};
ts.init = varargin{1}(1);
ts.freq = varargin{1}.freq;
end
return
elseif ischar(varargin{1})
......@@ -136,12 +135,11 @@ switch nargin
else
error(['dseries:: I''m not able to load data from ' inputname(1) '!'])
end
ts.init = init;
ts.freq = freq;
ts.data = data;
ts.name = varlist;
ts.vobs = length(varlist);
ts.nobs = size(data,1);
ts.dates = init:init+(ts.nobs-1);
if isempty(tex)
ts.tex = name2tex(varlist);
else
......@@ -150,10 +148,9 @@ switch nargin
elseif isnumeric(varargin{1}) && isequal(ndims(varargin{1}),2)
ts.data = varargin{1};
[ts.nobs, ts.vobs] = size(ts.data);
ts.freq = 1;
ts.init = dates(1,1);
ts.name = default_name(ts.vobs);
ts.tex = name2tex(ts.name);
ts.dates = dates(1,1):dates(1,1)+(ts.nobs-1);
end
case {2,3,4}
a = varargin{1};
......@@ -180,20 +177,15 @@ switch nargin
ts.vobs = size(a,2);
% Get the first date and set the frequency.
if isempty(b)
ts.freq = 1;
ts.init = dates(1,1);
init = dates(1,1);
elseif (isdates(b) && isequal(length(b),1))
ts.freq = b.freq;
ts.init = b;
init = b;
elseif isdate(b)% Weekly, Monthly, Quaterly or Annual data (string).
ts.init = dates(b);
ts.freq = ts.init.freq;
init = dates(b);
elseif (isnumeric(b) && isscalar(b) && isint(b)) % Yearly data.
ts.freq = 1;
ts.init = dates([num2str(b) 'Y']);
init = dates([num2str(b) 'Y']);
elseif isdates(b) % Range of dates
ts.freq = b.freq;
ts.init = b(1);
init = b(1);
if ts.nobs>1 && ~isequal(b.ndat,ts.nobs)
message = 'dseries::dseries: If second input is a range, its number of elements must match ';
message = char(message, ' the number of rows in the first input, unless the first input');
......@@ -218,7 +210,7 @@ switch nargin
if ~isempty(c)
if ts.vobs==length(c)
for i=1:ts.vobs
ts.name = vertcat(ts.name, c(i) );
ts.name = vertcat(ts.name, c(i));
end
else
error('dseries::dseries: The number of declared names does not match the number of variables!')
......@@ -242,7 +234,7 @@ switch nargin
end
if isempty(ts.dates)
ts.dates = ts.init:ts.init+(ts.nobs-1);
ts.dates = init:init+(ts.nobs-1);
end
%@test:1
......
function lastIndex = end(o, k, n)
% Copyright (C) 2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare 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 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/>.
assert(k==1 && n==1, 'dseries::end: Wrong indexing!');
lastIndex = o.vobs;
\ No newline at end of file
......@@ -49,13 +49,13 @@ if ~isequal(A.vobs,B.vobs)
return
end
if ~isequal(A.freq,B.freq)
if ~isequal(frequency(A),frequency(B))
warning('dseries::eq: Both input arguments should have the same frequencies!')
C = 0;
return
end
if ~isequal(A.init,B.init)
if ~isequal(firstdate(A),firstdate(B))
warning('dseries::eq: Both input arguments should have the same initial period!')
C = 0;
return
......
......@@ -126,8 +126,6 @@ end
A.data = B.data(:,idVariableName);
A.dates = B.dates;
A.init = B.init;
A.freq = B.freq;
A.nobs = B.nobs;
A.vobs = length(idVariableName);
A.name = B.name(idVariableName);
......
function f = firstdate(o)
% Copyright (C) 2014 Dynare Team
%
% This file is part of Dynare.
%
% Dynare 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 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/>.
f = o.dates(1);
\ No newline at end of file