Code covered by the BSD License  

Highlights from
Desenvolvimento de Aplicacoes com MATLAB

image thumbnail

Desenvolvimento de Aplicacoes com MATLAB

by

 

Slides and demo files from the webinar "Desenvolvimento de Aplicacoes com MATLAB"

Butterflysurf(OptionProps)
function Butterflysurf(OptionProps)
% Surf Plot the Option Price vs. Spot Price vs. Time to Maturity 

% Make sure input is column vector
OptionProps = OptionProps(:);

% Make sure input is column vector
OptionProps = OptionProps(:);

% Check for correct input properties
[m,n] = size(OptionProps);

% Vector Check
if n > 1
   errordlg('Function Requires a Vector Input','Input Dimension Error','on')
end

% Check for right length of input
if m < 7
    errordlg('Function Requires 7 inputs','Input Length Error','on')
end


SpotPrice = OptionProps(1);
StrikePrice = OptionProps(2);
RiskFreeRate = OptionProps(3);
TimeExpiry = OptionProps(4);
Volatility = OptionProps(5);
VizRange = OptionProps(6);
ButterflyRange = OptionProps(7);

     %Compute ranges for the spot price and time to expiry based on the
     %specified visualization range
   [SpotMat, TimeMat] = calcrange(SpotPrice, TimeExpiry, VizRange);
     
         
     %Price the option over the ranges
     ButterflyValue = blsbtyval(SpotMat, StrikePrice, RiskFreeRate, ...
          TimeMat, Volatility, ButterflyRange);
     
     %Plot the resulting value surface
     surf(SpotMat, TimeMat, ButterflyValue);
     xlabel('Spot Price');
     ylabel('Time to Expiry');
     zlabel('Option Value');
     title('Butterfly Option');
     
     

Contact us