function [f,g] = carloss(param,y,capt)

    mu = param(1);
    rho = param(2);
    ly = lx(y);
    etahat = y-mu-rho.*ly;
    etahat = etahat(2:capt,:);
    sig = cov(etahat);


    f = -.5*log(2*pi)-.5*log(sig/(1-rho^2)) -(y(1)-(mu/(1-rho))^2)/(2*sig/(1-rho^2)) ...
        -(capt-1)/2*log(2*pi) -(capt-1)/2*log(sig)-sum((etahat.^2)./(2*sig));

    f=-f;
end