Only interested in one parameter
Info
This question is closed. Reopen it to edit or answer.
Show older comments
SO I have the following code from a book I recently read: I am however only interested in "b" in [P,b]. So I want it to return "P" and "b" in my workspace so I can look at "b" values. How can I do that? Currently If I runt it as it is I get "ans" in my workspace, but when I klick on it its hard to distinguish whats b- values and what P-values
function [P, b]=AmericanPrice(r,delta,sigma,K,nx,nt,Xhat,That)
%Usage:P=AmericanPrice(r,delta,sigma,K,nx,nt,Xhat,That)
%P=AmericanPrice(0.08,0.12,.2,100,50,10,300,3);
dx=Xhat/nx;
dt=That/nt;
for i=1:nx-1
A(i,i:i+2)=[((r-delta)*dt*i-sigma*sigma*dt*i*i)/2
1+r*dt+sigma*sigma*dt*i*i
(-(r-delta)*dt*i-sigma*sigma*dt*i*i)/2];
end
P(:,1)=max(K-[0:dx:Xhat],0);
if(delta==0)
b(1)=K;
else
b(1)=min(K,K*r/delta);
end
for j=2:nt+1
bn=0; run=1;
while(run)
An=[A(1+bn:end,1+bn:end)];
An(end+1,end-1:end)=[-1 1];
An(end+1,1)=1;
Cn=[P(bn+2:nx,j-1)' 0 K-bn*dx]';
Pn=inv(An)*Cn;
if(Pn(2)<K-((bn+1)*dx))
bn=find(sign(diff(Pn)/dx+1)-1,1,'last')+bn;
else
b(j)=bn*dx; run=0;
end
end
P(:,j)=[K-[0:bn-1]*dx Pn'];
end
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!