Page 1 of 1

Matlab Option Greek Functions

Posted: February 4th, 2014, 2:59 am
by Bentam64
Basic Black and Scholes model with non-dividend paying stock and constant volatility. Where %S = Current Spot Price %X = Strike%r = Risk Free Rate (Per Annual)%T = Time (Per Annual)%v = Volatility (Per Annual)Vega ----------------------------------------------------------------------------------------function vega= bsvega( S, X, r, T, v) d1=(log(S/X)+(r+v^2/2)*T)/(v*sqrt(T)); d2=(log(S/X)+(r-v^2/2)*T)/(v*sqrt(T)); nPrimeD1 = (1/sqrt(pi))*exp(-(d1^2)/2) nPrimeD2 = (1/sqrt(pi))*exp(-(d2^2)/2) vega = S*sqrt(T)*nPrimeD1----------------------------------------------------------------------------------------Gamma----------------------------------------------------------------------------------------function Gamma = bsgamma( S, X, r, T, v, Symb, Texp, DataDate, Lifespan) d1=(log(S/X)+(r+v^2/2)*T)/(v*sqrt(T)); d2=(log(S/X)+(r-v^2/2)*T)/(v*sqrt(T)); nPrimeD1 = (1/sqrt(pi))*exp(-(d1^2)/2) nPrimeD2 = (1/sqrt(pi))*exp(-(d2^2)/2) Gamma = nPrimeD1/(S*v*sqrt(T))----------------------------------------------------------------------------------------Delta----------------------------------------------------------------------------------------function [cd,pd] = bsdelta( S, X, r, T, v, Symb, Texp, DataDate, Lifespan) d1=(log(S/X)+(r+v^2/2)*T)/(v*sqrt(T)); d2=(log(S/X)+(r-v^2/2)*T)/(v*sqrt(T)); cd = normcdf(d1) pd = normcdf(d1)-1----------------------------------------------------------------------------------------Theta----------------------------------------------------------------------------------------function [CallTheta,PutTheta] = bstheta( S, X, r, T, v, Symb, Texp, DataDate, Lifespan) d1=(log(S/X)+(r+v^2/2)*T)/(v*sqrt(T)); d2=(log(S/X)+(r-v^2/2)*T)/(v*sqrt(T)); nPrimeD1 = (1/sqrt(pi))*exp(-(d1^2)/2) nPrimeD2 = (1/sqrt(pi))*exp(-(d2^2)/2) CallTheta = -r*X*exp(-r*T)*normcdf(d2)-S*nPrimeD1*v/(2*sqrt(T)) PutTheta = r*X*exp(-r*T)*normcdf(-d2)-S*nPrimeD1*v/(2*sqrt(T))----------------------------------------------------------------------------------------

Matlab Option Greek Functions

Posted: February 4th, 2014, 1:36 pm
by eh
Excuse me for being pedantic, but these functions are not vectorised.

Matlab Option Greek Functions

Posted: May 21st, 2014, 7:01 pm
by Maosika
QuoteOriginally posted by: ehExcuse me for being pedantic, but these functions are not vectorised.I try it on Matlab and it's give me error because these functions aren't vectorised. This code doesn't work.