
tol = 0.0005;

S = 200;
K = 300;
r = 0.05;
T = 1;
cMarket = 2;


vol = 0.2;

n = 0;
while (abs(callBS(S,K,T,vol, r) - cMarket) > tol)
    n = n+1;
    d_minus = ((r - 1/2 * vol^2) * T - log(K/S))/ (vol * sqrt(T) );
    vega = K*exp(-r*T)*normpdf(d_minus)*sqrt(T);
    vol = vol - (callBS(S,K,T,vol, r) - cMarket)/vega; %Newton step
end
vol
n

