Thread Subject: Trying to Produce 3D graph

Subject: Trying to Produce 3D graph

From: Hugh

Date: 21 Nov, 2008 05:47:02

Message: 1 of 1

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!!


Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com