SERVING THE QUANTITATIVE FINANCE COMMUNITY

Bentam64
Topic Author
Posts: 6
Joined: November 23rd, 2013, 8:54 am

### Matlab Option Greek Functions

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))----------------------------------------------------------------------------------------
Last edited by Bentam64 on February 3rd, 2014, 11:00 pm, edited 1 time in total.

eh
Posts: 494
Joined: March 2nd, 2010, 9:26 am

### Matlab Option Greek Functions

Excuse me for being pedantic, but these functions are not vectorised.

Maosika
Posts: 19
Joined: May 5th, 2014, 7:06 pm

### Matlab Option Greek Functions

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.

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...

 JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...

GZIP: On