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

marketquant.tools import GammaExposure

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

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 is 50.

  • barchart: A boolean to determine if the gamma exposure should be plotted as a bar chart. Default is False.

  • netexposure: Whether to calculate net exposure by combining puts and calls per strike (True) or separating them (False). Default is False.

  • 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()

1. Initialize Data Provider (Schwab API)

You will need an initialized Schwab API client to fetch the options chains data.

from marketquant.data_provider import schwab
schwab_api = schwab()  # Example API client initialization

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

from marketquant.tools import GammaExposure
from marketquant.data_provider import schwab

# Initialize the API client
schwab_api = schwab()

# Run the GammaExposure calculation and print results to the terminal
gamma_exposure_data = GammaExposure.run(
    client=schwab_api,
    symbol="AAPL",
    plot_strikes=50,
    barchart=False,  # No chart, just print the data
    netexposure=True  # Calculate net exposure
)

print(gamma_exposure_data)

Example 2: Generate and Plot Gamma Exposure Bar Chart

from marketquant.tools import GammaExposure
from marketquant.data_provider import schwab

# Initialize the API client
schwab_api = schwab()

# Run the GammaExposure calculation and plot the bar chart
GammaExposure.run(
    client=schwab_api,
    symbol="AAPL",
    plot_strikes=50,         # Show 50 unique strikes in the plot
    barchart=True,           # Enable chart plotting
    netexposure=False,       # Separate puts and calls
    positive_color="green",  # Customize the color of positive exposure bars
    negative_color="red"     # Customize the color of negative exposure bars
)

The following figure is what the GammaExposure chart will output:

Gamma Exposure Chart

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 (if True, 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