GammaExposure()
GammaExposure initialization and uses
The GammaExposure
class is a utility for calculating and visualizing gamma exposure for a given stock's options chains. It integrates with a data provider (such as Schwab API) to fetch the options data, perform gamma exposure calculations, and display a bar chart if required.
Import Statement
Usage Overview
To use the GammaExposure
class, you need to initialize it with a data provider class (e.g. Schwab) and call the run
method to calculate the gamma exposure and optionally plot a chart.
Class: GammaExposure
GammaExposure
Method: run
GammaExposure.run(client, symbol, plot_strikes=50, barchart=False, netexposure=False, positive_color='blue', negative_color='red')
This is the primary method used for running the gamma exposure calculation. You can print the results to the terminal or visualize them using a bar chart.
Arguments:
client
: Initialized Schwab API client to fetch options chains data.symbol
: The stock ticker symbol (e.g., "AAPL").plot_strikes
: The number of unique strike prices to include in the chart. All expiration dates for these strikes will be included. Default is50
.barchart
: A boolean to determine if the gamma exposure should be plotted as a bar chart. Default isFalse
.netexposure
: Whether to calculate net exposure by combining puts and calls per strike (True
) or separating them (False
). Default isFalse
.positive_color
: Color for positive exposure bars in the chart. Default is'blue'
.negative_color
: Color for negative exposure bars in the chart. Default is'red'
.
Returns:
A
pandas.DataFrame
containing gamma exposure data for the selected strikes.
How to use GammaExposure()
GammaExposure()
1. Initialize Data Provider (Schwab API)
You will need an initialized Schwab API client to fetch the options chains data.
2. Run Gamma Exposure Calculation
The GammaExposure.run
method will calculate gamma exposure for the selected stock. If barchart=True
, it will also generate a bar chart with the results.
Example 1: Print Data to the Terminal
Example 2: Generate and Plot Gamma Exposure Bar Chart
The following figure is what the GammaExposure chart will output:
Customization Options for Chart
When plotting the chart, you can control various aspects of the visualization using the following arguments:
positive_color
: Set the color of bars representing positive exposure.negative_color
: Set the color of bars representing negative exposure.netexposure
: Enable or disable net exposure calculation (ifTrue
, puts and calls are combined for each strike).
The bar chart will automatically display the gamma exposure for the specified number of strikes across all expiration dates.
Output
The output will either be:
A printed DataFrame of gamma exposure values for the specified strikes.
A bar chart with customizable colors to show positive and negative gamma exposure for each strike.
Last updated