Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Trying to Produce 3D graph
Date: Fri, 21 Nov 2008 05:47:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 113
Message-ID: <gg5i0m$s6f$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1227246422 28879 172.30.248.35 (21 Nov 2008 05:47:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 21 Nov 2008 05:47:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1608486
Xref: news.mathworks.com comp.soft-sys.matlab:502251


Hi I have the follwin code:

function y = ImpVol(C,S,K,r,T,m,l,u,prec)

f =@(x) BS_European_Call(S,K,x,r,T)-C;

    switch m
        case 'bisection'
         y=bisection(f,l,u,prec,S,K,r,T,C);
        case 'newton'
         y=newton(f,u,prec,S,K,r,T);
        case 'secant'
         y=secant(f,u,prec);
        case 'RFalsi'
         y=RFalsi(f,l,u,prec,S,K,r,T,C);
        otherwise         
         y =MRFalsi(f,l,u,prec,S,K,r,T,C);
    end
end







function val = bisection(f,a,b,tol,S,K,r,T,a_th)

sigma_0=a;
a_call0 = BS_European_Call(S,K,sigma_0,r,T)

sigma_1=b;
a_call1 = BS_European_Call(S,K,sigma_1,r,T)


if (a_call0-a_th)*(a_call1-a_th) <= tol & (a_call0-a_th)*(a_call1-a_th) >= -tol
    disp('a_call is one  of the initial guesses')
    return
end
%------------------------------------------------------------------------
%
k=1;t=[];g=[];

tic;

while (a_call0-a_th)*(a_call1-a_th) < tol 

% in case sigma_0+sigma_1 = 0  
sigma_aux = (sigma_0+sigma_1);
if sigma_aux <= tol & sigma_aux >= -tol 
    sigma_aux = sigma_aux + tol;
end
sigma_m = sigma_aux/2
t(k)=sigma_m;
a_callm = BS_European_Call(S,K,sigma_m,r,T);
g(k)=a_callm;
k=k+1;

if (a_call0-a_th)*(a_callm-a_th) < 0
    if a_callm >= a_th-tol & a_callm <= a_th+tol
        disp('a_{callm} is a_th')
        t(k)=sigma_m;g(k)=a_callm;
    break;
    end
    sigma_1 =sigma_m;
    a_call1=a_callm;
   
elseif (a_callm-a_th)*(a_call1-a_th) < 0 
    if a_callm >= a_th-tol & a_callm<= a_th+tol
    disp('a_{callm} is a_th')
    t(k)=sigma_m;g(k)=a_callm;
    break;
    end
    sigma_0 =sigma_m;   
    a_call0=a_callm;
end                   % close "if"
end                   % close "while"
val= sigma_m;
toc;

disp(k);

figure(1),subplot(2,1,2);plot([1:k],g,'*',[0:k],4.7594*ones(k+1),'r');
xlabel('Number of iterations');
ylabel('European Call');legend('Call values','At \sigma=0.2 Call = 4.7594')
grid on
subplot(2,1,1);plot([1:k],t);
xlabel('Number of iterations');
ylabel('\sigma');
title('Implied volatility using Bisection method');
grid on



figure(2)
plot([1:k],g,'*')
grid on

figure(3)
plot([1:k],t)
grid on
end

I want to prduce a 3D map of the values from this function by moving the 2nd last and last paramters over 10 values each ImpVol(4.7594,42,40,0.1,0.5,'newton',0.1,1,0.0001)

i.e. vector upper(1:10);
vector accuracy(0.1:0.000000001);


can someone please explain in detaili how to do this, I've been trying for ages but have only founf a hundred ways to faill!!