function [rho,kappa]=copula_tvp(stdresid1,stdresid2)

xstd=normcdf(stdresid1,0,1);
ystd=normcdf(stdresid2,0,1);
kappa1=corr(stdresid1,stdresid2);
lower = -5*ones(3,1);  % in theory there are no constraints, but setting loose constraints sometimes helps in the numerical optimisation
upper = 5*ones(3,1);
theta0 = [log((1+kappa1)/(1-kappa1));0;0];
options = optimset('Display','off','TolCon',10^-12,'TolFun',10^-4,'TolX',10^-6);
[ kappa10 LL10] = fmincon('bivnorm_tvp1_CL',theta0,[],[],[],[],lower,upper,[],options,[xstd,ystd],kappa1);
[LL10, rho10] = bivnorm_tvp1_CL(kappa10,[xstd,ystd],kappa1);
kappa=kappa10;
rho=rho10(end);