A package for options trading strategies and analysis
Project description
OptionQuant: A Python Package for Option Pricing and Strategy Analysis
OptionQuant is a Python package designed to assist in the pricing and analysis of financial options. It includes functionality for various option pricing models, including the Binomial and Black-Scholes-Merton models. Additionally, the package provides tools for defining option strategies and visualizing their profit and loss (PnL) across a range of underlying prices.
Installation
To install OptionQuant
, you can either clone this repository or install it directly from PyPI (if published):
git clone https://github.com/yourusername/OptionQuant.git
cd OptionQuant
python setup.py install
Usage
Option
The Option
class allows you to define the properties of an individual option contract (either 'call' or 'put') and calculate its profit/loss (PnL) based on various underlying prices.
Example Usage
import OptionQuant as oq
# Define an option: (option_type, strike, underlying_price, premium, time_to_expiry, sigma, contract_fee, is_american)
option1 = oq.Option('put', 140, 141, 8.15, 2, 1.07, 0.75, True)
# Get PnL for the option across a range of underlying prices
pnl_values = option1.pnl()
# Print the PnL
print(pnl_values)
Option Strategy
The OptionStrategy
class allows you to create strategies by combining multiple options. You can calculate and plot the strategy's total PnL across a range of underlying asset prices.
import numpy as np
import OptionQuant as oq
# Define multiple options
option1 = oq.Option('put', 140, 141, 8.15, 2, 1.07, 0.75, True)
option2 = oq.Option('call', 140, 142, 5.80, 2, 1.07, 0.75)
# Define the strategy with a range of underlying prices
strategy = oq.OptionStrategy([option1, option2], np.linspace(130, 150, 1000))
# Plot the strategy's PnL
strategy.plot()
Option Pricing
The OptionPricer
class provides methods for pricing options using the Binomial and Black-Scholes-Merton models.
Example Usage (Binomial Model)
import OptionQuant as oq
option1 = oq.Option('put', 140, 141, 8.15, 2, 1.07, 0.75, True)
# Price the option using the Binomial Model
binomial_price = oq.OptionPricer.binomial_model(option1, risk_free_rate=0.04)
print(f"Option Price (Binomial): {binomial_price}")
Example Usage (Black-Scholes-Merton Model)
option1 = oq.Option('call', 140, 141, 5.80, 2, 1.07, 0.75)
# Price the option using the Black-Scholes-Merton Model
bs_price = oq.OptionPricer.black_scholes_merton(option1, risk_free_rate=0.04)
print(f"Option Price (Black-Scholes-Merton): {bs_price}")
Strategy Plotter
The StrategyPlotter
class provides a method to visualize the strategy's PnL across a range of underlying prices. This is useful to analyze potential outcomes and break-even points for a given strategy.
import OptionQuant as oq
# Define your options and strategy as before
option1 = oq.Option('put', 140, 141, 8.15, 2, 1.07, 0.75, True)
option2 = oq.Option('call', 140, 142, 5.80, 2, 1.07, 0.75)
strategy = oq.OptionStrategy([option1, option2], np.linspace(130, 150, 1000))
# Use the StrategyPlotter to visualize the strategy's PnL
oq.StrategyPlotter.plot_strategy_pnl(strategy.strategy_pnl_values, strategy.break_even_underlying)
Development
OptionQuant is using Python 3.13.0. After cloning the repo, setting up a virtual environment and installing the dependencies, read the Module section below to understand the structure of the package.
Modules
option.py
Defines the Option
class, which represents an individual option contract. It provides functionality for calculating the profit and loss (PnL) based on underlying prices and option parameters.
Key Functions:
pnl
: Calculates the PnL for the option based on underlying prices.
pricer.py
Defines the OptionPricer
class, which includes methods to price options using the Binomial model and the Black-Scholes-Merton model.
Key Functions:
binomial_model
: Prices an option using the Binomial Option Pricing Model.black_scholes_merton
: Prices an option using the Black-Scholes-Merton model.
strategy.py
Defines the OptionStrategy
class, which allows you to combine multiple options into a single strategy. It computes the total PnL of the strategy and identifies break-even points.
Key Functions:
_pnl
: Computes the total strategy PnL._break_even
: Identifies the break-even points of the strategy.plot
: Plots the strategy’s PnL vs underlying price.
plotter.py
Defines the StrategyPlotter
class, which provides functionality to plot the strategy's PnL against underlying prices and mark the break-even points.
Key Functions:
plot_strategy_pnl
: Plots the strategy's PnL and break-even points.
License
This package is licensed under the MIT License. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file optionquant-1.0.0.tar.gz
.
File metadata
- Download URL: optionquant-1.0.0.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e33dd5cc655438d6b32bf4393d8d4c38b06a1ceebaac3b5d7ee4848f37e3f9f |
|
MD5 | 1535e84ab1fdd61e97936d39159dd280 |
|
BLAKE2b-256 | 3ca785f053070844fca3582e1193232439b5aa9f57f9bf0ec4ff8dd42b33fff9 |
File details
Details for the file OptionQuant-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: OptionQuant-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.13.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c3efaa35b22a8898afcd0560b89693f9363a3d7bb12e263d8baf8d8f871970d |
|
MD5 | 37d8e81a98d139edae28c5e1d131a6d1 |
|
BLAKE2b-256 | 05e2488a9cbcb9e2756c8c6f7e4a920568d02d490cafb15e25f025a7df32556a |