From: Liva Micule on
Hi!
I have a problem with estimating parametres b and r. I have integral approximation with Gauss-Hermite quadrature using abscissas (in code xx) and weights (ww). And now I must optimize the log-likelihood function using quasi-Newton method. Here, I wrote what my function (lt) looks like.

dt=load('dt.txt'); % Number of defaults
nt=load('nt.txt'); % Borrowers
sum=0;
lt=0;
syms b r real
n=20;
t=47;
F=sym(zeros(n,1));
sum1=sym(zeros(n,1));
ln=sym(zeros(t,1));
for t=1:t,
for k=1:n,
e=exp((b-sqrt(2*r)*xx(k))/sqrt(1-r));
F(k)=e/(1+e);
sum1(k)=ww(k,1)*F(k)^dt(t)*(1-F(k))^(nt(k)-dt(k))*(exp(-xx(k)^2)/sqrt(pi));
sum=sum1(k)+sum;
end;
ln(t)=log(sum);
lt=lt+ln(t);
end;

There is NEWTON METHOD, but it doesn't work. I'm beginner in Matlab, I really need your help.
n=30;
clf;
syms b r real
dif1_b=diff(lt,'b');
dif1_r=diff(lt,'r');
H=jacobian(jacobian(lt));
nn = n; if n <= 0, nn = 100; end
v = [-3;0];
fprintf('\n n point\n\n')
for i=0:nn
fprintf(1,'%3d ',i)
fprintf(1,'%5.4f ',v')
fprintf(1,'\n')
if n <= 0, disp('Press any key to continue. . .'), pause;end
db=subs(dif1_b,{b,r},{v(1),v(2)});
dr=subs(dif1_r,{b,r},{v(1),v(2)});
H=subs(H,{b,r},{v(1),v(2)});
w = [db;dr];
A = [H];
v = v - A\w;
end;

Best,
Liva