function [lambda0, lambdaf, beta, Vf, Omega, e]=calibration(R, F) 

% This function returns parameters for d.g.p., using (R, F)
% R: T by N; F: T by K
    K=size(F,2);
    N=size(R,2);
    V=cov([F R]);                     
    Vf=V(1:K,1:K);
    Vfr=V(1:K,(K+1):end);
    Vr=V((K+1):end,(K+1):end);
    beta=Vfr'*inv(Vf);
    Omega=Vr-Vfr'*inv(Vf)*Vfr;
    X=[ones(N,1) beta];
    lambda=inv(X'*X)*X'*mean(R,1)';
    lambda0=lambda(1,1);
    lambdaf=lambda(2:end,1);
    e=mean(R,1)'-X*lambda;
end

