margin-estimator
Calculate estimated margin requirements for equities options, based on CBOE margining.
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,
Shares,
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')
You can even add shares of an underlying to calculate requirements for covered legs:
# a covered SPY call
underlying = Underlying(price=Decimal("740"))
expiration = date(2026, 5, 15)
call = Option(
expiration=expiration,
price=Decimal("4.45"),
quantity=-1,
strike=Decimal(780),
type=OptionType.CALL,
)
shares = Shares(price=Decimal("700.41"), quantity=100)
margin = calculate_margin([call, shares], underlying)
print(margin)
>>> cash_requirement=Decimal('70041.00') margin_requirement=Decimal('35020.00')
Please note that all numbers are baseline minimums from CBOE guidelines and individual broker margins will likely vary significantly.
Metadata
Release files for margin-estimator 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| margin_estimator-0.4.1.tar.gz | 17.2 kB | With provenance | Details for margin_estimator-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| margin_estimator-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for margin_estimator-0.4.1-py3-none-any.whl |
Total release size: 25.1 kB
Release files / margin_estimator-0.4.1.tar.gz
| Download URL | margin_estimator-0.4.1.tar.gz |
|---|---|
| Size | 17.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b0e25a57e2bd56eb6d3ba41f7603e794eb8d3c0add0dac91e98d9f5bd9c7689f
|
|
BLAKE2b-256 checksum How to use checksums |
21f074a759483242973ddb2ed9689ed6407385d5e78a4d95ca8af8bda36b92f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 16, 2026.
Transparency logRelease files / margin_estimator-0.4.1-py3-none-any.whl
| Download URL | margin_estimator-0.4.1-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
685821a23f4e42b9f8551c956f042a4dbd07513d67058f391c4923a5b1edf8dd
|
|
BLAKE2b-256 checksum How to use checksums |
38306aa2c32029f2b41bc08359b0339fa8c21ae6ad2d29442edad35d17222d82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 16, 2026.
Transparency logSecurity for margin-estimator 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for margin_estimator-0.4.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.