Prev: how to edit xml file
Next: Shift matrix in y direction
From: Philip M on 20 Jul 2010 17:55 Hey guys, I want to minimize the following function. I'm running a monte carlo simulation to calculate spreads of Collateralized Debt Obligations (CDOs). I want to minimize the difference of my model spread and the market spread by varying my model parameters "mu","a" and "b". To keep this model valid, a constraint has to be fulfilled for every point of valuating (r=1,...,20). I want to vary "mu" to keep the constraint fulfilled. In the end I would like to have a single parameter "a" and a single parameter "b" but a parameter vector "mu". I don't know how to set this up, which formula to use for multivariate minimization with constraints and how to tell matlab that it should vary only "mu" to match the constraints. Thanks alot, Philip! ----------------------------------------------------------------------------------------------- Constraint: expectedvalue=@(x) normcdf((mu+rho*sigma*x)/sqrt(1+sigma^2*(1-rho^2)))*normpdf(x); (0.4)/p(r)=quad(expectedvalue,-999999,c(r)); ------------------------------------------------------------------------------------------------ Function: function f = funrr(mu,a,b) q=100; % Number of runs varomikron=0.04; randZ=randn(q,12500); randEps=randn(q,12500); randOmik=normrnd(0,sqrt(varomikron),q,12500); sigma=sqrt(b^2+varomikron); rho=((a*b)/sigma); l=zeros([20 125]); Portfolioverlust=zeros(20,q); Epsilon=zeros(20,1); Omikron=zeros(20,1); X=zeros(20,1); Z=zeros(20,1); v=zeros(q,1); s=zeros(q,1); pvprot=zeros(21,q); pvdef=zeros(21,q); LA=zeros(20,q); LB=zeros(20,q); LTranche=zeros(21,q); spread=zeros(5,1); spreadmodel=[0.0723309797736948 0.00474353239675 0.00125486203410625 0.0005703876529 0.00022735709814375]; r2007=xlsread('C:\Universitaet\Diplomarbeit\Daten\Spotrates','Tabelle1','A2:A21'); stetverzinsung=zeros(20,1); for i = 1:20 stetverzinsung(i)=exp(-r2007(i)*(i/4)); end k=1:20; p=1-exp((-0.003514966*k)/4); c = norminv(p); Attachment=[0.00001 0.03 0.06 0.09 0.12]; Detachment=[0.03000 0.06 0.09 0.12 0.22]; for d=1:5 A=Attachment(d); %Attachment Punkt B=Detachment(d); %Detachment Punkt for i=1:q Z(1)=randZ(i,(d-1)*20+1); for j=1:125 Epsilon(j)=randEps(i,(d-1)*2500+j); Omikron(j)=randOmik(i,(d-1)*2500+j); X(j)=a*Z(1)+sqrt(1-a^2)*Epsilon(j); if (X(j)<=c(1)) l(1,j)=1-normcdf(mu-b*Z(1)+Omikron(j)); else l(1,j)=0; end end Portfolioverlust(1,i)=sum(l(1,:))/125; for r=2:20 Z(r)=randZ(i,(d-1)*20+r); for j=1:125 if (l(r-1,j)>0) l(r,j)=l(r-1,j); else Epsilon(j)=randEps(i,(r-1)*125+(d-1)*2500+j); Omikron(j)=randOmik(i,(r-1)*125+(d-1)*2500+j); X(j)=a*Z(r)+sqrt(1-a^2)*Epsilon(j); if (X(j)<=c(r)) l(r,j)=1-normcdf(mu-b*Z(r)+Omikron(j)); else l(r,j)=0; end end end Portfolioverlust(r,i)=sum(l(r,:))/125; LA(r,i)=max(Portfolioverlust(r,i)-A,0); LB(r,i)=max(Portfolioverlust(r,i)-B,0); LTranche(r+1,i)=(1/(B-A))*(LA(r,i)-LB(r,i)); end for h=2:21 pvprot(h-1,i)=stetverzinsung(h-1)*(LTranche(h,i)-LTranche(h-1,i)); pvdef(h-1,i)=0.25*stetverzinsung(h-1)*(1-LTranche(h,i)); end if (d==1) v(i)= -sum(pvdef(:,i))*0.05+sum(pvprot(:,i)); else s(i)=sum(pvprot(:,i))/sum(pvdef(:,i)); end if (d==1) spread(1)=sum(v)/q; else spread(d)=sum(s)/q; end end end f = spread(1)-spreadmodel(1)+spread(2)-spreadmodel(2)+spread(3)-spreadmodel(3)+spread(4)-spreadmodel(4)+spread(5)-spreadmodel(5);
From: Alan Weiss on 21 Jul 2010 08:34 On 7/20/2010 5:55 PM, Philip M wrote: > Hey guys, > > I want to minimize the following function. I'm running a monte carlo > simulation to calculate spreads of Collateralized Debt Obligations > (CDOs). I want to minimize the difference of my model spread and the > market spread by varying my model parameters "mu","a" and "b". To keep > this model valid, a constraint has to be fulfilled for every point of > valuating (r=1,...,20). I want to vary "mu" to keep the constraint > fulfilled. In the end I would like to have a single parameter "a" and a > single parameter "b" but a parameter vector "mu". I don't know how to > set this up, which formula to use for multivariate minimization with > constraints and how to tell matlab that it should vary only "mu" to > match the constraints. > > Thanks alot, > > Philip! > ----------------------------------------------------------------------------------------------- > > Constraint: > > expectedvalue=@(x) > normcdf((mu+rho*sigma*x)/sqrt(1+sigma^2*(1-rho^2)))*normpdf(x); > (0.4)/p(r)=quad(expectedvalue,-999999,c(r)); > ------------------------------------------------------------------------------------------------ Take a look at http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brhkghv-7.html to see how to pass extra parameters. In your case, if I understand, you want a and b to be fixed, and you want mu to vary. So you would write your objective as function f = myobjective(a,b,mu) .... and then call myobjective with the syntax @(mu)myobjective(a,b,mu) I recommend using the patternsearch solver for your problem, assuming you have a Global Optimization Toolbox license (or Genetic Algorithm and Direct Search Toolbox). If you have just Optimization Toolbox, I suggest setting large values for the DiffMinChange and DiffMaxChange options, since your objective function is going to be noisy. How large? It depends on your problem, but large enough that your finite difference estimates of gradients will be somewhat accurate. If mu is one-dimensional, use the fminbnd solver, after you figure out the bounds by experimentation. Alan Weiss MATLAB mathematical toolbox documentation
|
Pages: 1 Prev: how to edit xml file Next: Shift matrix in y direction |