Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/phammings/spx500-gamma-exposure-calculator

Script to generate the S&P 500 current Gamma Exposure
https://github.com/phammings/spx500-gamma-exposure-calculator

matplotlib python scipy selenium shell-script

Last synced: 2 months ago
JSON representation

Script to generate the S&P 500 current Gamma Exposure

Awesome Lists containing this project

README

        

# S&P 500 Gamma Calculator



S&P 500 Gamma Calculator


This script is designed to generate the absolute gamma exposure and gamma profile charts of the S&P 500 index based on the current options market.


Table of Contents



  1. About The Project


  2. Roadmap

  3. Instructions

  4. Acknowledgments

## [Tableau Visualization Link πŸ”—](https://public.tableau.com/views/SPXGammaProfileandExposureOverview/Dashboard2?:language=en-US&:sid=&:redirect=auth&:display_count=n&:origin=viz_share_link)

## About The Project

The project obtains options data from [CBOE](https://www.cboe.com/delayed_quotes/spx/quote_table) on the S&P 500 index to generate the absolute gamma exposure (by dollars and by calls/puts) and the gamma profile of the current market.






**Gamma Exposure in Equity Markets and Options Trading**

Gamma exposure refers to the impact of options trading, particularly in equity markets, and plays a crucial role in influencing market dynamics. This exposure is significant, especially in the case of S&P 500 options, which constitute a substantial portion (16%) of the S&P 500 market cap.

Options traders, often viewed as market makers, utilize delta-hedging to manage risks. Delta-hedging involves adjusting their positions in the underlying equity markets based on changes in the price of the asset. This process is essential to flatten risk, but it results in non-discretionary flows known as gamma exposure.

The gamma exposure depends on gamma, a measure indicating the potential delta-hedging activity. It has become more critical as the options market has grown, representing a sizable portion of the underlying equity market.



Two key states are described based on gamma exposure:



**Long Gamma**: Market makers are net buyers of options, providing liquidity during market rallies and absorbing it during drops. This contributes to reduced volatility.

**Short Gamma**: Market makers are net sellers of options, exacerbating market moves and reducing liquidity. This intensifies price actions, particularly during market downturns.


Understanding net gamma positioning involves estimating the direction of options trades. Puts are generally associated with negative gamma, while calls carry positive gamma. The concept of a "gamma flip," where gamma is zero, is closely monitored as it indicates potential shifts in market conditions.

- When the S&P 500 spot price is at this gamma flip level, flows are zero, as delta doesn’t need rebalancing due to spot moves.

- When the S&P 500 spot price is above the gamma flip level, dealer hedging flows are stabilizing and add liquidity to the market.
- A trader that is net long options has a positive gamma position, and hedges by selling stock as it goes up, and buying stock as it goes down. This can have the effect of dampening the underlying stocks movement and creating a low volatility environment.

- When the S&P 500 spot price is below the gamma flip level, dealer hedging flows are destabilizing and add to the volatility instead.
- If a trade is net short options then the trader must hedge by selling the underlying as the stock goes down, and buying as the stock goes up. This could make the stock more volatile as this trading pressure pushes the stock in its prevailing direction.

The impact of gamma exposure is influenced by factors such as time to expiry, open interest, market liquidity, and volatility. High open interest, especially around large expiries and at-the-money options, increases the likelihood of gamma flows impacting the market.

Despite its influence, gamma tends to lose potency in high volatility environments. In such situations, delta becomes less sensitive to underlying moves, affecting the concentration of gamma around the strike.

This project emphasizes the importance of recognizing and understanding gamma exposure to be prepared for its effects on equity markets.


*All code and information above gives credits to [Perfiliev](https://perfiliev.co.uk/market-commentary/how-to-calculate-gamma-exposure-and-zero-gamma-level/) and [Spot Gamma](https://support.spotgamma.com/hc/en-us/articles/15413261162387-Gamma-Flip).*

(back to top)

### Built With

* [![Python][Python.py]][Python-url]
* [![Selenium][Selenium]][Selenium-url]
* [![Matplotlib][Matplotlib]][Matplotlib-url]
* [![Scipy][Scipy]][Scipy-url]
* [![Shell Script][Shell]][Shell-url]

(back to top)

## Roadmap

- βœ”οΈ Employed Selenium for dynamic web scraping, seamlessly gathering data from online sources.
- βœ”οΈ Utilized Python's powerful matplotlib and scipy libraries to perform intricate calculations and craft visually engaging image charts.
- βœ”οΈ Orchestrated an efficient automation workflow using a shell script to streamline and execute the entire process effortlessly.

(back to top)

## Instructions
### Prerequisites
1. Python Installation

- Ensure Python 3.8 or higher is installed on your system. You can download it from Python's official website.

2. Required Libraries

- Install the following Python libraries to ensure the project runs smoothly:
```bash
pip install pandas numpy scipy matplotlib selenium
```
- ``pandas`` and ``numpy``: For data manipulation and analysis.
- ``scipy``: Required for statistical calculations.
- ``matplotlib``: Used to generate charts.
- ``selenium``: Used for web automation.

3. ChromeDriver Setup

- Download the latest ChromeDriver that matches your Chrome browser version from [ChromeDriver](https://googlechromelabs.github.io/chrome-for-testing/#stable]][https://googlechromelabs.github.io/chrome-for-testing/#stable) for Testing.
- Place the downloaded ``chromedriver.exe`` file in your ``Program Files`` folder, or add its path to your system's PATH environment variable.

### Clone Repository and Run
1. Clone this repository

```bash
git clone https://github.com/phammings/SPX500-Gamma-Exposure-Calculator.git
```

2. Run the Gamma Calculator Script

- Execute the following script to generate three charts:
```bash
gammaCalculator.sh
```
- The script will generate:
- Absolute Gamma Exposure by Dollars Chart
- Absolute Gamma Exposure by Calls/Puts Chart
- Gamma Profile Exposure Chart
- Note: The Gamma Profile Chart may take up to 5 minutes to generate.


(back to top)

## Acknowledgments

Gamma Exposure code calculations used from https://perfiliev.co.uk/market-commentary/how-to-calculate-gamma-exposure-and-zero-gamma-level/.

(back to top)

[Python.py]: https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54
[Python-url]: https://www.python.org/
[Selenium]: https://img.shields.io/badge/-selenium-%43B02A?style=for-the-badge&logo=selenium&logoColor=white
[Selenium-url]: https://www.selenium.dev/
[Matplotlib]: https://img.shields.io/badge/Matplotlib-%23FF0000.svg?style=for-the-badge&logo=Matplotlib&logoColor=black
[Matplotlib-url]: https://matplotlib.org/
[Scipy]: https://img.shields.io/badge/SciPy-%230C55A5.svg?style=for-the-badge&logo=scipy&logoColor=%white
[Scipy-url]: https://scipy.org/
[Shell]: https://img.shields.io/badge/shell_script-%23121011.svg?style=for-the-badge&logo=gnu-bash&logoColor=white
[Shell-url]: https://www.shellscript.sh/