  %compute factor loadings
  H(:,i) = ns_basis(ttm,i,1/2.5)';
end
H=[H zeros(length(H),K-get(ns,'dim'))];  

N=get(ns,'simT')*get(ns,'simN');  %number of quarters simulated
M=get(ns,'numSims');    %number of simulations

% Initialize matrices 
F=zeros(N,size(ttm,2),M);
Zb=zeros(N,size(ttm,2),M);
Zhat=zeros(N,size(ttm,2),M);
T=zeros(N,size(ttm,2),M);
T1=zeros(N,size(ttm,2),M);


%% 2. Compute term premia for VAR(1) model
if get(ns,'lags')==1;

  for p=1:M
    for i=1:N
      Zb(i,:,p)=interp1(simTenor,data.Z