SERVING THE QUANTITATIVE FINANCE COMMUNITY

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

Matlab Option Greek Functions

February 4th, 2014, 2:59 am

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.
 
User avatar
eh
Posts: 494
Joined: March 2nd, 2010, 9:26 am

Matlab Option Greek Functions

February 4th, 2014, 1:36 pm

Excuse me for being pedantic, but these functions are not vectorised.
 
User avatar
Maosika
Posts: 19
Joined: May 5th, 2014, 7:06 pm

Matlab Option Greek Functions

May 21st, 2014, 7:01 pm

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.
ABOUT WILMOTT

PW by JB

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


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

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


GZIP: On