margin-estimator 0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,51 @@
1
+ name: Publish Python distribution to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [created]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build distribution
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - name: Set up Python
15
+ uses: actions/setup-python@v5
16
+ with:
17
+ python-version: "3.x"
18
+ - name: Install pypa/build
19
+ run: >-
20
+ python3 -m
21
+ pip install
22
+ build
23
+ --user
24
+ - name: Build a binary wheel and a source tarball
25
+ run: python3 -m build
26
+ - name: Store the distribution packages
27
+ uses: actions/upload-artifact@v4
28
+ with:
29
+ name: python-package-distributions
30
+ path: dist/
31
+
32
+ publish-to-pypi:
33
+ name: >-
34
+ Publish Python distribution to PyPI
35
+ needs:
36
+ - build
37
+ runs-on: ubuntu-latest
38
+ environment:
39
+ name: pypi
40
+ url: https://pypi.org/p/margin-estimator
41
+ permissions:
42
+ id-token: write # IMPORTANT: mandatory for trusted publishing
43
+
44
+ steps:
45
+ - name: Download all the dists
46
+ uses: actions/download-artifact@v4
47
+ with:
48
+ name: python-package-distributions
49
+ path: dist/
50
+ - name: Publish distribution to PyPI
51
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,162 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110
+ .pdm.toml
111
+ .pdm-python
112
+ .pdm-build/
113
+
114
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115
+ __pypackages__/
116
+
117
+ # Celery stuff
118
+ celerybeat-schedule
119
+ celerybeat.pid
120
+
121
+ # SageMath parsed files
122
+ *.sage.py
123
+
124
+ # Environments
125
+ .env
126
+ .venv
127
+ env/
128
+ venv/
129
+ ENV/
130
+ env.bak/
131
+ venv.bak/
132
+
133
+ # Spyder project settings
134
+ .spyderproject
135
+ .spyproject
136
+
137
+ # Rope project settings
138
+ .ropeproject
139
+
140
+ # mkdocs documentation
141
+ /site
142
+
143
+ # mypy
144
+ .mypy_cache/
145
+ .dmypy.json
146
+ dmypy.json
147
+
148
+ # Pyre type checker
149
+ .pyre/
150
+
151
+ # pytype static type analyzer
152
+ .pytype/
153
+
154
+ # Cython debug symbols
155
+ cython_debug/
156
+
157
+ # PyCharm
158
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
159
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
160
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
161
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
+ #.idea/
@@ -0,0 +1 @@
1
+ 3.11
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 tastyware
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,151 @@
1
+ Metadata-Version: 2.3
2
+ Name: margin-estimator
3
+ Version: 0.1
4
+ Summary: Calculate estimated margin requirements for equities, options, futures, and futures options. Based on CBOE and CME margining.
5
+ Project-URL: Homepage, https://github.com/tastyware/margin-estimator
6
+ Author-email: Graeme Holliday <graeme.holliday@pm.me>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2024 tastyware
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ License-File: LICENSE
29
+ Requires-Python: >=3.11
30
+ Requires-Dist: pydantic>=2.9.2
31
+ Description-Content-Type: text/markdown
32
+
33
+ # margin-estimator
34
+ Calculate estimated margin requirements for equities, options, futures, and futures options. Based on CBOE and CME margining.
35
+
36
+ > [!NOTE]
37
+ > Not all features are available yet, pending further development.
38
+ > Currently, equity/ETF/index options are supported, for any trade
39
+ > type other than ratio spreads, box spreads, and jaze lizards.
40
+ > Contributions welcome!
41
+
42
+ ## Installation
43
+
44
+ ```console
45
+ $ pip install margin_estimator
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ Simply pass a 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!
51
+
52
+ ```python
53
+ from datetime import date
54
+ from decimal import Decimal
55
+ from margin_estimator import (
56
+ ETFType,
57
+ Option,
58
+ OptionType,
59
+ Underlying,
60
+ calculate_margin,
61
+ )
62
+
63
+ # a SPY iron condor
64
+ # make sure to pass `ETFType.BROAD` for broad-based indices
65
+ underlying = Underlying(price=Decimal("587.88"), etf_type=ETFType.BROAD)
66
+ expiration = date(2024, 12, 20)
67
+ long_put = Option(
68
+ expiration=expiration,
69
+ price=Decimal("4.78"),
70
+ quantity=1,
71
+ strike=Decimal(567),
72
+ type=OptionType.PUT,
73
+ )
74
+ short_put = Option(
75
+ expiration=expiration,
76
+ price=Decimal("5.61"),
77
+ quantity=-1,
78
+ strike=Decimal(572),
79
+ type=OptionType.PUT,
80
+ )
81
+ short_call = Option(
82
+ expiration=expiration,
83
+ price=Decimal("5.23"),
84
+ quantity=-1,
85
+ strike=Decimal(602),
86
+ type=OptionType.CALL,
87
+ )
88
+ long_call = Option(
89
+ expiration=expiration,
90
+ price=Decimal("3.68"),
91
+ quantity=1,
92
+ strike=Decimal(607),
93
+ type=OptionType.CALL,
94
+ )
95
+ margin = calculate_margin(
96
+ [long_put, short_put, long_call, short_call], underlying
97
+ )
98
+ print(margin)
99
+ ```
100
+
101
+ ```python
102
+ >>> cash_requirement=Decimal('262.00') margin_requirement=Decimal('262.00')
103
+ ```
104
+
105
+ For normal equities you can omit the `etf_type` parameter:
106
+
107
+ ```python
108
+ # a short F put
109
+ underlying = Underlying(price=Decimal("11.03"))
110
+ expiration = date(2024, 12, 20)
111
+ put = Option(
112
+ expiration=expiration,
113
+ price=Decimal("0.45"),
114
+ quantity=-1,
115
+ strike=Decimal(11),
116
+ type=OptionType.PUT,
117
+ )
118
+ margin = calculate_margin([put], underlying)
119
+ print(margin)
120
+ ```
121
+
122
+ ```python
123
+ >>> cash_requirement=Decimal('1055.00') margin_requirement=Decimal('263.00')
124
+ ```
125
+
126
+ And for leveraged products, you'll need to pass in the `leverage_factor`:
127
+
128
+ ```python
129
+ # a naked TQQQ call
130
+ underlying = Underlying(
131
+ price=Decimal("77.35"),
132
+ etf_type=ETFType.BROAD,
133
+ leverage_factor=Decimal(3),
134
+ )
135
+ expiration = date(2024, 12, 20)
136
+ call = Option(
137
+ expiration=expiration,
138
+ price=Decimal("4.45"),
139
+ quantity=-1,
140
+ strike=Decimal(80),
141
+ type=OptionType.CALL,
142
+ )
143
+ margin = calculate_margin([call], underlying)
144
+ print(margin)
145
+ ```
146
+
147
+ ```python
148
+ >>> cash_requirement=Decimal('7555.00') margin_requirement=Decimal('3661.00')
149
+ ```
150
+
151
+ Please note that all numbers are baseline estimates based on CBOE/CME guidelines and individual broker margins will likely vary significantly.
@@ -0,0 +1,119 @@
1
+ # margin-estimator
2
+ Calculate estimated margin requirements for equities, options, futures, and futures options. Based on CBOE and CME margining.
3
+
4
+ > [!NOTE]
5
+ > Not all features are available yet, pending further development.
6
+ > Currently, equity/ETF/index options are supported, for any trade
7
+ > type other than ratio spreads, box spreads, and jaze lizards.
8
+ > Contributions welcome!
9
+
10
+ ## Installation
11
+
12
+ ```console
13
+ $ pip install margin_estimator
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ Simply pass a 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!
19
+
20
+ ```python
21
+ from datetime import date
22
+ from decimal import Decimal
23
+ from margin_estimator import (
24
+ ETFType,
25
+ Option,
26
+ OptionType,
27
+ Underlying,
28
+ calculate_margin,
29
+ )
30
+
31
+ # a SPY iron condor
32
+ # make sure to pass `ETFType.BROAD` for broad-based indices
33
+ underlying = Underlying(price=Decimal("587.88"), etf_type=ETFType.BROAD)
34
+ expiration = date(2024, 12, 20)
35
+ long_put = Option(
36
+ expiration=expiration,
37
+ price=Decimal("4.78"),
38
+ quantity=1,
39
+ strike=Decimal(567),
40
+ type=OptionType.PUT,
41
+ )
42
+ short_put = Option(
43
+ expiration=expiration,
44
+ price=Decimal("5.61"),
45
+ quantity=-1,
46
+ strike=Decimal(572),
47
+ type=OptionType.PUT,
48
+ )
49
+ short_call = Option(
50
+ expiration=expiration,
51
+ price=Decimal("5.23"),
52
+ quantity=-1,
53
+ strike=Decimal(602),
54
+ type=OptionType.CALL,
55
+ )
56
+ long_call = Option(
57
+ expiration=expiration,
58
+ price=Decimal("3.68"),
59
+ quantity=1,
60
+ strike=Decimal(607),
61
+ type=OptionType.CALL,
62
+ )
63
+ margin = calculate_margin(
64
+ [long_put, short_put, long_call, short_call], underlying
65
+ )
66
+ print(margin)
67
+ ```
68
+
69
+ ```python
70
+ >>> cash_requirement=Decimal('262.00') margin_requirement=Decimal('262.00')
71
+ ```
72
+
73
+ For normal equities you can omit the `etf_type` parameter:
74
+
75
+ ```python
76
+ # a short F put
77
+ underlying = Underlying(price=Decimal("11.03"))
78
+ expiration = date(2024, 12, 20)
79
+ put = Option(
80
+ expiration=expiration,
81
+ price=Decimal("0.45"),
82
+ quantity=-1,
83
+ strike=Decimal(11),
84
+ type=OptionType.PUT,
85
+ )
86
+ margin = calculate_margin([put], underlying)
87
+ print(margin)
88
+ ```
89
+
90
+ ```python
91
+ >>> cash_requirement=Decimal('1055.00') margin_requirement=Decimal('263.00')
92
+ ```
93
+
94
+ And for leveraged products, you'll need to pass in the `leverage_factor`:
95
+
96
+ ```python
97
+ # a naked TQQQ call
98
+ underlying = Underlying(
99
+ price=Decimal("77.35"),
100
+ etf_type=ETFType.BROAD,
101
+ leverage_factor=Decimal(3),
102
+ )
103
+ expiration = date(2024, 12, 20)
104
+ call = Option(
105
+ expiration=expiration,
106
+ price=Decimal("4.45"),
107
+ quantity=-1,
108
+ strike=Decimal(80),
109
+ type=OptionType.CALL,
110
+ )
111
+ margin = calculate_margin([call], underlying)
112
+ print(margin)
113
+ ```
114
+
115
+ ```python
116
+ >>> cash_requirement=Decimal('7555.00') margin_requirement=Decimal('3661.00')
117
+ ```
118
+
119
+ Please note that all numbers are baseline estimates based on CBOE/CME guidelines and individual broker margins will likely vary significantly.
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "margin-estimator"
7
+ version = "0.1"
8
+ description = "Calculate estimated margin requirements for equities, options, futures, and futures options. Based on CBOE and CME margining."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = {file = "LICENSE"}
12
+ authors = [
13
+ {name = "Graeme Holliday", email = "graeme.holliday@pm.me"},
14
+ ]
15
+ dependencies = [
16
+ "pydantic>=2.9.2",
17
+ ]
18
+
19
+ [project.urls]
20
+ Homepage = "https://github.com/tastyware/margin-estimator"
21
+
22
+ [tool.uv]
23
+ dev-dependencies = [
24
+ "pytest>=8.3.3",
25
+ ]
@@ -0,0 +1,11 @@
1
+ from .margin import calculate_margin
2
+ from .models import ETFType, Option, OptionType, Underlying
3
+
4
+
5
+ __all__ = [
6
+ "ETFType",
7
+ "Option",
8
+ "OptionType",
9
+ "Underlying",
10
+ "calculate_margin",
11
+ ]