function val = forecast_rw(yields, h)
% Forecast ten-year foreward rate using random walk

% INPUT:
%       yields:         ten-year forward rate  Tx1
%       h:              scalar predicting horizons
% OUTPUT:
%       RMSE
%       resid:  (T-h)x1  residuals from forecast
%       yhat:   (T-h)x1  fitted y


T = size(yields,1);
% n = T - h;        % total number of forecasts
n = T - 40;         % total number of forecasts
yhat = zeros(n,1);
resid = zeros(n,1);

for ii = 20:n
    yhat(ii) = yields(ii);
    resid(ii) = yields(ii+h) - yhat(ii);
end

rmsfe = sqrt(sum(resid(20:end).^2)/(n-19));

val.rmsfe = rmsfe ;
val.resid = resid(20:end);
val.yhat = yhat;


end



