pyamcos 1.0.0__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.
- pyamcos-1.0.0/LICENSE +21 -0
- pyamcos-1.0.0/MANIFEST.in +1 -0
- pyamcos-1.0.0/PKG-INFO +81 -0
- pyamcos-1.0.0/README.md +66 -0
- pyamcos-1.0.0/pyamcos/__init__.py +28 -0
- pyamcos-1.0.0/pyamcos/cos_core.c +36697 -0
- pyamcos-1.0.0/pyamcos/cos_core.pyx +293 -0
- pyamcos-1.0.0/pyamcos/cos_market.py +85 -0
- pyamcos-1.0.0/pyamcos/cos_pricer.py +200 -0
- pyamcos-1.0.0/pyamcos/cos_py.py +326 -0
- pyamcos-1.0.0/pyamcos/forward_band.py +118 -0
- pyamcos-1.0.0/pyamcos.egg-info/PKG-INFO +81 -0
- pyamcos-1.0.0/pyamcos.egg-info/SOURCES.txt +18 -0
- pyamcos-1.0.0/pyamcos.egg-info/dependency_links.txt +1 -0
- pyamcos-1.0.0/pyamcos.egg-info/requires.txt +5 -0
- pyamcos-1.0.0/pyamcos.egg-info/top_level.txt +1 -0
- pyamcos-1.0.0/pyproject.toml +30 -0
- pyamcos-1.0.0/setup.cfg +4 -0
- pyamcos-1.0.0/setup.py +14 -0
- pyamcos-1.0.0/tests/test_cos.py +143 -0
pyamcos-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Martial Ren
|
|
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 @@
|
|
|
1
|
+
include pyamcos/*.pyx
|
pyamcos-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyamcos
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: American option pricing and implied volatility by the COS method, with discrete dividends (Cython)
|
|
5
|
+
Author: Martial Ren
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: numpy
|
|
11
|
+
Requires-Dist: scipy
|
|
12
|
+
Provides-Extra: test
|
|
13
|
+
Requires-Dist: pytest; extra == "test"
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# pyamcos
|
|
17
|
+
|
|
18
|
+
American option pricing and implied volatility by the COS (Fourier-cosine) method of
|
|
19
|
+
Fang & Oosterlee (2009), with discrete proportional dividends. The backward recursion is a
|
|
20
|
+
Cython extension with its own radix-2 FFT, running without the GIL; one recursion prices a
|
|
21
|
+
whole strike chain.
|
|
22
|
+
|
|
23
|
+
## Conventions
|
|
24
|
+
|
|
25
|
+
Same as [pybaw](https://pypi.org/project/pybaw/):
|
|
26
|
+
|
|
27
|
+
- `sigma` is the Black **total** vol (total standard deviation, `sigma_annual * sqrt(T)`).
|
|
28
|
+
- Arguments are `(S, K, D, F, sigma, flag)`; time is normalised to `T = 1`, `r = -ln(D)`.
|
|
29
|
+
- Prices are **raw premiums**; intrinsic is the American `max(S-K, 0)` / `max(K-S, 0)`.
|
|
30
|
+
- Dividends are `divs = [(frac, delta), ...]`: `frac` in (0, 1) is the ex-date's position in the
|
|
31
|
+
option's life, `delta` the proportional drop. `F` is the forward after them, so with the
|
|
32
|
+
dividends fixed `F` only carries the borrow.
|
|
33
|
+
- Implied-vol sentinels: `0.0` = exercise (in the money, quote at intrinsic); `NaN` = no vol
|
|
34
|
+
(a quote below intrinsic, an out-of-the-money zero bid, or out of reach).
|
|
35
|
+
|
|
36
|
+
## Method
|
|
37
|
+
|
|
38
|
+
- An American price is a Richardson extrapolation on Bermudans with 128, 256 and 512 exercise
|
|
39
|
+
dates, error exponents (1, 1.5).
|
|
40
|
+
- A call with borrow `q <= 0` and `r >= 0` is only ever exercised just before an ex-date, so it is
|
|
41
|
+
priced exactly, in one pass over the ex-dates and expiry (about 70x faster).
|
|
42
|
+
- `cos_implied_vol_chain` inverts a whole chain at once: it prices every strike on a vol grid
|
|
43
|
+
(one recursion per vol, on a thread pool) and inverts by monotone interpolation.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
pip install pyamcos
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Prebuilt wheels cover CPython 3.11+ on Linux (x86_64, aarch64), Windows (x86_64) and macOS
|
|
52
|
+
(arm64, x86_64). Elsewhere pip builds the sdist, which needs a C compiler: the compiled
|
|
53
|
+
extension is required, there is no pure-Python fallback.
|
|
54
|
+
|
|
55
|
+
## API
|
|
56
|
+
|
|
57
|
+
| Function | Purpose |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `cos_price(S, K, D, F, sigma, flag, divs=(), settings=FAST)` | American price; `K` may be an array |
|
|
60
|
+
| `cos_implied_vol(price, S, K, D, F, flag, divs=())` | invert one raw premium to total vol |
|
|
61
|
+
| `cos_implied_vol_chain(prices, S, K[], D, F, flag, divs=())` | invert a chain; `prices` `(n_K,)` or `(n_sets, n_K)` |
|
|
62
|
+
| `forward_band_cos(call_bid, call_ask, put_bid, put_ask, strikes, S, D, divs=())` | `(F_bid, F_ask)` where the near-money call and put vol intervals agree |
|
|
63
|
+
| `forward_band(...)`, `usable_forward_strikes(...)` | the model-agnostic forward search behind it |
|
|
64
|
+
|
|
65
|
+
`FAST` (about 2e-5 absolute on single strikes) and `ACCURATE` (about 3e-6) are the settings presets.
|
|
66
|
+
|
|
67
|
+
The forward search: only strikes whose four quotes are above intrinsic vote. At a trial
|
|
68
|
+
forward, a strike votes "too low" when its call bid vol is above its put ask vol and "too high"
|
|
69
|
+
when its put bid vol is above its call ask vol; the band is where the votes balance, after
|
|
70
|
+
dropping strikes that still dissent there, so one bad strike cannot move it.
|
|
71
|
+
|
|
72
|
+
## Tests
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
pip install -e .[test]
|
|
76
|
+
pytest
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
MIT, see [LICENSE](LICENSE).
|
pyamcos-1.0.0/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# pyamcos
|
|
2
|
+
|
|
3
|
+
American option pricing and implied volatility by the COS (Fourier-cosine) method of
|
|
4
|
+
Fang & Oosterlee (2009), with discrete proportional dividends. The backward recursion is a
|
|
5
|
+
Cython extension with its own radix-2 FFT, running without the GIL; one recursion prices a
|
|
6
|
+
whole strike chain.
|
|
7
|
+
|
|
8
|
+
## Conventions
|
|
9
|
+
|
|
10
|
+
Same as [pybaw](https://pypi.org/project/pybaw/):
|
|
11
|
+
|
|
12
|
+
- `sigma` is the Black **total** vol (total standard deviation, `sigma_annual * sqrt(T)`).
|
|
13
|
+
- Arguments are `(S, K, D, F, sigma, flag)`; time is normalised to `T = 1`, `r = -ln(D)`.
|
|
14
|
+
- Prices are **raw premiums**; intrinsic is the American `max(S-K, 0)` / `max(K-S, 0)`.
|
|
15
|
+
- Dividends are `divs = [(frac, delta), ...]`: `frac` in (0, 1) is the ex-date's position in the
|
|
16
|
+
option's life, `delta` the proportional drop. `F` is the forward after them, so with the
|
|
17
|
+
dividends fixed `F` only carries the borrow.
|
|
18
|
+
- Implied-vol sentinels: `0.0` = exercise (in the money, quote at intrinsic); `NaN` = no vol
|
|
19
|
+
(a quote below intrinsic, an out-of-the-money zero bid, or out of reach).
|
|
20
|
+
|
|
21
|
+
## Method
|
|
22
|
+
|
|
23
|
+
- An American price is a Richardson extrapolation on Bermudans with 128, 256 and 512 exercise
|
|
24
|
+
dates, error exponents (1, 1.5).
|
|
25
|
+
- A call with borrow `q <= 0` and `r >= 0` is only ever exercised just before an ex-date, so it is
|
|
26
|
+
priced exactly, in one pass over the ex-dates and expiry (about 70x faster).
|
|
27
|
+
- `cos_implied_vol_chain` inverts a whole chain at once: it prices every strike on a vol grid
|
|
28
|
+
(one recursion per vol, on a thread pool) and inverts by monotone interpolation.
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
pip install pyamcos
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Prebuilt wheels cover CPython 3.11+ on Linux (x86_64, aarch64), Windows (x86_64) and macOS
|
|
37
|
+
(arm64, x86_64). Elsewhere pip builds the sdist, which needs a C compiler: the compiled
|
|
38
|
+
extension is required, there is no pure-Python fallback.
|
|
39
|
+
|
|
40
|
+
## API
|
|
41
|
+
|
|
42
|
+
| Function | Purpose |
|
|
43
|
+
|---|---|
|
|
44
|
+
| `cos_price(S, K, D, F, sigma, flag, divs=(), settings=FAST)` | American price; `K` may be an array |
|
|
45
|
+
| `cos_implied_vol(price, S, K, D, F, flag, divs=())` | invert one raw premium to total vol |
|
|
46
|
+
| `cos_implied_vol_chain(prices, S, K[], D, F, flag, divs=())` | invert a chain; `prices` `(n_K,)` or `(n_sets, n_K)` |
|
|
47
|
+
| `forward_band_cos(call_bid, call_ask, put_bid, put_ask, strikes, S, D, divs=())` | `(F_bid, F_ask)` where the near-money call and put vol intervals agree |
|
|
48
|
+
| `forward_band(...)`, `usable_forward_strikes(...)` | the model-agnostic forward search behind it |
|
|
49
|
+
|
|
50
|
+
`FAST` (about 2e-5 absolute on single strikes) and `ACCURATE` (about 3e-6) are the settings presets.
|
|
51
|
+
|
|
52
|
+
The forward search: only strikes whose four quotes are above intrinsic vote. At a trial
|
|
53
|
+
forward, a strike votes "too low" when its call bid vol is above its put ask vol and "too high"
|
|
54
|
+
when its put bid vol is above its call ask vol; the band is where the votes balance, after
|
|
55
|
+
dropping strikes that still dissent there, so one bad strike cannot move it.
|
|
56
|
+
|
|
57
|
+
## Tests
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
pip install -e .[test]
|
|
61
|
+
pytest
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
MIT, see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""pyamcos: American options by the COS method (Fang & Oosterlee 2009), with discrete dividends.
|
|
2
|
+
|
|
3
|
+
Cython backward pass; prices a whole strike chain per recursion. Conventions as in pybaw: sigma is the
|
|
4
|
+
Black total vol, prices are raw premiums, time is normalised to T = 1 (r = -ln D).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .cos_pricer import (
|
|
8
|
+
ACCURATE,
|
|
9
|
+
FAST,
|
|
10
|
+
INTRINSIC_TOL,
|
|
11
|
+
cos_implied_vol,
|
|
12
|
+
cos_implied_vol_chain,
|
|
13
|
+
cos_price,
|
|
14
|
+
forward_band_cos,
|
|
15
|
+
)
|
|
16
|
+
from .forward_band import forward_band, usable_forward_strikes
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"ACCURATE",
|
|
20
|
+
"FAST",
|
|
21
|
+
"INTRINSIC_TOL",
|
|
22
|
+
"cos_implied_vol",
|
|
23
|
+
"cos_implied_vol_chain",
|
|
24
|
+
"cos_price",
|
|
25
|
+
"forward_band",
|
|
26
|
+
"forward_band_cos",
|
|
27
|
+
"usable_forward_strikes",
|
|
28
|
+
]
|