morphiq-sdk 0.2.1__tar.gz → 0.3.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.
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/PKG-INFO +59 -44
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/README.md +58 -43
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/README.md +58 -13
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/batch_price.py +49 -32
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/batch_price_async.py +49 -32
- morphiq_sdk-0.3.1/examples/book_explain.py +85 -0
- morphiq_sdk-0.3.1/examples/book_revalue.py +85 -0
- morphiq_sdk-0.3.1/examples/book_solve.py +81 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/chunked_price.py +37 -20
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/chunked_price_async.py +39 -20
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/greeks.py +31 -17
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/greeks_async.py +31 -17
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/identify_regime.py +65 -40
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/identify_regime_async.py +65 -40
- morphiq_sdk-0.2.1/examples/analytics.py → morphiq_sdk-0.3.1/examples/implied_greeks.py +33 -20
- morphiq_sdk-0.2.1/examples/analytics_async.py → morphiq_sdk-0.3.1/examples/implied_greeks_async.py +27 -20
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/implied_volatility.py +31 -17
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/implied_volatility_async.py +25 -17
- morphiq_sdk-0.2.1/examples/pricing_models.py → morphiq_sdk-0.3.1/examples/list_models.py +7 -3
- morphiq_sdk-0.3.1/examples/option_revalue.py +48 -0
- morphiq_sdk-0.3.1/examples/option_solve.py +50 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/price_american.py +31 -17
- morphiq_sdk-0.3.1/examples/price_async.py +97 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/price_european.py +31 -17
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/provider_regime.py +6 -5
- morphiq_sdk-0.3.1/examples/quickstart.py +96 -0
- morphiq_sdk-0.3.1/examples/rate_card_quote.py +105 -0
- morphiq_sdk-0.3.1/examples/solver_app/README.md +29 -0
- morphiq_sdk-0.3.1/examples/solver_app/app.js +121 -0
- morphiq_sdk-0.3.1/examples/solver_app/app.py +215 -0
- morphiq_sdk-0.3.1/examples/solver_app/index.html +72 -0
- morphiq_sdk-0.3.1/examples/solver_app/style.css +2 -0
- morphiq_sdk-0.2.1/examples/greeks_standard.py → morphiq_sdk-0.3.1/examples/standard_greeks.py +32 -18
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/tabular_price.py +27 -14
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/notebooks/README.md +17 -4
- morphiq_sdk-0.3.1/notebooks/books/explain.ipynb +31 -0
- morphiq_sdk-0.3.1/notebooks/books/revalue.ipynb +31 -0
- morphiq_sdk-0.3.1/notebooks/books/solve.ipynb +31 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/notebooks/cost/quotation.ipynb +36 -20
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/notebooks/pricing/models.ipynb +17 -5
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/notebooks/pricing/options.ipynb +182 -86
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/notebooks/pricing/standard-five.ipynb +41 -14
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/notebooks/regime/identification.ipynb +110 -55
- morphiq_sdk-0.3.1/notebooks/scenarios/revalue.ipynb +31 -0
- morphiq_sdk-0.3.1/notebooks/scenarios/solve.ipynb +31 -0
- morphiq_sdk-0.3.1/notebooks/start-here.ipynb +23 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/pyproject.toml +1 -1
- morphiq_sdk-0.3.1/src/morphiq_sdk/__init__.py +346 -0
- morphiq_sdk-0.3.1/src/morphiq_sdk/client.py +1021 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/src/morphiq_sdk/errors.py +16 -14
- morphiq_sdk-0.3.1/src/morphiq_sdk/models.py +1619 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/src/morphiq_sdk/pandas.py +23 -33
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/src/morphiq_sdk/workflows.py +15 -32
- morphiq_sdk-0.2.1/examples/cost_quote.py +0 -77
- morphiq_sdk-0.2.1/examples/price_async.py +0 -78
- morphiq_sdk-0.2.1/examples/quickstart.py +0 -77
- morphiq_sdk-0.2.1/notebooks/start-here.ipynb +0 -23
- morphiq_sdk-0.2.1/src/morphiq_sdk/__init__.py +0 -123
- morphiq_sdk-0.2.1/src/morphiq_sdk/client.py +0 -714
- morphiq_sdk-0.2.1/src/morphiq_sdk/models.py +0 -745
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/.gitignore +0 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/LICENSE +0 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/examples/__init__.py +0 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/src/morphiq_sdk/market_data.py +0 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/src/morphiq_sdk/py.typed +0 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/src/morphiq_sdk_yahoo/__init__.py +0 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.1}/src/morphiq_sdk_yahoo/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: morphiq-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Option pricing, Greeks, implied volatility and market regime identification through a Python API client
|
|
5
5
|
Project-URL: Homepage, https://developers.morphiqlabs.com
|
|
6
6
|
Project-URL: Documentation, https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/README.md
|
|
@@ -34,24 +34,28 @@ Provides-Extra: pandas
|
|
|
34
34
|
Requires-Dist: pandas<4,>=2.2; extra == 'pandas'
|
|
35
35
|
Description-Content-Type: text/markdown
|
|
36
36
|
|
|
37
|
-
#
|
|
37
|
+
# Options, scenarios, books and market regimes in Python
|
|
38
38
|
|
|
39
39
|
Price European and American options, calculate standard-five or all-ten Greeks, solve implied
|
|
40
|
-
volatility, and
|
|
40
|
+
volatility, revalue scenarios and books, explain P&L, solve targets, and identify
|
|
41
|
+
market regimes from price histories.
|
|
41
42
|
|
|
42
43
|
`morphiq-sdk` is a typed Python client for the MorphIQ API, with synchronous and
|
|
43
|
-
asynchronous calls. Pricing, Greeks, implied volatility and
|
|
44
|
+
asynchronous calls. Pricing, Greeks, implied volatility and implied Greeks
|
|
44
45
|
support ordered batches. Runnable examples and interactive notebooks cover option
|
|
45
|
-
valuation, sensitivity analysis and market-regime identification.
|
|
46
|
+
valuation, sensitivity analysis, scenarios, books and market-regime identification.
|
|
46
47
|
|
|
47
48
|
See the [documentation index](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/README.md) for all feature guides and the
|
|
48
49
|
[Python API reference](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/API.md) for methods, models and errors.
|
|
49
50
|
|
|
50
|
-
This client targets API **
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
This client targets the MorphIQ API **0.10** surface (**API v1 · Beta**,
|
|
52
|
+
contract label `0.1.0`): `collection:verb` routes, `option` / `market` / `model`
|
|
53
|
+
requests, grouped response metadata and RFC 9457 problem errors. Methods are
|
|
54
|
+
grouped by collection and spell each operation's canonical id, for example
|
|
55
|
+
`client.options.price(...)` for `options.price`. The SDK is published on PyPI
|
|
56
|
+
for this contract; SDK 0.2.1 uses the retired API routes. See the
|
|
57
|
+
[0.10.0 migration guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/API_0_10_ADOPTION.md)
|
|
58
|
+
and [model capabilities](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/MODELS.md): BSM/BS1993 support batches
|
|
55
59
|
up to 100; QdFp and cash-dividend finite difference support single price and IV.
|
|
56
60
|
|
|
57
61
|
## Quickstart
|
|
@@ -84,21 +88,16 @@ Save the following as `price_option.py`. It prices a European call with spot and
|
|
|
84
88
|
strike of 100, one year to expiry, 20% volatility, and a 5% interest rate:
|
|
85
89
|
|
|
86
90
|
```python
|
|
87
|
-
from morphiq_sdk import MorphIQ,
|
|
88
|
-
|
|
89
|
-
request =
|
|
90
|
-
exercise_style="european",
|
|
91
|
-
|
|
92
|
-
spot=100.0,
|
|
93
|
-
strike=100.0,
|
|
94
|
-
time_to_expiry_years=1.0,
|
|
95
|
-
risk_free_rate=0.05,
|
|
96
|
-
dividend_yield=0.0,
|
|
91
|
+
from morphiq_sdk import Market, MorphIQ, Option, OptionsPriceRequest
|
|
92
|
+
|
|
93
|
+
request = OptionsPriceRequest(
|
|
94
|
+
option=Option(type="call", exercise_style="european", strike=100.0, time_to_expiry_years=1.0),
|
|
95
|
+
market=Market(spot=100.0, risk_free_rate=0.05, dividend_yield=0.0),
|
|
97
96
|
volatility=0.20,
|
|
98
97
|
)
|
|
99
98
|
|
|
100
99
|
with MorphIQ() as client:
|
|
101
|
-
response = client.price(request)
|
|
100
|
+
response = client.options.price(request)
|
|
102
101
|
print(response.model_dump_json(indent=2, exclude_unset=True))
|
|
103
102
|
```
|
|
104
103
|
|
|
@@ -108,39 +107,56 @@ Run it in the same terminal where you set your API key:
|
|
|
108
107
|
python price_option.py
|
|
109
108
|
```
|
|
110
109
|
|
|
111
|
-
This sends one authenticated `POST https://api.morphiqlabs.com/v1/price`
|
|
112
|
-
and prints the JSON response. Example
|
|
110
|
+
This sends one authenticated `POST https://api.morphiqlabs.com/v1/options:price`
|
|
111
|
+
request with `model: {"id": "auto"}` and prints the JSON response. Example
|
|
112
|
+
response from the recorded synthetic fixture:
|
|
113
113
|
|
|
114
114
|
```json
|
|
115
115
|
{
|
|
116
116
|
"metadata": {
|
|
117
|
-
"request_id": "fr-
|
|
118
|
-
"
|
|
119
|
-
"
|
|
117
|
+
"request_id": "fr-18eb4d3a08c36fa2-0000000000000002",
|
|
118
|
+
"service_version": "0.10.0",
|
|
119
|
+
"contract": {
|
|
120
|
+
"version": "0.1.0",
|
|
121
|
+
"sha256": "68985d43f276fe525f46fbc9dc650a172f1303298bcc831da59f8cfee2dbb4c8"
|
|
122
|
+
},
|
|
120
123
|
"engines": [
|
|
121
124
|
{
|
|
122
125
|
"name": "morphiq-risk",
|
|
123
|
-
"version": "0.
|
|
124
|
-
"revision": "
|
|
126
|
+
"version": "0.46.1",
|
|
127
|
+
"revision": "1550e4e41b243b8a978677bc5e9b46916c08cb0e"
|
|
125
128
|
}
|
|
126
129
|
]
|
|
127
130
|
},
|
|
128
131
|
"result": {
|
|
129
|
-
"price": 10.
|
|
130
|
-
"
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
"price": 10.450583572185577,
|
|
133
|
+
"model": {
|
|
134
|
+
"id": "black_scholes_merton",
|
|
135
|
+
"version": "black_scholes_merton/1"
|
|
136
|
+
}
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
139
|
```
|
|
137
140
|
|
|
138
141
|
Your request ID and engine metadata will reflect the live service. This fixture
|
|
139
|
-
was recorded in open development mode; authenticated responses
|
|
140
|
-
commercial charges in `metadata.
|
|
142
|
+
was recorded in open development mode; authenticated responses also report
|
|
143
|
+
commercial charges in `metadata.billing.charged_cu`, the plan in
|
|
144
|
+
`metadata.policy` and the budget estimate in `metadata.budget`. Keep the request
|
|
145
|
+
ID for support.
|
|
141
146
|
See [the quickstart guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/QUICKSTART.md)
|
|
142
147
|
for input units, async usage, configuration and errors.
|
|
143
148
|
|
|
149
|
+
## Scenarios and books
|
|
150
|
+
|
|
151
|
+
The SDK supports `client.options.revalue` and `client.options.solve_scenario`,
|
|
152
|
+
plus `client.books.revalue`, `client.books.explain` and `client.books.solve_scenario`.
|
|
153
|
+
The async client exposes the same methods. All five support cost quotation and a
|
|
154
|
+
per-request CU ceiling. Results preserve partial failures, solver uncertainty,
|
|
155
|
+
signed positions, strategy membership and expiry/strike P&L attribution.
|
|
156
|
+
|
|
157
|
+
See the [scenario and book guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/SCENARIOS.md)
|
|
158
|
+
and the standalone notebooks in `notebooks/scenarios/` and `notebooks/books/`.
|
|
159
|
+
|
|
144
160
|
## Repository examples and notebooks
|
|
145
161
|
|
|
146
162
|
The executable examples and Docker notebooks live in the repository. Clone it
|
|
@@ -183,7 +199,7 @@ Choose an analysis workspace and run all cells once to display its controls:
|
|
|
183
199
|
- [Option pricing](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/notebooks/pricing/options.ipynb): European/American and model
|
|
184
200
|
dropdowns, call/put selection, editable assumptions, automatic Yahoo daily/intraday underlying prices,
|
|
185
201
|
a valuation comparison table, a price-and-Greeks panel, an implied-volatility solver,
|
|
186
|
-
|
|
202
|
+
implied-Greeks premium analysis, a session CU total and a spot-sensitivity chart.
|
|
187
203
|
- [Regime analysis](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/notebooks/regime/identification.ipynb): ticker selection,
|
|
188
204
|
Yahoo daily/intraday price history, latest regime assessment, score charts and provenance.
|
|
189
205
|
|
|
@@ -223,12 +239,11 @@ no real credentials; native API integration is opt-in. See
|
|
|
223
239
|
[CONTRIBUTING.md](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/CONTRIBUTING.md) and [RELEASE.md](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/RELEASE.md).
|
|
224
240
|
|
|
225
241
|
Clients make no automatic retries and do not follow redirects. A timeout
|
|
226
|
-
may leave work charged. Only `
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
deployments and are never used to calculate a charge.
|
|
242
|
+
may leave work charged. Only `metadata.billing.quoted_cu` and
|
|
243
|
+
`metadata.billing.charged_cu` report commercial CUs. A missing `charged_cu` means
|
|
244
|
+
unreported, not zero. Optional members are omitted by the API, never sent as
|
|
245
|
+
null. Response enums may gain values: the SDK keeps an unknown value as a plain
|
|
246
|
+
string and an unknown variant as an `Unrecognized` model instead of failing.
|
|
232
247
|
|
|
233
248
|
The SDK preserves server results, numerical diagnostics, request IDs, engine
|
|
234
249
|
provenance and commercial Compute Units (CU). Numerical engines, model selection,
|
|
@@ -240,7 +255,7 @@ pricing engines or calculate authoritative customer charges.
|
|
|
240
255
|
```text
|
|
241
256
|
src/morphiq_sdk/ Installable, typed Python package
|
|
242
257
|
scripts/ Development and package verification
|
|
243
|
-
examples/ Runnable pricing, Greeks, IV,
|
|
258
|
+
examples/ Runnable pricing, Greeks, IV, implied-Greeks, batch and regime examples
|
|
244
259
|
notebooks/ Quickstart and standalone feature notebooks
|
|
245
260
|
contracts/ Reviewed OpenAPI snapshot, digest and source provenance
|
|
246
261
|
docker/ Non-root notebook startup and workspace seeding
|
|
@@ -253,4 +268,4 @@ docs/ Usage guides and contract documentation
|
|
|
253
268
|
The SDK, examples and notebooks are licensed under the
|
|
254
269
|
[MIT License](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/LICENSE).
|
|
255
270
|
|
|
256
|
-
See [
|
|
271
|
+
See [the rate card and request quotes](docs/RATE_CARD.md) for zero-CU discovery, conditional quotes, and the optional `max_cu` execution ceiling.
|
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Options, scenarios, books and market regimes in Python
|
|
2
2
|
|
|
3
3
|
Price European and American options, calculate standard-five or all-ten Greeks, solve implied
|
|
4
|
-
volatility, and
|
|
4
|
+
volatility, revalue scenarios and books, explain P&L, solve targets, and identify
|
|
5
|
+
market regimes from price histories.
|
|
5
6
|
|
|
6
7
|
`morphiq-sdk` is a typed Python client for the MorphIQ API, with synchronous and
|
|
7
|
-
asynchronous calls. Pricing, Greeks, implied volatility and
|
|
8
|
+
asynchronous calls. Pricing, Greeks, implied volatility and implied Greeks
|
|
8
9
|
support ordered batches. Runnable examples and interactive notebooks cover option
|
|
9
|
-
valuation, sensitivity analysis and market-regime identification.
|
|
10
|
+
valuation, sensitivity analysis, scenarios, books and market-regime identification.
|
|
10
11
|
|
|
11
12
|
See the [documentation index](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/README.md) for all feature guides and the
|
|
12
13
|
[Python API reference](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/API.md) for methods, models and errors.
|
|
13
14
|
|
|
14
|
-
This client targets API **
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
This client targets the MorphIQ API **0.10** surface (**API v1 · Beta**,
|
|
16
|
+
contract label `0.1.0`): `collection:verb` routes, `option` / `market` / `model`
|
|
17
|
+
requests, grouped response metadata and RFC 9457 problem errors. Methods are
|
|
18
|
+
grouped by collection and spell each operation's canonical id, for example
|
|
19
|
+
`client.options.price(...)` for `options.price`. The SDK is published on PyPI
|
|
20
|
+
for this contract; SDK 0.2.1 uses the retired API routes. See the
|
|
21
|
+
[0.10.0 migration guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/API_0_10_ADOPTION.md)
|
|
22
|
+
and [model capabilities](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/MODELS.md): BSM/BS1993 support batches
|
|
19
23
|
up to 100; QdFp and cash-dividend finite difference support single price and IV.
|
|
20
24
|
|
|
21
25
|
## Quickstart
|
|
@@ -48,21 +52,16 @@ Save the following as `price_option.py`. It prices a European call with spot and
|
|
|
48
52
|
strike of 100, one year to expiry, 20% volatility, and a 5% interest rate:
|
|
49
53
|
|
|
50
54
|
```python
|
|
51
|
-
from morphiq_sdk import MorphIQ,
|
|
52
|
-
|
|
53
|
-
request =
|
|
54
|
-
exercise_style="european",
|
|
55
|
-
|
|
56
|
-
spot=100.0,
|
|
57
|
-
strike=100.0,
|
|
58
|
-
time_to_expiry_years=1.0,
|
|
59
|
-
risk_free_rate=0.05,
|
|
60
|
-
dividend_yield=0.0,
|
|
55
|
+
from morphiq_sdk import Market, MorphIQ, Option, OptionsPriceRequest
|
|
56
|
+
|
|
57
|
+
request = OptionsPriceRequest(
|
|
58
|
+
option=Option(type="call", exercise_style="european", strike=100.0, time_to_expiry_years=1.0),
|
|
59
|
+
market=Market(spot=100.0, risk_free_rate=0.05, dividend_yield=0.0),
|
|
61
60
|
volatility=0.20,
|
|
62
61
|
)
|
|
63
62
|
|
|
64
63
|
with MorphIQ() as client:
|
|
65
|
-
response = client.price(request)
|
|
64
|
+
response = client.options.price(request)
|
|
66
65
|
print(response.model_dump_json(indent=2, exclude_unset=True))
|
|
67
66
|
```
|
|
68
67
|
|
|
@@ -72,39 +71,56 @@ Run it in the same terminal where you set your API key:
|
|
|
72
71
|
python price_option.py
|
|
73
72
|
```
|
|
74
73
|
|
|
75
|
-
This sends one authenticated `POST https://api.morphiqlabs.com/v1/price`
|
|
76
|
-
and prints the JSON response. Example
|
|
74
|
+
This sends one authenticated `POST https://api.morphiqlabs.com/v1/options:price`
|
|
75
|
+
request with `model: {"id": "auto"}` and prints the JSON response. Example
|
|
76
|
+
response from the recorded synthetic fixture:
|
|
77
77
|
|
|
78
78
|
```json
|
|
79
79
|
{
|
|
80
80
|
"metadata": {
|
|
81
|
-
"request_id": "fr-
|
|
82
|
-
"
|
|
83
|
-
"
|
|
81
|
+
"request_id": "fr-18eb4d3a08c36fa2-0000000000000002",
|
|
82
|
+
"service_version": "0.10.0",
|
|
83
|
+
"contract": {
|
|
84
|
+
"version": "0.1.0",
|
|
85
|
+
"sha256": "68985d43f276fe525f46fbc9dc650a172f1303298bcc831da59f8cfee2dbb4c8"
|
|
86
|
+
},
|
|
84
87
|
"engines": [
|
|
85
88
|
{
|
|
86
89
|
"name": "morphiq-risk",
|
|
87
|
-
"version": "0.
|
|
88
|
-
"revision": "
|
|
90
|
+
"version": "0.46.1",
|
|
91
|
+
"revision": "1550e4e41b243b8a978677bc5e9b46916c08cb0e"
|
|
89
92
|
}
|
|
90
93
|
]
|
|
91
94
|
},
|
|
92
95
|
"result": {
|
|
93
|
-
"price": 10.
|
|
94
|
-
"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
"price": 10.450583572185577,
|
|
97
|
+
"model": {
|
|
98
|
+
"id": "black_scholes_merton",
|
|
99
|
+
"version": "black_scholes_merton/1"
|
|
100
|
+
}
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
```
|
|
101
104
|
|
|
102
105
|
Your request ID and engine metadata will reflect the live service. This fixture
|
|
103
|
-
was recorded in open development mode; authenticated responses
|
|
104
|
-
commercial charges in `metadata.
|
|
106
|
+
was recorded in open development mode; authenticated responses also report
|
|
107
|
+
commercial charges in `metadata.billing.charged_cu`, the plan in
|
|
108
|
+
`metadata.policy` and the budget estimate in `metadata.budget`. Keep the request
|
|
109
|
+
ID for support.
|
|
105
110
|
See [the quickstart guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/QUICKSTART.md)
|
|
106
111
|
for input units, async usage, configuration and errors.
|
|
107
112
|
|
|
113
|
+
## Scenarios and books
|
|
114
|
+
|
|
115
|
+
The SDK supports `client.options.revalue` and `client.options.solve_scenario`,
|
|
116
|
+
plus `client.books.revalue`, `client.books.explain` and `client.books.solve_scenario`.
|
|
117
|
+
The async client exposes the same methods. All five support cost quotation and a
|
|
118
|
+
per-request CU ceiling. Results preserve partial failures, solver uncertainty,
|
|
119
|
+
signed positions, strategy membership and expiry/strike P&L attribution.
|
|
120
|
+
|
|
121
|
+
See the [scenario and book guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/SCENARIOS.md)
|
|
122
|
+
and the standalone notebooks in `notebooks/scenarios/` and `notebooks/books/`.
|
|
123
|
+
|
|
108
124
|
## Repository examples and notebooks
|
|
109
125
|
|
|
110
126
|
The executable examples and Docker notebooks live in the repository. Clone it
|
|
@@ -147,7 +163,7 @@ Choose an analysis workspace and run all cells once to display its controls:
|
|
|
147
163
|
- [Option pricing](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/notebooks/pricing/options.ipynb): European/American and model
|
|
148
164
|
dropdowns, call/put selection, editable assumptions, automatic Yahoo daily/intraday underlying prices,
|
|
149
165
|
a valuation comparison table, a price-and-Greeks panel, an implied-volatility solver,
|
|
150
|
-
|
|
166
|
+
implied-Greeks premium analysis, a session CU total and a spot-sensitivity chart.
|
|
151
167
|
- [Regime analysis](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/notebooks/regime/identification.ipynb): ticker selection,
|
|
152
168
|
Yahoo daily/intraday price history, latest regime assessment, score charts and provenance.
|
|
153
169
|
|
|
@@ -187,12 +203,11 @@ no real credentials; native API integration is opt-in. See
|
|
|
187
203
|
[CONTRIBUTING.md](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/CONTRIBUTING.md) and [RELEASE.md](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/RELEASE.md).
|
|
188
204
|
|
|
189
205
|
Clients make no automatic retries and do not follow redirects. A timeout
|
|
190
|
-
may leave work charged. Only `
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
deployments and are never used to calculate a charge.
|
|
206
|
+
may leave work charged. Only `metadata.billing.quoted_cu` and
|
|
207
|
+
`metadata.billing.charged_cu` report commercial CUs. A missing `charged_cu` means
|
|
208
|
+
unreported, not zero. Optional members are omitted by the API, never sent as
|
|
209
|
+
null. Response enums may gain values: the SDK keeps an unknown value as a plain
|
|
210
|
+
string and an unknown variant as an `Unrecognized` model instead of failing.
|
|
196
211
|
|
|
197
212
|
The SDK preserves server results, numerical diagnostics, request IDs, engine
|
|
198
213
|
provenance and commercial Compute Units (CU). Numerical engines, model selection,
|
|
@@ -204,7 +219,7 @@ pricing engines or calculate authoritative customer charges.
|
|
|
204
219
|
```text
|
|
205
220
|
src/morphiq_sdk/ Installable, typed Python package
|
|
206
221
|
scripts/ Development and package verification
|
|
207
|
-
examples/ Runnable pricing, Greeks, IV,
|
|
222
|
+
examples/ Runnable pricing, Greeks, IV, implied-Greeks, batch and regime examples
|
|
208
223
|
notebooks/ Quickstart and standalone feature notebooks
|
|
209
224
|
contracts/ Reviewed OpenAPI snapshot, digest and source provenance
|
|
210
225
|
docker/ Non-root notebook startup and workspace seeding
|
|
@@ -217,4 +232,4 @@ docs/ Usage guides and contract documentation
|
|
|
217
232
|
The SDK, examples and notebooks are licensed under the
|
|
218
233
|
[MIT License](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/LICENSE).
|
|
219
234
|
|
|
220
|
-
See [
|
|
235
|
+
See [the rate card and request quotes](docs/RATE_CARD.md) for zero-CU discovery, conditional quotes, and the optional `max_cu` execution ceiling.
|
|
@@ -23,8 +23,9 @@ python examples/greeks.py
|
|
|
23
23
|
python examples/greeks_async.py
|
|
24
24
|
python examples/implied_volatility.py
|
|
25
25
|
python examples/implied_volatility_async.py
|
|
26
|
-
python examples/
|
|
27
|
-
python examples/
|
|
26
|
+
python examples/standard_greeks.py
|
|
27
|
+
python examples/implied_greeks.py
|
|
28
|
+
python examples/implied_greeks_async.py
|
|
28
29
|
python examples/batch_price.py
|
|
29
30
|
python examples/batch_price_async.py
|
|
30
31
|
```
|
|
@@ -48,21 +49,32 @@ See [the quickstart](../docs/QUICKSTART.md) and [all feature guides](../docs/REA
|
|
|
48
49
|
Start Here links to the interactive workspaces; the standalone scripts remain the
|
|
49
50
|
SDK usage demonstrations.
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
Single pricing, implied-volatility and Greek requests are built from the same parts: an `Option` (type, exercise style,
|
|
53
|
+
strike, time to expiry), a `Market` (spot, rates, optional cash dividends), a
|
|
54
|
+
`volatility` or a `market_price`, and a `ModelSelection`. Methods are grouped by
|
|
55
|
+
the API's collections and spell its canonical operation ids: `client.options.price()`
|
|
56
|
+
is `options.price` (`POST /v1/options:price`). Results report the resolved
|
|
57
|
+
`model.id` and its exact `model.version`; a charge is read from
|
|
58
|
+
`metadata.billing.charged_cu`.
|
|
59
|
+
|
|
60
|
+
The Greeks examples submit `OptionsGreeksRequest` to `client.options.greeks()` and
|
|
61
|
+
display the price plus all ten derivatives, with the same model/charge evidence and error
|
|
62
|
+
handling. Values use annual time units and unit volatility/rate bases. The
|
|
63
|
+
standard-Greeks example calls `client.options.standard_greeks()` for the price and
|
|
64
|
+
delta, gamma, theta, vega and rho. See [the Greeks guide](../docs/GREEKS.md).
|
|
55
65
|
|
|
56
66
|
The implied-volatility examples pass an explicit option premium to
|
|
57
|
-
`client.implied_volatility()` and print IV, residual with its basis, iterations,
|
|
67
|
+
`client.options.implied_volatility()` and print IV, residual with its basis, iterations,
|
|
58
68
|
fallback usage and provenance. See [the IV guide](../docs/IMPLIED_VOLATILITY.md).
|
|
59
69
|
|
|
60
|
-
The
|
|
61
|
-
solve IV and evaluate price and
|
|
62
|
-
|
|
70
|
+
The implied-Greeks examples submit one `OptionsImpliedGreeksRequest` to
|
|
71
|
+
`client.options.implied_greeks()` to solve IV from a premium and evaluate price and
|
|
72
|
+
all ten Greeks at that solved volatility. They report the combined response's
|
|
73
|
+
commercial charge once. See [implied Greeks](../docs/IMPLIED_GREEKS.md).
|
|
63
74
|
|
|
64
|
-
The batch examples submit two explicit pricing requests in one
|
|
65
|
-
ordered item outcomes, and count the
|
|
75
|
+
The batch examples submit two explicit pricing requests as `items` in one
|
|
76
|
+
`client.options.batch_price()` call, preserve ordered item outcomes, and count the
|
|
77
|
+
response charge once. See
|
|
66
78
|
[batch operations and 429 handling](../docs/BATCH.md).
|
|
67
79
|
|
|
68
80
|
The [chunked pricing examples](../docs/WORKFLOWS.md) prepare five synthetic spot
|
|
@@ -90,7 +102,7 @@ python examples/identify_regime_async.py
|
|
|
90
102
|
python examples/provider_regime.py
|
|
91
103
|
```
|
|
92
104
|
|
|
93
|
-
Each script submits one
|
|
105
|
+
Each script submits one `client.series.identify_regime()` request. The first two prompt for a ticker and
|
|
94
106
|
support a masked key prompt; the provider example uses SPY and requires the
|
|
95
107
|
exported key. See [regime interpretation](../docs/REGIME.md) and
|
|
96
108
|
[provider interfaces](../docs/PRICE_PROVIDERS.md). Data stays in memory; no CSV
|
|
@@ -110,3 +122,36 @@ python examples/tabular_price.py
|
|
|
110
122
|
|
|
111
123
|
See [the pandas adapter guide](../docs/PANDAS.md) for partial results, identifiers,
|
|
112
124
|
units and exact charge totals. Pandas is optional and conversion makes no API calls.
|
|
125
|
+
|
|
126
|
+
## Model catalog and rate card
|
|
127
|
+
|
|
128
|
+
```sh
|
|
129
|
+
python examples/list_models.py
|
|
130
|
+
python examples/rate_card_quote.py
|
|
131
|
+
python examples/rate_card_quote.py --batch --execute
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
`list_models.py` calls the public `client.models.list()` without a key or charge
|
|
135
|
+
and prints each model's canonical operation ids and validity contracts.
|
|
136
|
+
`rate_card_quote.py` reads your rate card with `client.rate_card.get()` and quotes
|
|
137
|
+
the exact request it would execute with `client.rate_card.quote()`; both are
|
|
138
|
+
utility requests. `--execute` then sends one pricing request with the quoted
|
|
139
|
+
total as its `max_cu` ceiling. See [the rate card guide](../docs/RATE_CARD.md).
|
|
140
|
+
|
|
141
|
+
## Option scenarios and books
|
|
142
|
+
|
|
143
|
+
Each script uses synthetic inputs and sends one calculation when run. All request
|
|
144
|
+
construction and the complete returned result are visible; missing charges stay
|
|
145
|
+
unreported. Set `MORPHIQ_API_KEY`, then run:
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
python examples/option_revalue.py
|
|
149
|
+
python examples/option_solve.py
|
|
150
|
+
python examples/book_revalue.py
|
|
151
|
+
python examples/book_explain.py
|
|
152
|
+
python examples/book_solve.py
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
[The guide](../docs/SCENARIOS.md) explains targets, units, coverage, signed values
|
|
156
|
+
and quotation. The [local solver app](solver_app/README.md) separates Quote and
|
|
157
|
+
Solve into explicit actions with a single-use quote and retained receipts.
|
|
@@ -9,9 +9,14 @@ from getpass import getpass
|
|
|
9
9
|
|
|
10
10
|
from morphiq_sdk import (
|
|
11
11
|
APIError,
|
|
12
|
-
|
|
12
|
+
BatchFailure,
|
|
13
|
+
BatchSuccess,
|
|
14
|
+
Market,
|
|
15
|
+
ModelSelection,
|
|
13
16
|
MorphIQ,
|
|
14
|
-
|
|
17
|
+
Option,
|
|
18
|
+
OptionsBatchPriceRequest,
|
|
19
|
+
OptionsPriceRequest,
|
|
15
20
|
RateLimitError,
|
|
16
21
|
ResponseError,
|
|
17
22
|
TransportError,
|
|
@@ -23,29 +28,37 @@ def main() -> None:
|
|
|
23
28
|
api_key = os.environ.get("MORPHIQ_API_KEY") or getpass("MorphIQ API key: ")
|
|
24
29
|
|
|
25
30
|
# The order of this list defines the index used in each response outcome.
|
|
26
|
-
request =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
request = OptionsBatchPriceRequest(
|
|
32
|
+
items=[
|
|
33
|
+
OptionsPriceRequest(
|
|
34
|
+
option=Option(
|
|
35
|
+
type="call",
|
|
36
|
+
exercise_style="european",
|
|
37
|
+
strike=100.0,
|
|
38
|
+
time_to_expiry_years=1,
|
|
39
|
+
),
|
|
40
|
+
market=Market(
|
|
41
|
+
spot=100.0,
|
|
42
|
+
risk_free_rate=0.05,
|
|
43
|
+
dividend_yield=0,
|
|
44
|
+
),
|
|
37
45
|
volatility=0.2,
|
|
46
|
+
model=ModelSelection(id="auto"),
|
|
38
47
|
),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
OptionsPriceRequest(
|
|
49
|
+
option=Option(
|
|
50
|
+
type="put",
|
|
51
|
+
exercise_style="american",
|
|
52
|
+
strike=105.0,
|
|
53
|
+
time_to_expiry_years=0.5,
|
|
54
|
+
),
|
|
55
|
+
market=Market(
|
|
56
|
+
spot=100.0,
|
|
57
|
+
risk_free_rate=0.05,
|
|
58
|
+
dividend_yield=0.01,
|
|
59
|
+
),
|
|
48
60
|
volatility=0.2,
|
|
61
|
+
model=ModelSelection(id="bjerksund_stensland_1993"),
|
|
49
62
|
),
|
|
50
63
|
]
|
|
51
64
|
)
|
|
@@ -53,14 +66,14 @@ def main() -> None:
|
|
|
53
66
|
try:
|
|
54
67
|
# The client uses https://api.morphiqlabs.com and closes its connection pool here.
|
|
55
68
|
with MorphIQ(api_key=api_key) as client:
|
|
56
|
-
response = client.
|
|
69
|
+
response = client.options.batch_price(request)
|
|
57
70
|
except APIError as error:
|
|
58
71
|
if isinstance(error, RateLimitError):
|
|
59
72
|
print("Rate limited. Retry-After:", error.retry_after, file=sys.stderr)
|
|
60
73
|
print("No automatic retry or batch splitting.", file=sys.stderr)
|
|
61
|
-
print(f"HTTP {error.status_code}: {error.code}: {error.
|
|
74
|
+
print(f"HTTP {error.status_code}: {error.code}: {error.detail}", file=sys.stderr)
|
|
62
75
|
print(f"Request ID: {error.request_id}", file=sys.stderr)
|
|
63
|
-
charged = error.metadata.
|
|
76
|
+
charged = error.metadata.charged_cu if error.metadata else None
|
|
64
77
|
print(
|
|
65
78
|
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
66
79
|
file=sys.stderr,
|
|
@@ -72,7 +85,7 @@ def main() -> None:
|
|
|
72
85
|
"No complete response; execution and charges may be unknown. No retry."
|
|
73
86
|
) from None
|
|
74
87
|
except ResponseError as error:
|
|
75
|
-
charged = error.metadata.
|
|
88
|
+
charged = error.metadata.charged_cu if error.metadata else None
|
|
76
89
|
print(
|
|
77
90
|
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
78
91
|
file=sys.stderr,
|
|
@@ -82,19 +95,23 @@ def main() -> None:
|
|
|
82
95
|
) from None
|
|
83
96
|
|
|
84
97
|
for item in response.results:
|
|
85
|
-
if item
|
|
98
|
+
if isinstance(item, BatchSuccess):
|
|
86
99
|
print(
|
|
87
100
|
f"Item {item.index}: price={item.result.price}; "
|
|
88
|
-
f"model={item.result.
|
|
101
|
+
f"model={item.result.model.id} ({item.result.model.version})"
|
|
89
102
|
)
|
|
103
|
+
elif isinstance(item, BatchFailure):
|
|
104
|
+
print(f"Item {item.index}: {item.error.code}: {item.error.detail}")
|
|
90
105
|
else:
|
|
91
|
-
|
|
106
|
+
# A newer outcome status this SDK does not know; keep it unhandled.
|
|
107
|
+
print(f"Item {item.index}: unrecognized status {item.status}")
|
|
92
108
|
# One metadata block and one commercial charge cover the entire batch.
|
|
93
109
|
print(f"Request ID: {response.metadata.request_id}")
|
|
94
|
-
for engine in response.metadata.engines:
|
|
110
|
+
for engine in response.metadata.engines or []:
|
|
95
111
|
print(f"Engine: {engine.name} {engine.version} ({engine.revision})")
|
|
96
|
-
#
|
|
97
|
-
|
|
112
|
+
# The charge is metadata.billing.charged_cu; missing means unreported, not zero.
|
|
113
|
+
billing = response.metadata.billing
|
|
114
|
+
charged = billing.charged_cu if billing is not None else None
|
|
98
115
|
print("Commercial CU charged:", charged if charged is not None else "not reported")
|
|
99
116
|
|
|
100
117
|
|