# run Bry Boschan program

조회 수: 25(최근 30일)
ramzi 2021년 2월 24일
답변: crane lee 2021년 9월 7일
function dating=brybos(X,F)
% function dating=brybos(X,F)
% This function applies the Bry-Boschan (1971) algorithm and determines the peaks and troughs of data
% matrix X with T time series observations and N time series. The output is a (TxN) matrix where 1 signifies a
% peak and -1 a trough. F is the frequency of the observations where monthly observations are the default.
% F=0: monthly, F=1: quarterly, F=2: annual.
% For monthly data, the minimum peak-to-trough (trough-to-peak) period is 5 months and peak-to-peak
% (trough-to-trough) is 15 months. For quarterly p-to-t is 2 quarters and p-to-p is 6 quarters. For annual
% data, p-to-t is 1 year and p-to-p is 2 years.
% The program calls on the M-functions alternate.m, check.m, dates.m, enforce.m, ma.m, mcd.m, outier.m,
% qcd.m, refine.m, spencer.m
% This program was writen by Robert Inklaar, University of Groningen (May 2003) and is an adaption of the
% programs for Gauss of Mark Watson.
% The algorithm is based on Bry and Boschan (1971), 'Cyclical analysis of time series: Selected procedures
% and computer programs', NBER: New York
if nargin == 1; F=0; end
if F == 0; D=5;
elseif F == 1; D=2;
elseif F == 2; D=1;
end
N=size(X,2);
if sum(sum(isnan(X)))>0; error('Data matrix contains empty values'); end
% I - Find outliers and replace them with the Spencer curve value X=outlier(X); Moved down this step and
% only use it in step II
% II - Peaks and troughs of one-year centered moving average (enforcing alternating peaks and troughs)
if F == 0; M=12; elseif F == 1; M=4; elseif F == 2; M=1; end
Xf=ma(outlier(X),M);
[peaks,troughs] = dates(Xf,D);
[peaks,troughs] = alternate(Xf,peaks,troughs);
if F == 0;
% III - Refine peaks and troughs with Spencer curve. Also enforce alternating peaks and troughs and a
% minimum p-to-p (t-to-t) period.
Xs=spencer(X);
[peaks,troughs] = check(peaks,troughs,D);
[peaks,troughs] = refine(Xs,peaks,troughs,D);
[peaks,troughs] = alternate(Xs,peaks,troughs);
[peaks,troughs] = enforce(Xs,peaks,troughs,D);
% IV - Refine peaks and troughs with moving average determined by the number of months/quarters of
% cyclical dominance (MCD). For annual data, the cyclical dominance is set to 1 year. Also enforce
% alternating peaks and troughs.
if F == 0; cdnum=mcd(X);
elseif F == 1; cdnum=qcd(X);
else cdnum=ones(1,N);
end
for i=1:N; Xf2(:,i)=ma(X(:,i),cdnum(i)); end
[peaks,troughs] = check(peaks,troughs,D);
[peaks,troughs] = refine(Xf2,peaks,troughs,D);
[peaks,troughs] = alternate(Xf2,peaks,troughs);
% V - Refine peaks and troughs with actual series. Also enforce
% alternating peaks and troughs and a minimum p-to-p (t-to-t)period.
span=max(4,cdnum);
for i=1:N
[peaks(:,i),troughs(:,i)] = check(peaks(:,i),troughs(:,i),span(i));
[peaks(:,i),troughs(:,i)] = refine(X(:,i),peaks(:,i),troughs(:,i),span(i));
[peaks(:,i),troughs(:,i)] = alternate(X(:,i),peaks(:,i),troughs(:,i));
[peaks(:,i),troughs(:,i)] = enforce(X(:,i),peaks(:,i),troughs(:,i),span(i));
[peaks(:,i),troughs(:,i)] = alternate(X(:,i),peaks(:,i),troughs(:,i));
end
dating=peaks-troughs;
else
[peaks,troughs] = refine(X,peaks,troughs,D);
[peaks,troughs] = check(peaks,troughs,D);
[peaks,troughs] = enforce(X,peaks,troughs,D);
[peaks,troughs] = alternate(X,peaks,troughs);
[peaks,troughs] = enforce(X,peaks,troughs,D);
dating=peaks-troughs;
end
.
.
.
the following message appears when I run the Bryboschan program:
>> brybos (X,0)
Undefined function or variable 'outlier'.
Error in brybos (line 27)
Xf=ma(outlier(X),M);

댓글을 달려면 로그인하십시오.

### 답변(1개)

crane lee 2021년 9월 7일