function [LLF,llk,sigma_e,K0Q_cP, K1Q_cP,K0P_cP, K1P_cP] = ...
    jsz_like_L_macroRR_L(parameters,yields, W, mats, ...
    dt,NFACT,L,varargin)
% if max(parameters(1:3))>1
if isempty(varargin)
    rnk=1;
else
    rnk=varargin{1};
end
    npar=length(parameters(NFACT+2:end));
    %parameter restrictions
    lb=[-0.6*ones(NFACT,1)+1;0;-inf*ones(npar,1)];
ub=[-.0001*ones(NFACT,1)+1;0.4;inf*ones(npar,1)];
% A = [[1 -1 0; 0 1 -1] zeros(2,npar+1)];
% b = [0;0];
tmp=zeros(NFACT-1,NFACT);
jj=1;
for j=1:NFACT-1
    tmp(j,jj:jj+1)=[1 -1];
    jj=jj+1;
end
A=[tmp zeros(NFACT-1,npar+1)];
b=zeros(NFACT-1,1);%ones(NFACT-1,1).*0.01;%zeros(NFACT-1,1);
if any(parameters>ub)||any(parameters<lb)||any(A*parameters<b)
    LLF=inf;
 
else
    K1Q_X = diag(parameters(1:NFACT)-1);
    rinfQ = parameters(NFACT+1);
    sig_p = veclt(parameters(NFACT+2:end));
    Sigma_cP = sig_p*sig_p';
  
    [llk, penalty,AcP, BcP, AX, BX, K0P_cP, K1P_cP, sigma_e, K0Q_cP, K1Q_cP, rho0_cP, rho1_cP, cP, llkP, llkQ] = ...
        jszLLK_LL(yields, W, K1Q_X, rinfQ, Sigma_cP, mats, dt,[],[],[],rnk,L);
    varcoef=K1P_cP+eye(NFACT,NFACT*L);
    FF=comp1(vec(varcoef'),NFACT,L,0); 
    if max(abs(eig(FF)))>1
        LLF=inf;
    else
    LLF = sum(llk);
    end
end