File Exchange

image thumbnail

calcGreeks: Calculate option Greeks (European Black/Scholes)

version 1.1.2 (30.5 KB) by Yair Altman
calcGreeks computes fair price and Greek values for vanilla European options using the Black-Scholes-Merton model, optimized for performance

2 Downloads

Updated 28 Dec 2018

View License

calcGreeks computes and reports the fair price value and numerous Greek values for vanilla European options, using the Black-Scholes-Merton model, optimized for performance.

No toolbox is required - only basic Matlab.

Any input parameter can be vectorized (examples below). Note that only one parameter can be vectorized (any parameter that you choose).

calcGreeks is used by the IQFeed-Matlab connector (IQML) - https://undocumentedmatlab.com/IQML

Syntax:
[fairValue, greeks] = calcGreeks(spot, strike, rate, yield, volatility, maturity, putCallInd, annualFactor)

Inputs:
- spot - (mandatory) Underlying asset's spot price
- strike - (mandatory) Derivative contract's strike price
- rate - (default: 0) Domestic risk-free interest rate (%)
- yield - (default: 0) Foreign interest rate (Forex) or dividend yield (stock)
- volatility - (default: 0.3) Historic volatility of the underlying asset's price
- maturity - (default: 1.0) Number of years until the option contract expires
- putCallInd - (default: 'Call') Either 1 (Call), -1 (Put), or [1,-1] (both), or as strings. For example: "Call", 'put', 'cp', {'Call',"put"} etc.
- annualFactor - (default: 1) Used to de-annualize Theta, Charm, Veta, Color. Typical values: 1 (report annualized values), 365 (report 1-calendar-day estimates), or 252 (report 1-trading-day estimates)

Usage examples:

% Example 1: vectorized call/put
>> [fairValue, greeks] = calcGreeks(56.8, 60, 5, 2.5, 35, 15/365, {'call',"put"}, 365)
fairValue =
0.5348 3.6700
greeks =
struct with fields:
delta: [0.2347 -0.7642]
vega: 3.5347
theta: [-0.0421 -0.0378]
rho: [0.5260 -1.9347]
crho: [0.5480 -1.7839]
omega: [24.9311 -11.8278]
lambda: [24.9311 -11.8278]
gamma: 0.0762
vanna: 0.6959
charm: [-0.0025 -0.0275]
vomma: 5.7897
volga: 5.7897
veta: 0.1876
speed: 0.0123
zomma: -0.0929
color: -0.0010
ultima: -40.2881

% Example 2: vectorized strike prices
>> [fairValue, greeks] = calcGreeks(56.8, 45:5:65, 5, 2.5, 35, 15/365, 'c', 365)
fairValue =
11.8345 6.8966 2.6769 0.5348 0.0493
greeks =
struct with fields:
delta: [0.9985 0.9666 0.6921 0.2347 0.0321]
vega: [0.0178 0.8334 4.0419 3.5347 0.8280]
theta: [-0.0025 -0.0125 -0.0495 -0.0421 -0.0098]
rho: [1.8445 1.9730 1.5055 0.5260 0.0729]
crho: [2.3308 2.2564 1.6155 0.5480 0.0749]
omega: [4.7925 7.9612 14.6854 24.9311 36.9547]
lambda: [4.7925 7.9612 14.6854 24.9311 36.9547]
gamma: [3.8391e-04 0.0180 0.0871 0.0762 0.0178]
vanna: [-0.0144 -0.3673 -0.4341 0.6959 0.3948]
charm: [0.0251 0.0284 0.0220 -0.0025 -0.0039]
vomma: [0.5531 7.8117 2.5186 5.7897 8.4126]
volga: [0.5531 7.8117 2.5186 5.7897 8.4126]
veta: [0.0070 0.1174 0.1619 0.1876 0.1272]
speed: [-3.2418e-04 -0.0085 -0.0124 0.0123 0.0079]
zomma: [0.0108 0.1170 -0.1946 -0.0929 0.1303]
color: [1.2500e-04 0.0013 -0.0023 -0.0010 0.0016]
ultima: [12.4303 6.2331 -20.1849 -40.2881 13.3330]

Bugs and suggestions:
Please send to Yair Altman (altmany at gmail dot com)

Technical description:
https://en.wikipedia.org/wiki/Greeks_(finance)#Delta

Cite As

Yair Altman (2019). calcGreeks: Calculate option Greeks (European Black/Scholes) (https://www.mathworks.com/matlabcentral/fileexchange/69544-calcgreeks-calculate-option-greeks-european-black-scholes), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (0)

Updates

1.1.2

Updated description; added IQML File-Exchange reference

1.1.1

another attempt to publish as a toolbox...

1.1.0

retrying to upload as a toolbox...

MATLAB Release Compatibility
Created with R2018a
Compatible with any release
Platform Compatibility
Windows macOS Linux