IBTvolaplot (MatLab R2007b)

shows the implied local volatility surface sigma(S,tau) in the implied tree at different time and stock price levels. Required by XFGIBT02.m.

Download File

Click the button to demonstrate a graph view. 
Notice: This content requires Java Runtime Environment.
Java Applet and JavaScript should be allowed on your browser.

Fri, July 27 2012 by Dedy Dwi Prastyo

IBTvolaplot(loc, step, startpoint, endpoint, m)

- a surface plot to show the implied local volatility


 function[XI,YI,f] = IBT2volaplot(loc, step, startpoint, endpoint, l)
 [v,w] = size(loc);
 if w~= 3
     error('IBT2volaplot: data matrix must contain 3 columns');
 end
 if (step<=0)
     error('IBT2volaplot: the time bandwidth needs to be larger than 0');
 end
 if ((l<0) || (floor(l)~=l))
     error('IBT2volaplot: the number of the steps should be a natural number');
 end
  leng=(endpoint-startpoint)/l;
  while (startpoint<min(loc(:,1))-leng)
  %    disp('IBT2volaplot: startpoint is too small');
  %    disp('Input a new startpoint:');
  %    startpoint = input('startpoint=');
  end
  while (endpoint> max(loc(:,1))+leng)
      disp('IBT2volaplot: endpoint is too large');
      disp('Input a new endpoint:');
      endpoint = input('endpoint=');
  end
  ti = 1:1:l+1;
  [XI,YI] = meshgrid(ti,ti);
  XI = (startpoint-leng)+leng.*XI;
  YI = step.*YI;
  X = reshape(XI,(l+1)^2,1);
  Y = reshape(YI,(l+1)^2,1);
  n=length(X);
  f=zeros(n,1);
  j=1;
  while(j<n+1)
    s=0;
    m1=X(j);
    m2=Y(j);
    k=1;
    while(k< length(loc)+1)
      if(abs(loc(k,1)-X(j)-leng/2)<leng/2 && loc(k,2)==Y(j))
        f(j)=f(j)+loc(k,3);
        f(j);
        s=s+1;
      end
      k=k+1;
    end
    if(s>0) 
      f(j)=f(j)/s;
    end
	j=j+1;
  end
  d = [X Y f];
  XI = XI(1,:)';
  YI = YI(:,1);
  f = reshape(f,l+1,l+1);
  surf(XI,YI,f);
  title('Implied Local Volatility Surface');
  xlabel('Strike Price');
  ylabel('Maturity');