Graph Tips – V: Vintage Data and Forecast Updates

This example introduces the use of vintage data. Using getFredData to access ALFRED allows you to get vintage data, eg. GDP for 1995 as it was actually measured in 1995 (before various revisions, re-indexing, etc.). In fact two examples are given. The first is based forecasts of the GDP growth rate and two graphs are created; one of GDP growth rates, and the other the implicit forecasts of GDP in levels. The second is based on forecasts of Potential GDP and illustrates one of the difficulties of working with vintage data, namely re-indexing and changing definitions (uses normalizations to deal with these). The three graphs that will be created are sometimes referred to as Groundhog Day graphs as they show how each day the forecasters wake up and create forecasts all over again.

 

The Matlab code to generate these is:

First Example (first two graphs)

% First, just get the graph of GDP growth
GDPgrowth=getFredData(‘GDPCA’, ‘2007-01-01’, ‘2014-12-31′,’pc1’);

% Now, get the forecasts from each year for the next two years
ForecastGDPgrowth=nan(2,2,8);
FourthQuarterGDP=nan(10,2);
FourthQuarterGDPForecasts=nan(3,2,8);
temp2=getFredData(‘GDPC1’, ‘2005-12-31’, ‘2005-12-31’);
FourthQuarterGDP(1,:)=temp2.Data;
temp2=getFredData(‘GDPC1’, ‘2006-12-31’, ‘2006-12-31′);
FourthQuarterGDP(2,:)=temp2.Data;

for t=2007:2014
ondate=[num2str(t),’-12-31′];
nextyear=[num2str(t+1),’-07-01′];
next2year=[num2str(t+2),’-07-01′];
% FOMC Summary of Economic Projections for the Growth Rate of Real Gross Domestic Product, Central Tendency, Midpoint
    %(Fourth Quarter to Fourth Quarter Percent Change, Annual, Not Seasonally Adjusted)
temp=getFredData(‘GDPC1CTM’, nextyear, next2year, [], [],[], ondate);
ForecastGDPgrowth(:,:,t-2006)=temp.Data;
temp2=getFredData(‘GDPC1’, ondate, ondate);
FourthQuarterGDP(t-2006+2,:)=temp2.Data;

FourthQuarterGDPForecasts(1,:,t-2006)=temp2.Data;
FourthQuarterGDPForecasts(2:3,1,t-2006)=temp.Data(:,1);
FourthQuarterGDPForecasts(2,2,t-2006)=temp2.Data(1,2)*(1+temp.Data(1,2)/100);
FourthQuarterGDPForecasts(3,2,t-2006)=temp2.Data(1,2)*(1+temp.Data(1,2)/100)*(1+temp.Data(2,2)/100);
end

% Graph of the growth rate forecasts
trace1= struct(‘x’, {cellstr(datestr(GDPgrowth.Data(:,1),’yyyy’))},’y’,GDPgrowth.Data(:,2),’name’, ‘Actual GDP growth’,’type’, ‘scatter’,’marker’,struct(‘size’,1));
trace2= struct(‘x’, {cellstr(datestr(ForecastGDPgrowth(:,1,1),’yyyy’))},’y’,ForecastGDPgrowth(:,2,1),’name’, ‘2007 Forecast’,’type’, ‘scatter’,’marker’,struct(‘size’,1));
trace3= struct(‘x’, {cellstr(datestr(ForecastGDPgrowth(:,1,2),’yyyy’))},’y’,ForecastGDPgrowth(:,2,2),’name’, ‘2008 Forecast’,’type’, ‘scatter’,’marker’,struct(‘size’,1));
trace4= struct(‘x’, {cellstr(datestr(ForecastGDPgrowth(:,1,3),’yyyy’))},’y’,ForecastGDPgrowth(:,2,3),’name’, ‘2009 Forecast’,’type’, ‘scatter’,’marker’,struct(‘size’,1));
trace5= struct(‘x’, {cellstr(datestr(ForecastGDPgrowth(:,1,4),’yyyy’))},’y’,ForecastGDPgrowth(:,2,4),’name’, ‘2010 Forecast’,’type’, ‘scatter’,’marker’,struct(‘size’,1));
trace6= struct(‘x’, {cellstr(datestr(ForecastGDPgrowth(:,1,5),’yyyy’))},’y’,ForecastGDPgrowth(:,2,5),’name’, ‘2011 Forecast’,’type’, ‘scatter’,’marker’,struct(‘size’,1));
trace7= struct(‘x’, {cellstr(datestr(ForecastGDPgrowth(:,1,6),’yyyy’))},’y’,ForecastGDPgrowth(:,2,6),’name’, ‘2012 Forecast’,’type’, ‘scatter’,’marker’,struct(‘size’,1));
data = {trace1,trace2,trace3,trace4,trace5,trace6,trace7};
layout = struct(‘title’, ‘Recognition Lags: US GDP growth Forecasts in Great Recession’,’showlegend’, true,’width’, 800,…
‘xaxis’, struct(‘domain’, [0, 0.9],’title’,’Year’), …
‘yaxis’, struct(‘title’, ‘Percent’,’titlefont’, ‘anchor’, ‘free’,’side’, ‘left’,’position’,0) );
response = plotly(data, struct(‘layout’, layout, ‘filename’, ‘GreatRecession_GDPgrowthForecasts’, ‘fileopt’, ‘overwrite’));
response.data=data; response.layout=layout;
% Graph has been created let’s save a pdf copy to inside a folder called Graphs (folder must already exist or matlab will error)
saveplotlyfig(response, ‘./Graphs/GreatRecession_GDPgrowthForecasts.pdf’)

% Graph of the implicit level forecasts
trace1= struct(‘x’, {cellstr(datestr(FourthQuarterGDP(:,1),’yyyy’))},’y’,FourthQuarterGDP(:,2),’name’, ‘Actual GDP’,’type’, ‘scatter’,’marker’,struct(‘size’,1));
trace2= struct(‘x’, {cellstr(datestr(FourthQuarterGDPForecasts(:,1,1),’yyyy’))},’y’,FourthQuarterGDPForecasts(:,2,1),’name’, ‘2007 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
trace3= struct(‘x’, {cellstr(datestr(FourthQuarterGDPForecasts(:,1,2),’yyyy’))},’y’,FourthQuarterGDPForecasts(:,2,2),’name’, ‘2008 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
trace4= struct(‘x’, {cellstr(datestr(FourthQuarterGDPForecasts(:,1,3),’yyyy’))},’y’,FourthQuarterGDPForecasts(:,2,3),’name’, ‘2009 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
trace5= struct(‘x’, {cellstr(datestr(FourthQuarterGDPForecasts(:,1,4),’yyyy’))},’y’,FourthQuarterGDPForecasts(:,2,4),’name’, ‘2010 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
trace6= struct(‘x’, {cellstr(datestr(FourthQuarterGDPForecasts(:,1,5),’yyyy’))},’y’,FourthQuarterGDPForecasts(:,2,5),’name’, ‘2011 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
trace7= struct(‘x’, {cellstr(datestr(FourthQuarterGDPForecasts(:,1,6),’yyyy’))},’y’,FourthQuarterGDPForecasts(:,2,6),’name’, ‘2012 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
data = {trace1,trace2,trace3,trace4,trace5,trace6,trace7};
layout = struct(‘title’, ‘Recognition Lags: US GDP Forecasts in Great Recession’,’showlegend’, true,’width’, 800,…
‘xaxis’, struct(‘domain’, [0, 0.9],’title’,’Year’,’showgrid’,false), …
‘yaxis’, struct(‘title’, temp2.Units(:),’anchor’, ‘free’,’side’, ‘left’,’position’,0,’showgrid’,false) );
response = plotly(data, struct(‘layout’, layout, ‘filename’, ‘GreatRecession_ImplicitGDPlevelForecasts’, ‘fileopt’, ‘overwrite’));
response.data=data; response.layout=layout;
% Graph has been created let’s save a pdf copy to inside a folder called Graphs (folder must already exist or matlab will error)
saveplotlyfig(response, ‘./Graphs/GreatRecession_ImplicitGDPlevelForecasts.pdf’)

Second Example (third graph)
% This example is more complicated as it uses structures to store the data rather than matrices (useful here as the different series are different lengths)
% Real Gross Domestic Product (Billions of Chained 2009 Dollars, Quarterly, Seasonally Adjusted Annual Rate)

fred_GDP = getFredData(‘GDPC1’, ‘2005-12-31’, ‘2014-12-31’)
% Real Potential Gross Domestic Product (Billions of Chained 2009 Dollars, Quarterly, Not Seasonally Adjusted)
fred_PotentialGDP = getFredData(‘GDPPOT’, ‘2005-12-31’, ‘2014-12-31′)

for t=2007:2014
ti=t-2006;
ondate=[num2str(t),’-12-31′];
    % FOMC Summary of Economic Projections for the Growth Rate of Real Gross Domestic Product, Central Tendency, Midpoint
    % (Fourth Quarter to Fourth Quarter Percent Change, Annual, Not Seasonally Adjusted)
ForecastPotentialGDP(ti)=getFredData(‘GDPPOT’, ondate, ‘2014-12-31’, [], [],[], ondate);
[~,FindDateIndex]=min(abs(fred_PotentialGDP.Data(:,1)-datenum(ForecastPotentialGDP(ti).Data(1,1))));
ForecastPotentialGDP(ti).Data(:,2)=ForecastPotentialGDP(ti).Data(:,2)*(fred_PotentialGDP.Data(FindDateIndex,2)/ForecastPotentialGDP(ti).Data(1,2));
    % Note that just reindexing using the GDP Deflator doesn’t work. There is more to the revisions than this. (Possibly/probably due to revised versus
    % realtime GDP data; including changes in measurement of GDP, things like the recent switch to include measurement of Intangibles in GDP.)
    % The approach I use here is based on assumption that original forecast was really about how fast potential gdp would grow in the future. It will
    % be accurate in as far as this is true. If change in level would have led to change in prediction then approach I use would be biased.
end

% Now draw the graph
trace1= struct(‘x’, {cellstr(datestr(fred_GDP.Data(:,1),’yyyy-QQ’))},’y’,fred_GDP.Data(:,2),’name’, ‘Real GDP’,’type’, ‘scatter’,’marker’,struct(‘size’,1));
trace2= struct(‘x’, {cellstr(datestr(fred_PotentialGDP.Data(:,1),’yyyy-QQ’))},’y’,fred_PotentialGDP.Data(:,2),’name’, ‘Potential Real GDP’,’type’, ‘scatter’,’marker’,struct(‘size’,1));
trace3= struct(‘x’, {cellstr(datestr(ForecastPotentialGDP(1).Data(:,1),’yyyy-QQ’))},’y’,ForecastPotentialGDP(1).Data(:,2),’name’, ‘2007 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
trace4= struct(‘x’, {cellstr(datestr(ForecastPotentialGDP(2).Data(:,1),’yyyy-QQ’))},’y’,ForecastPotentialGDP(2).Data(:,2),’name’, ‘2008 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
trace5= struct(‘x’, {cellstr(datestr(ForecastPotentialGDP(3).Data(:,1),’yyyy-QQ’))},’y’,ForecastPotentialGDP(3).Data(:,2),’name’, ‘2009 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
trace6= struct(‘x’, {cellstr(datestr(ForecastPotentialGDP(4).Data(:,1),’yyyy-QQ’))},’y’,ForecastPotentialGDP(4).Data(:,2),’name’, ‘2010 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
trace7= struct(‘x’, {cellstr(datestr(ForecastPotentialGDP(5).Data(:,1),’yyyy-QQ’))},’y’,ForecastPotentialGDP(5).Data(:,2),’name’, ‘2011 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
trace8= struct(‘x’, {cellstr(datestr(ForecastPotentialGDP(6).Data(:,1),’yyyy-QQ’))},’y’,ForecastPotentialGDP(6).Data(:,2),’name’, ‘2012 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
trace9= struct(‘x’, {cellstr(datestr(ForecastPotentialGDP(7).Data(:,1),’yyyy-QQ’))},’y’,ForecastPotentialGDP(7).Data(:,2),’name’, ‘2013 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
trace10= struct(‘x’, {cellstr(datestr(ForecastPotentialGDP(8).Data(:,1),’yyyy-QQ’))},’y’,ForecastPotentialGDP(8).Data(:,2),’name’, ‘2014 Forecast’,’type’, ‘scatter’,’opacity’,0.8,’marker’,struct(‘size’,1),’line’,struct(‘dash’,’dot’));
data = {trace1,trace2,trace3,trace4,trace5,trace6,trace7,trace8,trace9,trace10};
layout = struct(‘title’, ‘US Potential GDP updates during the Great Recession’,’showlegend’, true,’width’, 800,…
‘xaxis’, struct(‘domain’, [0, 0.9],’title’,’Year’), …
‘yaxis’, struct(‘title’, fred_GDP.Units(:),’anchor’, ‘free’,’side’, ‘left’,’position’,0) );
response = plotly(data, struct(‘layout’, layout, ‘filename’, ‘GreatRecession_PotentialGDP’, ‘fileopt’, ‘overwrite’));
response.data=data; response.layout=layout;
% Graph has been created let’s save a pdf copy to inside a folder called Graphs (folder must already exist or matlab will error)
saveplotlyfig(response, ‘./Graphs/GreatRecession_PotentialGDP.pdf’)

Leave a Reply

Your email address will not be published. Required fields are marked *