📄 plt_turnsd.m
字号:
% PURPOSE: demo of fturns() % find turning points in time-series % %---------------------------------------------------% USAGE: fturns_d%---------------------------------------------------% set downturn turning point definition% y(t-4), y(t-3), y(t-2), y(t-1) <= y(t) [seq = 0, bdt = 4, eq = 1]% which is the condition for a downturn if,% y(t+1) < y(t) we have a downturn [adt = 1]% else no downturnin.bdt = 4;in.adt = 1;in.eq = 1;in.seq = 0;% set upturn turning point definition% y(t-4), y(t-3), y(t-2), y(t-1) >= y(t) [seq = 0, but = 4, eq = 1]% which is the condition for a upturn if, % y(t+1) > y(t) we have an upturn [aut = 1]% else no upturnin.but = 4;in.aut = 1;dates = cal(1982,1,12); % create calendar structure variableload test.dat; % monthly time-series on employment for 8 statesy = growthr(test,dates); % convert to growth-ratesyt = trimr(y,dates.freq,0); % truncate initial zerostdates = cal(1983,1,12); % update calendar for truncationytime = yt(:,1); % pull out state 1 time-seriesresults = fturns(ytime,in);plt(results,tdates,'employment');title('loose non-sequential definition of turns --- produces lots of turns');pause;% Now, change to a sequential definitionin.seq = 1;% which sets downturn turning point definition to:% y(t-4) <= y(t-3) <= y(t-2) <= y(t-1) <= y(t) [seq = 1, bdt = 4, eq = 1]% which is the condition for a downturn if,% y(t+1) < y(t) we have a downturn [adt = 1]% else no downturn% and the upturn turning point definition% y(t-4) >= y(t-3) >= y(t-2) >= y(t-1) >= y(t) [seq = 1, but = 4, eq = 1]% which is the condition for a upturn if% y(t+1) > y(t) which is an upturn [aut = 1]% else no upturnresults = fturns(ytime,in);plt(results,tdates,'employment');title('sequential definition --- produces fewer turns');pause;% Now, illustrate requiring many points after the turns% which should rule out some of the turning points% seen in the above graphin.seq = 1;in.aut = 4; % 4 periods of up after an upturnin.adt = 4; % 4 periods of down after a downturn% which sets downturn turning point definition to:% y(t-4), y(t-3), y(t-2), y(t-1) <= y(t) [seq = 1, bdt = 4, eq = 1]% which is the condition for a downturn if,% y(t+4) < y(t+3) < y(t+2) < y(t+1) < y(t) we have a downturn [adt = 4]% else no downturn% and the upturn turning point definition% y(t-4), y(t-3), y(t-2), y(t-1) >= y(t) [seq = 1, bdt = 4, eq = 1]% which is the condition for a upturn if% y(t+4) > y(t+3) > y(t+2) > y(t+1) > y(t) which is an upturn [aut = 4]% else no upturnresults = fturns(ytime,in);plt_turns(results,tdates,'employment');title('tighter sequential with aut=4, adt=4 definition --- produces less turns');pause;% Now turn off the sequential requirement, which% should produce more turns that meet this looser definitionin.seq = 0;results = fturns(ytime,in);plt(results,tdates,'employment');title('looser non-sequential definition with aut=4, adt=4 --- produces more turns');pause;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -