morphiq-sdk 0.2.1__tar.gz → 0.3.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.
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/PKG-INFO +55 -41
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/README.md +54 -40
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/README.md +58 -13
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/batch_price.py +49 -32
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/batch_price_async.py +49 -32
- morphiq_sdk-0.3.0/examples/book_explain.py +85 -0
- morphiq_sdk-0.3.0/examples/book_revalue.py +85 -0
- morphiq_sdk-0.3.0/examples/book_solve.py +81 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/chunked_price.py +37 -20
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/chunked_price_async.py +39 -20
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/greeks.py +31 -17
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/greeks_async.py +31 -17
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/identify_regime.py +65 -40
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/identify_regime_async.py +65 -40
- morphiq_sdk-0.2.1/examples/analytics.py → morphiq_sdk-0.3.0/examples/implied_greeks.py +33 -20
- morphiq_sdk-0.2.1/examples/analytics_async.py → morphiq_sdk-0.3.0/examples/implied_greeks_async.py +27 -20
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/implied_volatility.py +31 -17
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/implied_volatility_async.py +25 -17
- morphiq_sdk-0.2.1/examples/pricing_models.py → morphiq_sdk-0.3.0/examples/list_models.py +7 -3
- morphiq_sdk-0.3.0/examples/option_revalue.py +48 -0
- morphiq_sdk-0.3.0/examples/option_solve.py +50 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/price_american.py +31 -17
- morphiq_sdk-0.3.0/examples/price_async.py +97 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/price_european.py +31 -17
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/provider_regime.py +6 -5
- morphiq_sdk-0.3.0/examples/quickstart.py +96 -0
- morphiq_sdk-0.3.0/examples/rate_card_quote.py +105 -0
- morphiq_sdk-0.3.0/examples/solver_app/README.md +29 -0
- morphiq_sdk-0.3.0/examples/solver_app/app.js +121 -0
- morphiq_sdk-0.3.0/examples/solver_app/app.py +215 -0
- morphiq_sdk-0.3.0/examples/solver_app/index.html +72 -0
- morphiq_sdk-0.3.0/examples/solver_app/style.css +2 -0
- morphiq_sdk-0.2.1/examples/greeks_standard.py → morphiq_sdk-0.3.0/examples/standard_greeks.py +32 -18
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/tabular_price.py +27 -14
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/notebooks/README.md +17 -4
- morphiq_sdk-0.3.0/notebooks/books/explain.ipynb +31 -0
- morphiq_sdk-0.3.0/notebooks/books/revalue.ipynb +31 -0
- morphiq_sdk-0.3.0/notebooks/books/solve.ipynb +31 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/notebooks/cost/quotation.ipynb +36 -20
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/notebooks/pricing/models.ipynb +17 -5
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/notebooks/pricing/options.ipynb +182 -86
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/notebooks/pricing/standard-five.ipynb +41 -14
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/notebooks/regime/identification.ipynb +110 -55
- morphiq_sdk-0.3.0/notebooks/scenarios/revalue.ipynb +31 -0
- morphiq_sdk-0.3.0/notebooks/scenarios/solve.ipynb +31 -0
- morphiq_sdk-0.3.0/notebooks/start-here.ipynb +23 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/pyproject.toml +1 -1
- morphiq_sdk-0.3.0/src/morphiq_sdk/__init__.py +346 -0
- morphiq_sdk-0.3.0/src/morphiq_sdk/client.py +1021 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/src/morphiq_sdk/errors.py +16 -14
- morphiq_sdk-0.3.0/src/morphiq_sdk/models.py +1619 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/src/morphiq_sdk/pandas.py +23 -33
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/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.0}/.gitignore +0 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/LICENSE +0 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/examples/__init__.py +0 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/src/morphiq_sdk/market_data.py +0 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/src/morphiq_sdk/py.typed +0 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/src/morphiq_sdk_yahoo/__init__.py +0 -0
- {morphiq_sdk-0.2.1 → morphiq_sdk-0.3.0}/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.0
|
|
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
|
|
@@ -40,18 +40,21 @@ Price European and American options, calculate standard-five or all-ten Greeks,
|
|
|
40
40
|
volatility, and identify market regimes from price histories.
|
|
41
41
|
|
|
42
42
|
`morphiq-sdk` is a typed Python client for the MorphIQ API, with synchronous and
|
|
43
|
-
asynchronous calls. Pricing, Greeks, implied volatility and
|
|
43
|
+
asynchronous calls. Pricing, Greeks, implied volatility and implied Greeks
|
|
44
44
|
support ordered batches. Runnable examples and interactive notebooks cover option
|
|
45
45
|
valuation, sensitivity analysis and market-regime identification.
|
|
46
46
|
|
|
47
47
|
See the [documentation index](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/README.md) for all feature guides and the
|
|
48
48
|
[Python API reference](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/API.md) for methods, models and errors.
|
|
49
49
|
|
|
50
|
-
This client targets API **
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
This client targets the MorphIQ API **0.10.0** contract (**API v1 · Beta**,
|
|
51
|
+
contract label `0.1.0`): `collection:verb` routes, `option` / `market` / `model`
|
|
52
|
+
requests, grouped response metadata and RFC 9457 problem errors. Methods are
|
|
53
|
+
grouped by collection and spell each operation's canonical id, for example
|
|
54
|
+
`client.options.price(...)` for `options.price`. SDK 0.2.1 on PyPI targets the
|
|
55
|
+
earlier contract; this client is unreleased until the next SDK release. See the
|
|
56
|
+
[0.10.0 migration guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/API_0_10_ADOPTION.md)
|
|
57
|
+
and [model capabilities](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/MODELS.md): BSM/BS1993 support batches
|
|
55
58
|
up to 100; QdFp and cash-dividend finite difference support single price and IV.
|
|
56
59
|
|
|
57
60
|
## Quickstart
|
|
@@ -84,21 +87,16 @@ Save the following as `price_option.py`. It prices a European call with spot and
|
|
|
84
87
|
strike of 100, one year to expiry, 20% volatility, and a 5% interest rate:
|
|
85
88
|
|
|
86
89
|
```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,
|
|
90
|
+
from morphiq_sdk import Market, MorphIQ, Option, OptionsPriceRequest
|
|
91
|
+
|
|
92
|
+
request = OptionsPriceRequest(
|
|
93
|
+
option=Option(type="call", exercise_style="european", strike=100.0, time_to_expiry_years=1.0),
|
|
94
|
+
market=Market(spot=100.0, risk_free_rate=0.05, dividend_yield=0.0),
|
|
97
95
|
volatility=0.20,
|
|
98
96
|
)
|
|
99
97
|
|
|
100
98
|
with MorphIQ() as client:
|
|
101
|
-
response = client.price(request)
|
|
99
|
+
response = client.options.price(request)
|
|
102
100
|
print(response.model_dump_json(indent=2, exclude_unset=True))
|
|
103
101
|
```
|
|
104
102
|
|
|
@@ -108,39 +106,56 @@ Run it in the same terminal where you set your API key:
|
|
|
108
106
|
python price_option.py
|
|
109
107
|
```
|
|
110
108
|
|
|
111
|
-
This sends one authenticated `POST https://api.morphiqlabs.com/v1/price`
|
|
112
|
-
and prints the JSON response. Example
|
|
109
|
+
This sends one authenticated `POST https://api.morphiqlabs.com/v1/options:price`
|
|
110
|
+
request with `model: {"id": "auto"}` and prints the JSON response. Example
|
|
111
|
+
response from the recorded synthetic fixture:
|
|
113
112
|
|
|
114
113
|
```json
|
|
115
114
|
{
|
|
116
115
|
"metadata": {
|
|
117
|
-
"request_id": "fr-
|
|
118
|
-
"
|
|
119
|
-
"
|
|
116
|
+
"request_id": "fr-18eb4d3a08c36fa2-0000000000000002",
|
|
117
|
+
"service_version": "0.10.0",
|
|
118
|
+
"contract": {
|
|
119
|
+
"version": "0.1.0",
|
|
120
|
+
"sha256": "68985d43f276fe525f46fbc9dc650a172f1303298bcc831da59f8cfee2dbb4c8"
|
|
121
|
+
},
|
|
120
122
|
"engines": [
|
|
121
123
|
{
|
|
122
124
|
"name": "morphiq-risk",
|
|
123
|
-
"version": "0.
|
|
124
|
-
"revision": "
|
|
125
|
+
"version": "0.46.1",
|
|
126
|
+
"revision": "1550e4e41b243b8a978677bc5e9b46916c08cb0e"
|
|
125
127
|
}
|
|
126
128
|
]
|
|
127
129
|
},
|
|
128
130
|
"result": {
|
|
129
|
-
"price": 10.
|
|
130
|
-
"
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
"price": 10.450583572185577,
|
|
132
|
+
"model": {
|
|
133
|
+
"id": "black_scholes_merton",
|
|
134
|
+
"version": "black_scholes_merton/1"
|
|
135
|
+
}
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
138
|
```
|
|
137
139
|
|
|
138
140
|
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.
|
|
141
|
+
was recorded in open development mode; authenticated responses also report
|
|
142
|
+
commercial charges in `metadata.billing.charged_cu`, the plan in
|
|
143
|
+
`metadata.policy` and the budget estimate in `metadata.budget`. Keep the request
|
|
144
|
+
ID for support.
|
|
141
145
|
See [the quickstart guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/QUICKSTART.md)
|
|
142
146
|
for input units, async usage, configuration and errors.
|
|
143
147
|
|
|
148
|
+
## Scenarios and books
|
|
149
|
+
|
|
150
|
+
The SDK supports `client.options.revalue` and `client.options.solve_scenario`,
|
|
151
|
+
plus `client.books.revalue`, `client.books.explain` and `client.books.solve_scenario`.
|
|
152
|
+
The async client exposes the same methods. All five support cost quotation and a
|
|
153
|
+
per-request CU ceiling. Results preserve partial failures, solver uncertainty,
|
|
154
|
+
signed positions, strategy membership and expiry/strike P&L attribution.
|
|
155
|
+
|
|
156
|
+
See the [scenario and book guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/SCENARIOS.md)
|
|
157
|
+
and the standalone notebooks in `notebooks/scenarios/` and `notebooks/books/`.
|
|
158
|
+
|
|
144
159
|
## Repository examples and notebooks
|
|
145
160
|
|
|
146
161
|
The executable examples and Docker notebooks live in the repository. Clone it
|
|
@@ -183,7 +198,7 @@ Choose an analysis workspace and run all cells once to display its controls:
|
|
|
183
198
|
- [Option pricing](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/notebooks/pricing/options.ipynb): European/American and model
|
|
184
199
|
dropdowns, call/put selection, editable assumptions, automatic Yahoo daily/intraday underlying prices,
|
|
185
200
|
a valuation comparison table, a price-and-Greeks panel, an implied-volatility solver,
|
|
186
|
-
|
|
201
|
+
implied-Greeks premium analysis, a session CU total and a spot-sensitivity chart.
|
|
187
202
|
- [Regime analysis](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/notebooks/regime/identification.ipynb): ticker selection,
|
|
188
203
|
Yahoo daily/intraday price history, latest regime assessment, score charts and provenance.
|
|
189
204
|
|
|
@@ -223,12 +238,11 @@ no real credentials; native API integration is opt-in. See
|
|
|
223
238
|
[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
239
|
|
|
225
240
|
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.
|
|
241
|
+
may leave work charged. Only `metadata.billing.quoted_cu` and
|
|
242
|
+
`metadata.billing.charged_cu` report commercial CUs. A missing `charged_cu` means
|
|
243
|
+
unreported, not zero. Optional members are omitted by the API, never sent as
|
|
244
|
+
null. Response enums may gain values: the SDK keeps an unknown value as a plain
|
|
245
|
+
string and an unknown variant as an `Unrecognized` model instead of failing.
|
|
232
246
|
|
|
233
247
|
The SDK preserves server results, numerical diagnostics, request IDs, engine
|
|
234
248
|
provenance and commercial Compute Units (CU). Numerical engines, model selection,
|
|
@@ -240,7 +254,7 @@ pricing engines or calculate authoritative customer charges.
|
|
|
240
254
|
```text
|
|
241
255
|
src/morphiq_sdk/ Installable, typed Python package
|
|
242
256
|
scripts/ Development and package verification
|
|
243
|
-
examples/ Runnable pricing, Greeks, IV,
|
|
257
|
+
examples/ Runnable pricing, Greeks, IV, implied-Greeks, batch and regime examples
|
|
244
258
|
notebooks/ Quickstart and standalone feature notebooks
|
|
245
259
|
contracts/ Reviewed OpenAPI snapshot, digest and source provenance
|
|
246
260
|
docker/ Non-root notebook startup and workspace seeding
|
|
@@ -253,4 +267,4 @@ docs/ Usage guides and contract documentation
|
|
|
253
267
|
The SDK, examples and notebooks are licensed under the
|
|
254
268
|
[MIT License](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/LICENSE).
|
|
255
269
|
|
|
256
|
-
See [
|
|
270
|
+
See [the rate card and request quotes](docs/RATE_CARD.md) for zero-CU discovery, conditional quotes, and the optional `max_cu` execution ceiling.
|
|
@@ -4,18 +4,21 @@ Price European and American options, calculate standard-five or all-ten Greeks,
|
|
|
4
4
|
volatility, and identify market regimes from price histories.
|
|
5
5
|
|
|
6
6
|
`morphiq-sdk` is a typed Python client for the MorphIQ API, with synchronous and
|
|
7
|
-
asynchronous calls. Pricing, Greeks, implied volatility and
|
|
7
|
+
asynchronous calls. Pricing, Greeks, implied volatility and implied Greeks
|
|
8
8
|
support ordered batches. Runnable examples and interactive notebooks cover option
|
|
9
9
|
valuation, sensitivity analysis and market-regime identification.
|
|
10
10
|
|
|
11
11
|
See the [documentation index](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/README.md) for all feature guides and the
|
|
12
12
|
[Python API reference](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/API.md) for methods, models and errors.
|
|
13
13
|
|
|
14
|
-
This client targets API **
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
This client targets the MorphIQ API **0.10.0** contract (**API v1 · Beta**,
|
|
15
|
+
contract label `0.1.0`): `collection:verb` routes, `option` / `market` / `model`
|
|
16
|
+
requests, grouped response metadata and RFC 9457 problem errors. Methods are
|
|
17
|
+
grouped by collection and spell each operation's canonical id, for example
|
|
18
|
+
`client.options.price(...)` for `options.price`. SDK 0.2.1 on PyPI targets the
|
|
19
|
+
earlier contract; this client is unreleased until the next SDK release. See the
|
|
20
|
+
[0.10.0 migration guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/API_0_10_ADOPTION.md)
|
|
21
|
+
and [model capabilities](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/MODELS.md): BSM/BS1993 support batches
|
|
19
22
|
up to 100; QdFp and cash-dividend finite difference support single price and IV.
|
|
20
23
|
|
|
21
24
|
## Quickstart
|
|
@@ -48,21 +51,16 @@ Save the following as `price_option.py`. It prices a European call with spot and
|
|
|
48
51
|
strike of 100, one year to expiry, 20% volatility, and a 5% interest rate:
|
|
49
52
|
|
|
50
53
|
```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,
|
|
54
|
+
from morphiq_sdk import Market, MorphIQ, Option, OptionsPriceRequest
|
|
55
|
+
|
|
56
|
+
request = OptionsPriceRequest(
|
|
57
|
+
option=Option(type="call", exercise_style="european", strike=100.0, time_to_expiry_years=1.0),
|
|
58
|
+
market=Market(spot=100.0, risk_free_rate=0.05, dividend_yield=0.0),
|
|
61
59
|
volatility=0.20,
|
|
62
60
|
)
|
|
63
61
|
|
|
64
62
|
with MorphIQ() as client:
|
|
65
|
-
response = client.price(request)
|
|
63
|
+
response = client.options.price(request)
|
|
66
64
|
print(response.model_dump_json(indent=2, exclude_unset=True))
|
|
67
65
|
```
|
|
68
66
|
|
|
@@ -72,39 +70,56 @@ Run it in the same terminal where you set your API key:
|
|
|
72
70
|
python price_option.py
|
|
73
71
|
```
|
|
74
72
|
|
|
75
|
-
This sends one authenticated `POST https://api.morphiqlabs.com/v1/price`
|
|
76
|
-
and prints the JSON response. Example
|
|
73
|
+
This sends one authenticated `POST https://api.morphiqlabs.com/v1/options:price`
|
|
74
|
+
request with `model: {"id": "auto"}` and prints the JSON response. Example
|
|
75
|
+
response from the recorded synthetic fixture:
|
|
77
76
|
|
|
78
77
|
```json
|
|
79
78
|
{
|
|
80
79
|
"metadata": {
|
|
81
|
-
"request_id": "fr-
|
|
82
|
-
"
|
|
83
|
-
"
|
|
80
|
+
"request_id": "fr-18eb4d3a08c36fa2-0000000000000002",
|
|
81
|
+
"service_version": "0.10.0",
|
|
82
|
+
"contract": {
|
|
83
|
+
"version": "0.1.0",
|
|
84
|
+
"sha256": "68985d43f276fe525f46fbc9dc650a172f1303298bcc831da59f8cfee2dbb4c8"
|
|
85
|
+
},
|
|
84
86
|
"engines": [
|
|
85
87
|
{
|
|
86
88
|
"name": "morphiq-risk",
|
|
87
|
-
"version": "0.
|
|
88
|
-
"revision": "
|
|
89
|
+
"version": "0.46.1",
|
|
90
|
+
"revision": "1550e4e41b243b8a978677bc5e9b46916c08cb0e"
|
|
89
91
|
}
|
|
90
92
|
]
|
|
91
93
|
},
|
|
92
94
|
"result": {
|
|
93
|
-
"price": 10.
|
|
94
|
-
"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
"price": 10.450583572185577,
|
|
96
|
+
"model": {
|
|
97
|
+
"id": "black_scholes_merton",
|
|
98
|
+
"version": "black_scholes_merton/1"
|
|
99
|
+
}
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
102
|
```
|
|
101
103
|
|
|
102
104
|
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.
|
|
105
|
+
was recorded in open development mode; authenticated responses also report
|
|
106
|
+
commercial charges in `metadata.billing.charged_cu`, the plan in
|
|
107
|
+
`metadata.policy` and the budget estimate in `metadata.budget`. Keep the request
|
|
108
|
+
ID for support.
|
|
105
109
|
See [the quickstart guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/QUICKSTART.md)
|
|
106
110
|
for input units, async usage, configuration and errors.
|
|
107
111
|
|
|
112
|
+
## Scenarios and books
|
|
113
|
+
|
|
114
|
+
The SDK supports `client.options.revalue` and `client.options.solve_scenario`,
|
|
115
|
+
plus `client.books.revalue`, `client.books.explain` and `client.books.solve_scenario`.
|
|
116
|
+
The async client exposes the same methods. All five support cost quotation and a
|
|
117
|
+
per-request CU ceiling. Results preserve partial failures, solver uncertainty,
|
|
118
|
+
signed positions, strategy membership and expiry/strike P&L attribution.
|
|
119
|
+
|
|
120
|
+
See the [scenario and book guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/SCENARIOS.md)
|
|
121
|
+
and the standalone notebooks in `notebooks/scenarios/` and `notebooks/books/`.
|
|
122
|
+
|
|
108
123
|
## Repository examples and notebooks
|
|
109
124
|
|
|
110
125
|
The executable examples and Docker notebooks live in the repository. Clone it
|
|
@@ -147,7 +162,7 @@ Choose an analysis workspace and run all cells once to display its controls:
|
|
|
147
162
|
- [Option pricing](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/notebooks/pricing/options.ipynb): European/American and model
|
|
148
163
|
dropdowns, call/put selection, editable assumptions, automatic Yahoo daily/intraday underlying prices,
|
|
149
164
|
a valuation comparison table, a price-and-Greeks panel, an implied-volatility solver,
|
|
150
|
-
|
|
165
|
+
implied-Greeks premium analysis, a session CU total and a spot-sensitivity chart.
|
|
151
166
|
- [Regime analysis](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/notebooks/regime/identification.ipynb): ticker selection,
|
|
152
167
|
Yahoo daily/intraday price history, latest regime assessment, score charts and provenance.
|
|
153
168
|
|
|
@@ -187,12 +202,11 @@ no real credentials; native API integration is opt-in. See
|
|
|
187
202
|
[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
203
|
|
|
189
204
|
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.
|
|
205
|
+
may leave work charged. Only `metadata.billing.quoted_cu` and
|
|
206
|
+
`metadata.billing.charged_cu` report commercial CUs. A missing `charged_cu` means
|
|
207
|
+
unreported, not zero. Optional members are omitted by the API, never sent as
|
|
208
|
+
null. Response enums may gain values: the SDK keeps an unknown value as a plain
|
|
209
|
+
string and an unknown variant as an `Unrecognized` model instead of failing.
|
|
196
210
|
|
|
197
211
|
The SDK preserves server results, numerical diagnostics, request IDs, engine
|
|
198
212
|
provenance and commercial Compute Units (CU). Numerical engines, model selection,
|
|
@@ -204,7 +218,7 @@ pricing engines or calculate authoritative customer charges.
|
|
|
204
218
|
```text
|
|
205
219
|
src/morphiq_sdk/ Installable, typed Python package
|
|
206
220
|
scripts/ Development and package verification
|
|
207
|
-
examples/ Runnable pricing, Greeks, IV,
|
|
221
|
+
examples/ Runnable pricing, Greeks, IV, implied-Greeks, batch and regime examples
|
|
208
222
|
notebooks/ Quickstart and standalone feature notebooks
|
|
209
223
|
contracts/ Reviewed OpenAPI snapshot, digest and source provenance
|
|
210
224
|
docker/ Non-root notebook startup and workspace seeding
|
|
@@ -217,4 +231,4 @@ docs/ Usage guides and contract documentation
|
|
|
217
231
|
The SDK, examples and notebooks are licensed under the
|
|
218
232
|
[MIT License](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/LICENSE).
|
|
219
233
|
|
|
220
|
-
See [
|
|
234
|
+
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
|
+
Every request is 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
|
|