Help calibrate Matrix using lsqnonlin

Hi :) I have imported actual Call Option price Data data from a spresheet into Matlab, and with the help of "lsqnonlin" I am now to calibrate the Black-Scholes model to find the volatility σ which gives the best fit to the entire set of observed prices I have imported and saved in the matrix "prices".
Specifically, I want to find the value of the volatility which minimizes the square differences between Black-Scholes prices and the corresponding observed prices.
I am fairly new to Matlab, but can anyone tell me how to do this using lsqnonlin, or at least guide me in the right direction? :)
Any help is greatly appreciated!
%specifying variables:
StrikesRelToSpot = xlsread('SPXDataExercise', 'Data', 'D9:P9')
StrikesCash = xlsread('SPXDataExercise', 'Data', 'D8:P8')
Expiry = xlsread('SPXDataExercise', 'Data', 'C10:C23')
prices=xlsread('SPXDataExercise', 'Data', 'D10:P23');%matrix of call prices
m=length(Expiry)
n=length(StrikesRelToSpot)
S0=xlsread('SPXDataExercise', 'Data', 'B3');%Spot
r=xlsread('SPXDataExercise', 'Data', 'B4');%Interest rate
d=xlsread('SPXDataExercise', 'Data', 'B5');%Dividend yield
impliedvols = zeros(m,n);
for i = 1:m
for j = 1:n
impliedvols(i,j) = blsimpv(S0,StrikesCash(j),r,Expiry(i),prices(i,j),[],d);
end
end
InitialSigma = zeros(m,n);
for i = 1:m
for j = 1:n
InitialSigma(i,j) = 0.3;
end
end

Answers (0)

Tags

Asked:

on 19 Nov 2014

Edited:

on 19 Nov 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!