Calculate estimated margin requirements for equities options, based on CBOE margining.
Project description
margin-estimator
Calculate estimated margin requirements for equities options, based on CBOE margining.
[!NOTE] Box spreads and some complex multi-legged positions may be calculated too conservatively.
Installation
$ pip install margin_estimator
Usage
Simply pass an arbitrary list of legs to the calculate_margin function along with an Underlying object containing information on the underlying, and you'll get back margin requirement estimates for cash and margin accounts!
from datetime import date
from decimal import Decimal
from margin_estimator import (
ETFType,
Option,
OptionType,
Underlying,
calculate_margin,
)
# a SPY iron condor
# make sure to pass `ETFType.BROAD` for broad-based indices
underlying = Underlying(price=Decimal("587.88"), etf_type=ETFType.BROAD)
expiration = date(2024, 12, 20)
long_put = Option(
expiration=expiration,
price=Decimal("4.78"),
quantity=1,
strike=Decimal(567),
type=OptionType.PUT,
)
short_put = Option(
expiration=expiration,
price=Decimal("5.61"),
quantity=-1,
strike=Decimal(572),
type=OptionType.PUT,
)
short_call = Option(
expiration=expiration,
price=Decimal("5.23"),
quantity=-1,
strike=Decimal(602),
type=OptionType.CALL,
)
long_call = Option(
expiration=expiration,
price=Decimal("3.68"),
quantity=1,
strike=Decimal(607),
type=OptionType.CALL,
)
margin = calculate_margin(
[long_put, short_put, long_call, short_call], underlying
)
print(margin)
>>> cash_requirement=Decimal('262.00') margin_requirement=Decimal('262.00')
For normal equities you can omit the etf_type parameter:
# a short F put
underlying = Underlying(price=Decimal("11.03"))
expiration = date(2024, 12, 20)
put = Option(
expiration=expiration,
price=Decimal("0.45"),
quantity=-1,
strike=Decimal(11),
type=OptionType.PUT,
)
margin = calculate_margin([put], underlying)
print(margin)
>>> cash_requirement=Decimal('1055.00') margin_requirement=Decimal('263.00')
And for leveraged products, you'll need to pass in the leverage_factor:
# a naked TQQQ call
underlying = Underlying(
price=Decimal("77.35"),
etf_type=ETFType.BROAD,
leverage_factor=Decimal(3),
)
expiration = date(2024, 12, 20)
call = Option(
expiration=expiration,
price=Decimal("4.45"),
quantity=-1,
strike=Decimal(80),
type=OptionType.CALL,
)
margin = calculate_margin([call], underlying)
print(margin)
>>> cash_requirement=Decimal('7555.00') margin_requirement=Decimal('3661.00')
Please note that all numbers are baseline minimums from CBOE guidelines and individual broker margins will likely vary significantly.
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
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 margin_estimator-0.2.tar.gz.
File metadata
- Download URL: margin_estimator-0.2.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2599e3be3619443a5a6de32f15fbfaeace1ab93bbed832036bce211ad5e3ab6f
|
|
| MD5 |
517e1af5a333dd8a6110afd5592d42e5
|
|
| BLAKE2b-256 |
100dcc459f7c54852fd6f0f3664d805470a37b5af8eafe0fffd2a638ea376b8f
|
Provenance
The following attestation bundles were made for margin_estimator-0.2.tar.gz:
Publisher:
publish.yml on tastyware/margin-estimator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
margin_estimator-0.2.tar.gz -
Subject digest:
2599e3be3619443a5a6de32f15fbfaeace1ab93bbed832036bce211ad5e3ab6f - Sigstore transparency entry: 802591723
- Sigstore integration time:
-
Permalink:
tastyware/margin-estimator@4530dea5a491c5e93a7f96edbc689f32e775a61e -
Branch / Tag:
refs/tags/v0.2 - Owner: https://github.com/tastyware
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4530dea5a491c5e93a7f96edbc689f32e775a61e -
Trigger Event:
release
-
Statement type:
File details
Details for the file margin_estimator-0.2-py3-none-any.whl.
File metadata
- Download URL: margin_estimator-0.2-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c482d1932be8f4b75d5274c6b6c0ce2d7c7c52a04cab75f2e640823322869495
|
|
| MD5 |
25d58c1095af7af45a09cf0e5f1869a5
|
|
| BLAKE2b-256 |
70786007afe68dcee7d00f86b6f0ded061cf86943675326a230fdd04593f5d0c
|
Provenance
The following attestation bundles were made for margin_estimator-0.2-py3-none-any.whl:
Publisher:
publish.yml on tastyware/margin-estimator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
margin_estimator-0.2-py3-none-any.whl -
Subject digest:
c482d1932be8f4b75d5274c6b6c0ce2d7c7c52a04cab75f2e640823322869495 - Sigstore transparency entry: 802591766
- Sigstore integration time:
-
Permalink:
tastyware/margin-estimator@4530dea5a491c5e93a7f96edbc689f32e775a61e -
Branch / Tag:
refs/tags/v0.2 - Owner: https://github.com/tastyware
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4530dea5a491c5e93a7f96edbc689f32e775a61e -
Trigger Event:
release
-
Statement type: