Table of Contents
The inspiration for this App Scripts was my curiosity in simulating how changes in Greeks influence option pricing. While calculating BSM is fairly straight forward, I wanted to use custom functions for simplicity and to prevent convoluted formulas. BSM sheets creates Google Sheets functions to retrieve all standard option greeks and contract pricing.
Some interesting things you can do:
- Create a "profitability" matrix to see how the price of the underlying impacts the option price, through time.
- How does increase in volatility, with no change in underlying price, impacts the option price, through time.
- Generating matrices for different strikes to text theta/vega impact, from above.
Some things you cannot do:
- Generate alpha
This is 100% an educational resource and you should not expect a way to generate any alpha. The calculations are "close enough" for general learning but are absolutely not sufficient to price risk in the market.
All functions were written within Google App Scripts and have to be added manually to the desired sheet.
The following papers were used to create the functions:
The following link helped in the original creation of the script:
If you need a general overview of option greeks:
This is a TL;DR version of the greeks. For a full description, please read the CBOE paper, above.
Delta represents the relative increase in the price of an option, given an increase in the price of the underlying.
Gamma represents the change in Delta, given a change in the underlying price.
Theta is the change in option price, given a 1 day change in time.
Vega is the change in price of an option for a 1pt increase in the implied volatility of the underlying.
If you have never worked with Google App Scripts, don't worry, its straight forward and there a lot of documentation on the internet. So much so, that instead of giving step-by-step instructions, I'm going to link to some of the best guides I have found.
Instead of creating a tutorial, here are some I've found useful to install App Scripts into your sheet. The first article is really in-depth and comprehensive.
Currently,
index.gs
is the stable release. All classes have been moved to./classes
folder for future development and implementation of a build system. Since GAS does not useimport
statement, the classes are not guaranteed to load in the correct order.
For a simple installation, follow the guide above and copy the index.gs
content into App Scripts. This file is condensed to include all modules so you can start working right away. Otherwise, you can add each module in its own file. App Scripts auto include all files in a project and no import is necessary.
The file naming convention follow standard JS principals but you can name them as you wish. Please see description of each file below:
File | Description |
---|---|
Derivatives.gs | Encapsulates all derivative math. |
Greeks.gs | Encapsulates all option greeks math. |
NormalDistribution.gs | JS implementation of normal distribution function (NORMDIST). |
index.gs | A single file that includes all above for a quick copy/paste into Google Sheets. |
If you are not familiar with google Scripts, here are some resources to get you started.
There are two primary ways to interact with the script:
- Retrieve a contracts full quote, which includes price + greeks, for both Calls and Puts.
- Retrieve specific information, as needed (ex: get Gamma for Calls or Price for Puts).
Default return of a 2D array (two rows) with price and all the Greeks for put and call. Specifying quote
will trim the output to the the specified request. Table below lists all valid input.
Name | Description |
---|---|
default | array Returns the full quote for both sides of the contract (CALL|PUT). |
price | float Returns the price of the contract. type defaults to CALL. |
delta | float Returns the Delta value of the contract. type defaults to CALL. |
gamma | float Returns the Gamma value of the contract. Bi directional (CALL|PUT) does not change value. |
vega | float Returns the Vega value of the contract. Bi directional (CALL|PUT) does not change value. |
rho | float Returns the Rho value of the contract. type defaults to CALL. |
theta | float Returns the Theta value of the contract. type defaults to CALL. |
Name | Description |
---|---|
price | float Spot price of underlying stock. |
strike | float Selected option strike. |
time | float Time to maturity (expiry - today) / 365. |
rate | float Suggested default: 10 year bond rate ("TNX"). |
iv | float Implied volatility from your broker or Yahoo Finance. |
divYield | float Annualized dividend yield for the company. |
quote | string Default return of full option contract. Can specify to return subsect of contract. See table above. |
type | string Default CALL but can be specified when retrieving subsect data. |
Col 1 | Col 2 | Col 3 | Col 4 | Col 5 | Col 6 | |
---|---|---|---|---|---|---|
Row 1 | CALL PRICE | DELTA | GAMMA | Theta | VEGA | RHO |
Row 2 | PUT PRICE | DELTA | GAMMA | Theta | VEGA | RHO |
Price | Delta | Gamma | Theta | Vega | Rho |
---|---|---|---|---|---|
float | float | float | float | float | float |
Calculates an approximate price of an option contract.
Name | Description |
---|---|
type | string Specify CALL or PUT . Default CALL . |
nsd_d1 | float Normal Standard Distribution of the first derivative. |
nsd_d2 | float Normal Standard Distribution of the second derivative. |
price | float Spot price of underlying stock. |
strike | float Selected option strike. |
time | float Time to maturity (expiry - today) / 365. |
rate | float Suggested default: 10 year bond rate ("TNX"). |
divYield | float Annualized dividend yield for the company. |
Return:
Name | Type |
---|---|
price | float |
Gamma represents the rate of change between an option's Delta and the underlying asset's price. Higher Gamma values indicate that the Delta could change dramatically with even very small price changes in the underlying stock.
Name | Description |
---|---|
nd1 | float Probability density of the normal distribution. |
price | float Spot price of underlying stock. |
iv | float Implied volatility from your broker or Yahoo Finance. |
time | float Time to maturity (expiry - today) / 365. |
Return:
Name | Type |
---|---|
gamma | float |
Theta represents, in theory, how much an option's premium may decay each day with all other factors remaining the same.
Name | Description |
---|---|
type | string Specify CALL or PUT . Default CALL . |
nd1 | float Probability density of the normal distribution. |
nsd_d2 | float Normal Standard Distribution of the second derivative. |
price | float Spot price of underlying stock. |
strike | float Selected option strike. |
time | float Time to maturity (expiry - today) / 365. |
rate | float Annualized dividend yield for the company. |
iv | float Annualized dividend yield for the company. |
Return:
Name | Type |
---|---|
theta | float |
Vega measures the amount of increase or decrease in an option premium based on a 1% change in implied volatility.
Name | Description |
---|---|
nd1 | float Probability density of the normal distribution. |
price | float Spot price of underlying stock. |
strike | float Selected option strike. |
time | float Time to maturity (expiry - today) / 365. |
rate | float Suggested default: 10 year bond rate ("TNX"). |
iv | float Implied volatility from your broker or Yahoo Finance. |
divYield | float Annualized dividend yield for the company. |
Return:
Name | Type |
---|---|
vega | float |
Rho measures an option's sensitivity to changes in the risk-free rate of interest (the interest rate paid on US Treasury bills) and is expressed as the amount of money an option will lose or gain with a 1% change in interest rates.
Name | Description |
---|---|
type | string Specify CALL or PUT . Default CALL . |
nsd_d2 | float Normal Standard Distribution of the second derivative. |
strike | float Selected option strike. |
time | float Time to maturity (expiry - today) / 365. |
rate | float Suggested default: 10 year bond rate ("TNX"). |
Return:
Name | Type |
---|---|
rho | float |
Please see the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.