recessionplot function using recession dates for a country other than USA

I have been trying to overlay recession bands to my graphs. However, the recessionplot function by default use NBER recession dates. In my case, I have the following recession dates on a quarterly basis where for example 1980.00 represent the beginning of the first quarter of the year 1983 and 1983.25 representing the beginning of the second quarter of the year 1983. Also the entry 1983.00, 1983.25 represents the begin and end quarters of the recession period.
recessionsdates=[1982.00, 1982.25
1983.00, 1983.25
1984.00, 1984.25
1986.00, 1986.25
1987.00, 1987.25
1990.75, 1991.00
1992.00, 1992.25
1993.00, 1993.25
1995.00, 1995.25
1997.00, 1997.25
1998.00, 1998.25
1999.00, 1999.25
2000.00, 2000.25
2001.00, 2001.25
2001.50, 2001.75
2002.00, 2002.25
2003.00, 2003.25
2004.00, 2004.25
2005.00, 2005.25
2006.00, 2006.25
2007.00, 2007.25
2008.00, 2008.25
2008.75, 2009.00
2009.25, 2009.50
2014.00, 2014.25
2016.00, 2016.25
2019.00, 2019.25
2020.00, 2020.50
2021.00, 2021.25];
How do I make the recessionplot function use these recessions dates?

 채택된 답변

% Pull data and plot an example from recessionplot documentation
load Data_CreditDefaults
X = Data(:,1:4);
T = numel(dates);
dates = [dates [12 31].*ones(T,2)];
dates = datetime(dates);
figure
plot(dates,X,'LineWidth',2);
xlabel("Year");
ylabel("Level");
% Use a few instances of your recession data instead of default
recessionsdates=[1982.00, 1982.25
1983.00, 1983.25
1984.00, 1984.25
1986.00, 1986.25
1987.00, 1987.25
1990.75, 1991.00
1992.00, 1992.25
1993.00, 1993.25];
% Convert your data to datetime format.
y = floor(recessionsdates);
m = 12*(recessionsdates-y);
d = 0;
recessionDatetimes = datetime(y,m,d);
% Plot the recession bands
hBands = recessionplot('recessions',recessionDatetimes);
set(hBands,'FaceColor',"r",'FaceAlpha',0.1);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Geoscience에 대해 자세히 알아보기

제품

릴리스

R2022b

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by