function y = genFR3(fname,maturities)
% Construct monthly forward rates using data from Liu and Wu.
% smooth data by taking 12-month average
% Input: 
%        file name;
%        maturities in months;
% Ouput:
%        time: date in yyyymm from Jan 197110
%        forwardrate: forward rates; differerent columns are forward rates of different maturities

datacell = readtable(fname) ;
yyyymm = datacell{:,1};
id_start = find(yyyymm == 197110,1,'last');
id_end = find(yyyymm == 202204,1,'last');
datacell = datacell(id_start:id_end,:);
mydata = datacell(:,2:end);
T = size(datacell,1);

% m*y_(t,m)
m1 = maturities/12;
n1 = repmat(m1,1,T);
yield1 = n1.*mydata{:,maturities}';

% (m+1)*y_{t,m+1}
m2 = (maturities+12)/12;
n2 = repmat(m2,1,T);
yield2 = n2.*mydata{:,maturities+1}';

forwardrates = yield2 - yield1; 
y = forwardrates';

end