% Compare our real interest rate trend to other rstars

clear all
close all
clc

% 197111 - 202204 or 1971Q4 - 2022Q1
xdate = datetime(1971,11,1) + calmonths(0:605);
xdateQ = datetime(1971,12,1) + calquarters(0:201);
load("USrstar.mat")
rstar = mean(USrstar(1:end,:),1)';
rstarQ = nan(size(rstar,1),1);
for i = 2:3:(size(rstar)-1)
    rstarQ(i) = rstar(i);
end
rstarQ(any(isnan(rstarQ),2),:) = []; 

% read documented LW, HLW, DGGT, JM rstar
DR = readtable("documented rstar.csv");
DR = DR(DR.Date>datetime(1971,9,1) & DR.Date<datetime(2022,4,1),:);
% lw = DR.LW;
% hlw = DR.HLW;
dggt = DR.DGGT;
jm = DR.JM;
lm = DR.LM;
% rstar from MDW
load("MDWrstar.mat")


plot(xdateQ,dggt,"LineWidth",1,"LineStyle","-.")
hold on
plot(xdateQ,jm,"LineWidth",1, 'LineStyle','--')
hold on
plot(xdateQ,lm,"LineWidth",1, "LineStyle",":")
hold on
plot(MDW.dates,MDW.rstar,"-*","LineWidth",1)
hold on
plot(xdateQ,rstarQ,'k',"LineWidth",1,"LineStyle","-")
legend('DGGT Estimate','JM Estimate','LM Estimate','MTW Estimate',"Our Real Interest Rate Trend")
set(gca, 'FontSize',20, 'XTick',datetime([1975 1980 1985 1990 1995 2000 2005 2010 2015 2020],03,01),...
    'XTickLabel', {'1975', '1980', '1985', '1990', '1995', '2000', '2005', '2010', '2015', '2020'});

corr(rstarQ,hlw)

%% compose rstar using WX shadow rate trend and inflation trend
% run under WX shadow rate


% Labauch-William r*
lw = DR.LW;

load("USrstar.mat")
rstar = mean(USrstar(1:end,:),1)';

WXdata = readtable("./WX shadow rate/WX_trend.csv");
inflation_trend = readtable("./WX shadow rate/pit.csv");
rstar2 = WXdata.V2 - inflation_trend.Var1;
% 197111 - 202204
xdate = datetime(1971,11,1) + calmonths(0:605);


plot(xdate, rstar,"LineWidth",1)
hold on
plot(xdate,rstar2,"LineWidth",1, "LineStyle","--")
hold on
plot(xdateQ,lw,"LineWidth",1, "LineStyle",":");
legend("Our Real Interest Rate Trend",'Real Interest Rate Trend from Shadow Rate'," Laubach-William r*")
set(gca, 'FontSize',20, 'XTick',datetime([1975 1980 1985 1990 1995 2000 2005 2010 2015 2020],03,01),...
    'XTickLabel', {'1975', '1980', '1985', '1990', '1995', '2000', '2005', '2010', '2015', '2020'});








