A small Python library for building options strategies
Project description
optstrat
A small Python library for building options strategies.
It lets you define a strategy leg by leg, calculate the payoff at expiration, and compute max profit and max loss.
Installation
pip install optstrat
For plotting examples:
pip install matplotlib
Usage example
Plot payoff using matplotlib:
import matplotlib.pyplot as plt
from optstrat import OptionStrategy
strategy = OptionStrategy("Covered Call", 100, contract_size=100)
# 100 shares + short 1 call contract
strategy.long_underlying(100, quantity=100)
strategy.short_call(110, 2.5, quantity=1)
max_profit, max_loss = strategy.max_profit_and_loss()
net_cost = strategy.net_cost()
print(f"Max Profit: {max_profit}")
print(f"Max Loss: {max_loss}")
print(f"Cost of entering position ${net_cost}")
for leg in strategy.legs:
print(leg)
plt.plot(strategy.underlying_prices, strategy.payoffs)
plt.title(strategy.name)
plt.fill_between(
strategy.underlying_prices,
strategy.payoffs,
where=(strategy.payoffs > 0),
facecolor='g',
alpha=0.4,
)
plt.fill_between(
strategy.underlying_prices,
strategy.payoffs,
where=(strategy.payoffs < 0),
facecolor='r',
alpha=0.4,
)
plt.xlabel(r'$S_T$')
plt.ylabel('P&L')
plt.show()
Notes
underlying_pricesrepresents possible underlying prices at expiration.quantityis the number of contracts for option legs and the number of shares for underlying legs.contract_sizeapplies only to option legs.strategy.net_cost()computes the net cost of entering the position.strategy.max_profit_and_loss()computes max profit and max loss at expiration.
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
optstrat-0.1.0.tar.gz
(4.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file optstrat-0.1.0.tar.gz.
File metadata
- Download URL: optstrat-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cacb64981f5ffb93fe69b91074511ba5630ea8bc5fa50a347939e174b7878725
|
|
| MD5 |
f88df867d7f6a36de98e2593c89abdca
|
|
| BLAKE2b-256 |
bab5724b48c3c860624695c30c031e1aeaec4b15ac717ad6e9a1fe731da9510b
|
File details
Details for the file optstrat-0.1.0-py3-none-any.whl.
File metadata
- Download URL: optstrat-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6fec4c3f6fc45a82e711c2e82eb4fe7642ad0b1b7afe5afb1cc7416a9f1a30d
|
|
| MD5 |
bb9316448b4bd361a8ff78c0677a73e2
|
|
| BLAKE2b-256 |
4e8ec72178ee1a680b31172757012c3606fefca24554a3073b171c6dacaf5790
|