%HGAINSQ   plot quarterly holding gains from the US Flow of Funds.

%          Ellen McGrattan, 2-4-2012

%
% NIPA Table 1.1.5 nominal GDP and Table 1.1.9 deflator 
%
load ../BEA/NIPA/dgdp4711.dat
i            = find(dgdp4711(1,:)>1951);
y            = dgdp4711(1,i)';
q            = dgdp4711(2,i)';
gdp          = dgdp4711(3,i)';
def          = dgdp4711(4,i)'/100;
rgdp         = gdp./def;
T            = length(gdp);

%
% FOF Table R100 Change in household net worth (Quarterly, Bil$)
% (Guess of 4th quarter reversal from 3rd quarter in 2011:4)
%

load ../FOF/btabs/btab100d.dat
load ../FOF/btabs/rtab100d.dat
nholdgain    = (rtab100d(:,10)-rtab100d(:,11))/1000 *4;
nholdgain    = [nholdgain;-nholdgain(length(nholdgain))];
Vnholdgain   = cumsum(nholdgain);
T            = length(Vnholdgain);

ngain        = [Vnholdgain(2:T)-Vnholdgain(1:T-1)]./gdp(1:T-1);
rgain        = [Vnholdgain(2:T)./def(2:T)-Vnholdgain(1:T-1)./ ...
                def(1:T-1)]./rgdp(1:T-1);
t            = ptime(1952.2,T-1,4);

plot(t,rgain)
title(['Real Holding Gains Relative to GDP (Quarterly, ', ...
       'Excluding Real Estate)'],'Fontsize',14)
