morphiq-sdk 0.1.1__tar.gz → 0.2.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.1.1 → morphiq_sdk-0.2.1}/PKG-INFO +30 -19
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/README.md +29 -18
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/analytics.py +6 -4
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/analytics_async.py +6 -4
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/batch_price.py +4 -4
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/batch_price_async.py +4 -4
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/chunked_price.py +3 -3
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/chunked_price_async.py +3 -3
- morphiq_sdk-0.2.1/examples/cost_quote.py +77 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/greeks.py +5 -3
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/greeks_async.py +5 -3
- morphiq_sdk-0.2.1/examples/greeks_standard.py +76 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/identify_regime.py +18 -2
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/identify_regime_async.py +18 -2
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/implied_volatility.py +2 -2
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/implied_volatility_async.py +2 -2
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/price_american.py +2 -2
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/price_async.py +2 -2
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/price_european.py +2 -2
- morphiq_sdk-0.2.1/examples/pricing_models.py +17 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/quickstart.py +2 -2
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/tabular_price.py +3 -3
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/notebooks/README.md +3 -0
- morphiq_sdk-0.2.1/notebooks/cost/quotation.ipynb +167 -0
- morphiq_sdk-0.2.1/notebooks/pricing/models.ipynb +72 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/notebooks/pricing/options.ipynb +39 -77
- morphiq_sdk-0.2.1/notebooks/pricing/standard-five.ipynb +120 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/notebooks/regime/identification.ipynb +29 -2
- morphiq_sdk-0.2.1/notebooks/start-here.ipynb +23 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/pyproject.toml +1 -1
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/src/morphiq_sdk/__init__.py +34 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/src/morphiq_sdk/client.py +300 -55
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/src/morphiq_sdk/models.py +329 -26
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/src/morphiq_sdk/pandas.py +23 -11
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/src/morphiq_sdk/workflows.py +22 -7
- morphiq_sdk-0.1.1/notebooks/start-here.ipynb +0 -23
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/.gitignore +0 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/LICENSE +0 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/README.md +0 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/__init__.py +0 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/examples/provider_regime.py +0 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/src/morphiq_sdk/errors.py +0 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/src/morphiq_sdk/market_data.py +0 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/src/morphiq_sdk/py.typed +0 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.1}/src/morphiq_sdk_yahoo/__init__.py +0 -0
- {morphiq_sdk-0.1.1 → morphiq_sdk-0.2.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.2.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
|
|
@@ -36,7 +36,7 @@ Description-Content-Type: text/markdown
|
|
|
36
36
|
|
|
37
37
|
# Option pricing, Greeks, volatility and market regimes in Python
|
|
38
38
|
|
|
39
|
-
Price European and American options, calculate ten Greeks, solve implied
|
|
39
|
+
Price European and American options, calculate standard-five or all-ten Greeks, solve implied
|
|
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
|
|
@@ -47,6 +47,13 @@ valuation, sensitivity analysis and market-regime identification.
|
|
|
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 **v0.7.0**, including public model discovery,
|
|
51
|
+
standard-five Greeks, cost utilities and spend caps, preferred CU fields, and
|
|
52
|
+
typed regime crisis/volatility results. SDK 0.2.0 covers the routes but predates
|
|
53
|
+
the typed CU and regime additions; install the release containing this update.
|
|
54
|
+
See [model capabilities and migration](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/MODELS.md): BSM/BS1993 support batches
|
|
55
|
+
up to 100; QdFp and cash-dividend finite difference support single price and IV.
|
|
56
|
+
|
|
50
57
|
## Quickstart
|
|
51
58
|
|
|
52
59
|
### 1. Get API access
|
|
@@ -106,33 +113,31 @@ and prints the JSON response. Example response from the recorded synthetic fixtu
|
|
|
106
113
|
|
|
107
114
|
```json
|
|
108
115
|
{
|
|
109
|
-
"result": {
|
|
110
|
-
"price": 10.450583572185538,
|
|
111
|
-
"exercise_style": "european",
|
|
112
|
-
"option_type": "call",
|
|
113
|
-
"pricing_model": "black_scholes_merton",
|
|
114
|
-
"model_version": "black_scholes_merton/1"
|
|
115
|
-
},
|
|
116
116
|
"metadata": {
|
|
117
|
-
"request_id": "
|
|
117
|
+
"request_id": "fr-18e88a7b3977d162-0000000000000002",
|
|
118
118
|
"api_version": "v1",
|
|
119
|
-
"engine_version": "0.
|
|
119
|
+
"engine_version": "0.45.0",
|
|
120
120
|
"engines": [
|
|
121
121
|
{
|
|
122
122
|
"name": "morphiq-risk",
|
|
123
|
-
"version": "0.
|
|
124
|
-
"revision": "
|
|
123
|
+
"version": "0.45.0",
|
|
124
|
+
"revision": "a4df4da57ff2d53a1f1146f1c4310f0e980a497a"
|
|
125
125
|
}
|
|
126
|
-
]
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
"result": {
|
|
129
|
+
"price": 10.450583572185565,
|
|
130
|
+
"exercise_style": "european",
|
|
131
|
+
"option_type": "call",
|
|
132
|
+
"pricing_model": "black_scholes_merton",
|
|
133
|
+
"model_version": "black_scholes_merton/1"
|
|
129
134
|
}
|
|
130
135
|
}
|
|
131
136
|
```
|
|
132
137
|
|
|
133
138
|
Your request ID and engine metadata will reflect the live service. This fixture
|
|
134
139
|
was recorded in open development mode; authenticated responses may also report
|
|
135
|
-
commercial charges in `metadata.
|
|
140
|
+
commercial charges in `metadata.cu_charged`. Keep the request ID for support.
|
|
136
141
|
See [the quickstart guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/QUICKSTART.md)
|
|
137
142
|
for input units, async usage, configuration and errors.
|
|
138
143
|
|
|
@@ -218,8 +223,12 @@ no real credentials; native API integration is opt-in. See
|
|
|
218
223
|
[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).
|
|
219
224
|
|
|
220
225
|
Clients make no automatic retries and do not follow redirects. A timeout
|
|
221
|
-
may leave work charged.
|
|
222
|
-
`
|
|
226
|
+
may leave work charged. Only `cu_quoted` and `cu_charged` report commercial CUs.
|
|
227
|
+
Missing `cu_charged` means unreported, not zero. The `fcu_*` names are deprecated
|
|
228
|
+
aliases with equal values; the SDK fills each name from the other, so older servers
|
|
229
|
+
that send only `fcu_*` still work. Explicit nulls remain unreported. The retired `units_charged` and
|
|
230
|
+
`compute_schedule_version` fields are optional; they remain accepted from older
|
|
231
|
+
deployments and are never used to calculate a charge.
|
|
223
232
|
|
|
224
233
|
The SDK preserves server results, numerical diagnostics, request IDs, engine
|
|
225
234
|
provenance and commercial Compute Units (CU). Numerical engines, model selection,
|
|
@@ -243,3 +252,5 @@ docs/ Usage guides and contract documentation
|
|
|
243
252
|
|
|
244
253
|
The SDK, examples and notebooks are licensed under the
|
|
245
254
|
[MIT License](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/LICENSE).
|
|
255
|
+
|
|
256
|
+
See [cost schedules and request quotes](docs/COST.md) for zero-CU discovery, conditional quotes, and the optional `max_cu` execution ceiling.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Option pricing, Greeks, volatility and market regimes in Python
|
|
2
2
|
|
|
3
|
-
Price European and American options, calculate ten Greeks, solve implied
|
|
3
|
+
Price European and American options, calculate standard-five or all-ten Greeks, solve implied
|
|
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
|
|
@@ -11,6 +11,13 @@ valuation, sensitivity analysis and market-regime identification.
|
|
|
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 **v0.7.0**, including public model discovery,
|
|
15
|
+
standard-five Greeks, cost utilities and spend caps, preferred CU fields, and
|
|
16
|
+
typed regime crisis/volatility results. SDK 0.2.0 covers the routes but predates
|
|
17
|
+
the typed CU and regime additions; install the release containing this update.
|
|
18
|
+
See [model capabilities and migration](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/MODELS.md): BSM/BS1993 support batches
|
|
19
|
+
up to 100; QdFp and cash-dividend finite difference support single price and IV.
|
|
20
|
+
|
|
14
21
|
## Quickstart
|
|
15
22
|
|
|
16
23
|
### 1. Get API access
|
|
@@ -70,33 +77,31 @@ and prints the JSON response. Example response from the recorded synthetic fixtu
|
|
|
70
77
|
|
|
71
78
|
```json
|
|
72
79
|
{
|
|
73
|
-
"result": {
|
|
74
|
-
"price": 10.450583572185538,
|
|
75
|
-
"exercise_style": "european",
|
|
76
|
-
"option_type": "call",
|
|
77
|
-
"pricing_model": "black_scholes_merton",
|
|
78
|
-
"model_version": "black_scholes_merton/1"
|
|
79
|
-
},
|
|
80
80
|
"metadata": {
|
|
81
|
-
"request_id": "
|
|
81
|
+
"request_id": "fr-18e88a7b3977d162-0000000000000002",
|
|
82
82
|
"api_version": "v1",
|
|
83
|
-
"engine_version": "0.
|
|
83
|
+
"engine_version": "0.45.0",
|
|
84
84
|
"engines": [
|
|
85
85
|
{
|
|
86
86
|
"name": "morphiq-risk",
|
|
87
|
-
"version": "0.
|
|
88
|
-
"revision": "
|
|
87
|
+
"version": "0.45.0",
|
|
88
|
+
"revision": "a4df4da57ff2d53a1f1146f1c4310f0e980a497a"
|
|
89
89
|
}
|
|
90
|
-
]
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
"result": {
|
|
93
|
+
"price": 10.450583572185565,
|
|
94
|
+
"exercise_style": "european",
|
|
95
|
+
"option_type": "call",
|
|
96
|
+
"pricing_model": "black_scholes_merton",
|
|
97
|
+
"model_version": "black_scholes_merton/1"
|
|
93
98
|
}
|
|
94
99
|
}
|
|
95
100
|
```
|
|
96
101
|
|
|
97
102
|
Your request ID and engine metadata will reflect the live service. This fixture
|
|
98
103
|
was recorded in open development mode; authenticated responses may also report
|
|
99
|
-
commercial charges in `metadata.
|
|
104
|
+
commercial charges in `metadata.cu_charged`. Keep the request ID for support.
|
|
100
105
|
See [the quickstart guide](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/docs/QUICKSTART.md)
|
|
101
106
|
for input units, async usage, configuration and errors.
|
|
102
107
|
|
|
@@ -182,8 +187,12 @@ no real credentials; native API integration is opt-in. See
|
|
|
182
187
|
[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).
|
|
183
188
|
|
|
184
189
|
Clients make no automatic retries and do not follow redirects. A timeout
|
|
185
|
-
may leave work charged.
|
|
186
|
-
`
|
|
190
|
+
may leave work charged. Only `cu_quoted` and `cu_charged` report commercial CUs.
|
|
191
|
+
Missing `cu_charged` means unreported, not zero. The `fcu_*` names are deprecated
|
|
192
|
+
aliases with equal values; the SDK fills each name from the other, so older servers
|
|
193
|
+
that send only `fcu_*` still work. Explicit nulls remain unreported. The retired `units_charged` and
|
|
194
|
+
`compute_schedule_version` fields are optional; they remain accepted from older
|
|
195
|
+
deployments and are never used to calculate a charge.
|
|
187
196
|
|
|
188
197
|
The SDK preserves server results, numerical diagnostics, request IDs, engine
|
|
189
198
|
provenance and commercial Compute Units (CU). Numerical engines, model selection,
|
|
@@ -207,3 +216,5 @@ docs/ Usage guides and contract documentation
|
|
|
207
216
|
|
|
208
217
|
The SDK, examples and notebooks are licensed under the
|
|
209
218
|
[MIT License](https://github.com/MorphIQ-Labs/morphiq-sdk-python/blob/main/LICENSE).
|
|
219
|
+
|
|
220
|
+
See [cost schedules and request quotes](docs/COST.md) for zero-CU discovery, conditional quotes, and the optional `max_cu` execution ceiling.
|
|
@@ -35,7 +35,7 @@ def main() -> None:
|
|
|
35
35
|
except APIError as error:
|
|
36
36
|
print(f"HTTP {error.status_code}: {error.code}: {error.message}", file=sys.stderr)
|
|
37
37
|
print(f"Request ID: {error.request_id}", file=sys.stderr)
|
|
38
|
-
charged = error.metadata.
|
|
38
|
+
charged = error.metadata.cu_charged if error.metadata else None
|
|
39
39
|
print(
|
|
40
40
|
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
41
41
|
file=sys.stderr,
|
|
@@ -47,7 +47,7 @@ def main() -> None:
|
|
|
47
47
|
"No complete response; execution and charges may be unknown. No retry."
|
|
48
48
|
) from None
|
|
49
49
|
except ResponseError as error:
|
|
50
|
-
charged = error.metadata.
|
|
50
|
+
charged = error.metadata.cu_charged if error.metadata else None
|
|
51
51
|
print(
|
|
52
52
|
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
53
53
|
file=sys.stderr,
|
|
@@ -75,14 +75,16 @@ def main() -> None:
|
|
|
75
75
|
"veta",
|
|
76
76
|
"color",
|
|
77
77
|
):
|
|
78
|
-
|
|
78
|
+
value = getattr(response.result.greeks, name)
|
|
79
|
+
reason = response.result.greeks.unavailable.get(name)
|
|
80
|
+
print(f" {name}: {value if value is not None else reason}")
|
|
79
81
|
# The combined response reports one charge, not one charge per result component.
|
|
80
82
|
print(f"Model: {response.result.pricing_model} ({response.result.model_version})")
|
|
81
83
|
print(f"Request ID: {response.metadata.request_id}")
|
|
82
84
|
for engine in response.metadata.engines:
|
|
83
85
|
print(f"Engine: {engine.name} {engine.version} ({engine.revision})")
|
|
84
86
|
# Missing commercial CU is unreported, not zero.
|
|
85
|
-
charged = response.metadata.
|
|
87
|
+
charged = response.metadata.cu_charged
|
|
86
88
|
print("Commercial CU charged:", charged if charged is not None else "not reported")
|
|
87
89
|
|
|
88
90
|
|
|
@@ -42,7 +42,7 @@ async def main() -> None:
|
|
|
42
42
|
except APIError as error:
|
|
43
43
|
print(f"HTTP {error.status_code}: {error.code}: {error.message}", file=sys.stderr)
|
|
44
44
|
print(f"Request ID: {error.request_id}", file=sys.stderr)
|
|
45
|
-
charged = error.metadata.
|
|
45
|
+
charged = error.metadata.cu_charged if error.metadata else None
|
|
46
46
|
print(
|
|
47
47
|
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
48
48
|
file=sys.stderr,
|
|
@@ -54,7 +54,7 @@ async def main() -> None:
|
|
|
54
54
|
"No complete response; execution and charges may be unknown. No retry."
|
|
55
55
|
) from None
|
|
56
56
|
except ResponseError as error:
|
|
57
|
-
charged = error.metadata.
|
|
57
|
+
charged = error.metadata.cu_charged if error.metadata else None
|
|
58
58
|
print(
|
|
59
59
|
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
60
60
|
file=sys.stderr,
|
|
@@ -82,14 +82,16 @@ async def main() -> None:
|
|
|
82
82
|
"veta",
|
|
83
83
|
"color",
|
|
84
84
|
):
|
|
85
|
-
|
|
85
|
+
value = getattr(response.result.greeks, name)
|
|
86
|
+
reason = response.result.greeks.unavailable.get(name)
|
|
87
|
+
print(f" {name}: {value if value is not None else reason}")
|
|
86
88
|
# The combined response reports one charge, not one charge per result component.
|
|
87
89
|
print(f"Model: {response.result.pricing_model} ({response.result.model_version})")
|
|
88
90
|
print(f"Request ID: {response.metadata.request_id}")
|
|
89
91
|
for engine in response.metadata.engines:
|
|
90
92
|
print(f"Engine: {engine.name} {engine.version} ({engine.revision})")
|
|
91
93
|
# Missing commercial CU is unreported, not zero.
|
|
92
|
-
charged = response.metadata.
|
|
94
|
+
charged = response.metadata.cu_charged
|
|
93
95
|
print("Commercial CU charged:", charged if charged is not None else "not reported")
|
|
94
96
|
|
|
95
97
|
|
|
@@ -38,7 +38,7 @@ def main() -> None:
|
|
|
38
38
|
),
|
|
39
39
|
PriceRequest(
|
|
40
40
|
exercise_style="american",
|
|
41
|
-
pricing_model="
|
|
41
|
+
pricing_model="bjerksund_stensland_1993",
|
|
42
42
|
option_type="put",
|
|
43
43
|
spot=100.0,
|
|
44
44
|
strike=105.0,
|
|
@@ -60,7 +60,7 @@ def main() -> None:
|
|
|
60
60
|
print("No automatic retry or batch splitting.", file=sys.stderr)
|
|
61
61
|
print(f"HTTP {error.status_code}: {error.code}: {error.message}", file=sys.stderr)
|
|
62
62
|
print(f"Request ID: {error.request_id}", file=sys.stderr)
|
|
63
|
-
charged = error.metadata.
|
|
63
|
+
charged = error.metadata.cu_charged if error.metadata else None
|
|
64
64
|
print(
|
|
65
65
|
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
66
66
|
file=sys.stderr,
|
|
@@ -72,7 +72,7 @@ def main() -> None:
|
|
|
72
72
|
"No complete response; execution and charges may be unknown. No retry."
|
|
73
73
|
) from None
|
|
74
74
|
except ResponseError as error:
|
|
75
|
-
charged = error.metadata.
|
|
75
|
+
charged = error.metadata.cu_charged if error.metadata else None
|
|
76
76
|
print(
|
|
77
77
|
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
78
78
|
file=sys.stderr,
|
|
@@ -94,7 +94,7 @@ def main() -> None:
|
|
|
94
94
|
for engine in response.metadata.engines:
|
|
95
95
|
print(f"Engine: {engine.name} {engine.version} ({engine.revision})")
|
|
96
96
|
# Missing commercial CU is unreported, not zero.
|
|
97
|
-
charged = response.metadata.
|
|
97
|
+
charged = response.metadata.cu_charged
|
|
98
98
|
print("Commercial CU charged:", charged if charged is not None else "not reported")
|
|
99
99
|
|
|
100
100
|
|
|
@@ -39,7 +39,7 @@ async def main() -> None:
|
|
|
39
39
|
),
|
|
40
40
|
PriceRequest(
|
|
41
41
|
exercise_style="american",
|
|
42
|
-
pricing_model="
|
|
42
|
+
pricing_model="bjerksund_stensland_1993",
|
|
43
43
|
option_type="put",
|
|
44
44
|
spot=100.0,
|
|
45
45
|
strike=105.0,
|
|
@@ -61,7 +61,7 @@ async def main() -> None:
|
|
|
61
61
|
print("No automatic retry or batch splitting.", file=sys.stderr)
|
|
62
62
|
print(f"HTTP {error.status_code}: {error.code}: {error.message}", file=sys.stderr)
|
|
63
63
|
print(f"Request ID: {error.request_id}", file=sys.stderr)
|
|
64
|
-
charged = error.metadata.
|
|
64
|
+
charged = error.metadata.cu_charged if error.metadata else None
|
|
65
65
|
print(
|
|
66
66
|
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
67
67
|
file=sys.stderr,
|
|
@@ -73,7 +73,7 @@ async def main() -> None:
|
|
|
73
73
|
"No complete response; execution and charges may be unknown. No retry."
|
|
74
74
|
) from None
|
|
75
75
|
except ResponseError as error:
|
|
76
|
-
charged = error.metadata.
|
|
76
|
+
charged = error.metadata.cu_charged if error.metadata else None
|
|
77
77
|
print(
|
|
78
78
|
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
79
79
|
file=sys.stderr,
|
|
@@ -95,7 +95,7 @@ async def main() -> None:
|
|
|
95
95
|
for engine in response.metadata.engines:
|
|
96
96
|
print(f"Engine: {engine.name} {engine.version} ({engine.revision})")
|
|
97
97
|
# Missing commercial CU is unreported, not zero.
|
|
98
|
-
charged = response.metadata.
|
|
98
|
+
charged = response.metadata.cu_charged
|
|
99
99
|
print("Commercial CU charged:", charged if charged is not None else "not reported")
|
|
100
100
|
|
|
101
101
|
|
|
@@ -40,7 +40,7 @@ def main() -> None:
|
|
|
40
40
|
# Also runs on interruption; preserve partial results and unknown charges.
|
|
41
41
|
for attempt in workflow.attempts:
|
|
42
42
|
print(f"Input range [{attempt.start}, {attempt.stop}): {attempt.request_id}")
|
|
43
|
-
charge = attempt.
|
|
43
|
+
charge = attempt.cu_charged
|
|
44
44
|
print("Chunk CU:", charge if charge is not None else "not reported")
|
|
45
45
|
if attempt.response is None:
|
|
46
46
|
print("No validated results for this chunk; do not replay automatically.")
|
|
@@ -57,9 +57,9 @@ def main() -> None:
|
|
|
57
57
|
for engine in attempt.response.metadata.engines:
|
|
58
58
|
print("Engine:", engine.name, engine.version, engine.revision)
|
|
59
59
|
print("Workflow state:", workflow.state)
|
|
60
|
-
print("Reported CU subtotal:", workflow.
|
|
60
|
+
print("Reported CU subtotal:", workflow.reported_cu_charged)
|
|
61
61
|
print("Attempts with unknown CU:", workflow.unknown_charge_count)
|
|
62
|
-
total = workflow.
|
|
62
|
+
total = workflow.total_cu_charged
|
|
63
63
|
print("Whole-workflow CU:", total if total is not None else "unknown or incomplete")
|
|
64
64
|
print("Unattempted input ranges:", workflow.unattempted_ranges)
|
|
65
65
|
if workflow.state != "completed":
|
|
@@ -43,7 +43,7 @@ async def main(max_concurrency: int = 1) -> None:
|
|
|
43
43
|
# Also runs on interruption; preserve partial results and unknown charges.
|
|
44
44
|
for attempt in workflow.attempts:
|
|
45
45
|
print(f"Input range [{attempt.start}, {attempt.stop}): {attempt.request_id}")
|
|
46
|
-
charge = attempt.
|
|
46
|
+
charge = attempt.cu_charged
|
|
47
47
|
print("Chunk CU:", charge if charge is not None else "not reported")
|
|
48
48
|
if attempt.response is None:
|
|
49
49
|
print("No validated results for this chunk; do not replay automatically.")
|
|
@@ -60,9 +60,9 @@ async def main(max_concurrency: int = 1) -> None:
|
|
|
60
60
|
for engine in attempt.response.metadata.engines:
|
|
61
61
|
print("Engine:", engine.name, engine.version, engine.revision)
|
|
62
62
|
print("Workflow state:", workflow.state)
|
|
63
|
-
print("Reported CU subtotal:", workflow.
|
|
63
|
+
print("Reported CU subtotal:", workflow.reported_cu_charged)
|
|
64
64
|
print("Attempts with unknown CU:", workflow.unknown_charge_count)
|
|
65
|
-
total = workflow.
|
|
65
|
+
total = workflow.total_cu_charged
|
|
66
66
|
print("Whole-workflow CU:", total if total is not None else "unknown or incomplete")
|
|
67
67
|
print("Unattempted input ranges:", workflow.unattempted_ranges)
|
|
68
68
|
if workflow.state != "completed":
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Two non-billable utility requests; --execute adds one capped pricing request."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
from morphiq_sdk import (
|
|
7
|
+
APIError,
|
|
8
|
+
BatchPriceRequest,
|
|
9
|
+
BatchPriceResponse,
|
|
10
|
+
MorphIQ,
|
|
11
|
+
PriceRequest,
|
|
12
|
+
PriceResponse,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main() -> None:
|
|
17
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
18
|
+
parser.add_argument(
|
|
19
|
+
"--execute", action="store_true", help="Execute once with the quoted CU ceiling"
|
|
20
|
+
)
|
|
21
|
+
parser.add_argument("--batch", action="store_true", help="Quote two synthetic contracts")
|
|
22
|
+
parser.add_argument(
|
|
23
|
+
"--max-cu", type=int, help="Explicit execution ceiling; defaults to the quote"
|
|
24
|
+
)
|
|
25
|
+
args = parser.parse_args()
|
|
26
|
+
if args.max_cu is not None and not 0 <= args.max_cu <= 2**64 - 1:
|
|
27
|
+
parser.error("--max-cu must be an unsigned 64-bit integer")
|
|
28
|
+
if args.max_cu is not None and not args.execute:
|
|
29
|
+
parser.error("--max-cu requires --execute")
|
|
30
|
+
request = PriceRequest(
|
|
31
|
+
exercise_style="european",
|
|
32
|
+
option_type="call",
|
|
33
|
+
spot=100.0,
|
|
34
|
+
strike=100.0,
|
|
35
|
+
time_to_expiry_years=1.0,
|
|
36
|
+
risk_free_rate=0.05,
|
|
37
|
+
dividend_yield=0.0,
|
|
38
|
+
volatility=0.2,
|
|
39
|
+
)
|
|
40
|
+
with MorphIQ() as client:
|
|
41
|
+
schedule = client.cost_schedule(operation="price")
|
|
42
|
+
print(schedule.model_dump_json(indent=2))
|
|
43
|
+
batch = BatchPriceRequest(requests=[request, request])
|
|
44
|
+
quote = client.quote(batch if args.batch else request)
|
|
45
|
+
print(quote.model_dump_json(indent=2))
|
|
46
|
+
print("Prospective execution CU:", quote.quote.total_cu)
|
|
47
|
+
print("Utility CU charged:", quote.metadata.cu_charged)
|
|
48
|
+
if args.execute:
|
|
49
|
+
ceiling = quote.quote.total_cu if args.max_cu is None else args.max_cu
|
|
50
|
+
response: PriceResponse | BatchPriceResponse
|
|
51
|
+
try:
|
|
52
|
+
if args.batch:
|
|
53
|
+
response = client.price_batch(batch, max_cu=ceiling)
|
|
54
|
+
else:
|
|
55
|
+
response = client.price(request, max_cu=ceiling)
|
|
56
|
+
except APIError as error:
|
|
57
|
+
print(f"HTTP {error.status_code}: {error.code}", file=sys.stderr)
|
|
58
|
+
print("Request ID:", error.request_id, file=sys.stderr)
|
|
59
|
+
quoted = error.metadata.cu_quoted if error.metadata else None
|
|
60
|
+
charged = error.metadata.cu_charged if error.metadata else None
|
|
61
|
+
print(
|
|
62
|
+
"Execution quote CU:",
|
|
63
|
+
quoted if quoted is not None else "not reported",
|
|
64
|
+
file=sys.stderr,
|
|
65
|
+
)
|
|
66
|
+
print(
|
|
67
|
+
"CU charged:",
|
|
68
|
+
charged if charged is not None else "not reported",
|
|
69
|
+
file=sys.stderr,
|
|
70
|
+
)
|
|
71
|
+
print("No retry or automatic ceiling increase.", file=sys.stderr)
|
|
72
|
+
raise SystemExit(1) from None
|
|
73
|
+
print(response.model_dump_json(indent=2))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == "__main__":
|
|
77
|
+
main()
|
|
@@ -34,7 +34,7 @@ def main() -> None:
|
|
|
34
34
|
except APIError as error:
|
|
35
35
|
print(f"HTTP {error.status_code}: {error.code}: {error.message}", file=sys.stderr)
|
|
36
36
|
print(f"Request ID: {error.request_id}", file=sys.stderr)
|
|
37
|
-
charged = error.metadata.
|
|
37
|
+
charged = error.metadata.cu_charged if error.metadata else None
|
|
38
38
|
print(
|
|
39
39
|
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
40
40
|
file=sys.stderr,
|
|
@@ -65,13 +65,15 @@ def main() -> None:
|
|
|
65
65
|
"veta",
|
|
66
66
|
"color",
|
|
67
67
|
):
|
|
68
|
-
|
|
68
|
+
value = getattr(response.result.greeks, name)
|
|
69
|
+
reason = response.result.greeks.unavailable.get(name)
|
|
70
|
+
print(f" {name}: {value if value is not None else reason}")
|
|
69
71
|
print(f"Model: {response.result.pricing_model} ({response.result.model_version})")
|
|
70
72
|
print(f"Request ID: {response.metadata.request_id}")
|
|
71
73
|
for engine in response.metadata.engines:
|
|
72
74
|
print(f"Engine: {engine.name} {engine.version} ({engine.revision})")
|
|
73
75
|
# Missing commercial CU is unreported, not zero.
|
|
74
|
-
charged = response.metadata.
|
|
76
|
+
charged = response.metadata.cu_charged
|
|
75
77
|
print("Commercial CU charged:", charged if charged is not None else "not reported")
|
|
76
78
|
|
|
77
79
|
|
|
@@ -35,7 +35,7 @@ async def main() -> None:
|
|
|
35
35
|
except APIError as error:
|
|
36
36
|
print(f"HTTP {error.status_code}: {error.code}: {error.message}", file=sys.stderr)
|
|
37
37
|
print(f"Request ID: {error.request_id}", file=sys.stderr)
|
|
38
|
-
charged = error.metadata.
|
|
38
|
+
charged = error.metadata.cu_charged if error.metadata else None
|
|
39
39
|
print(
|
|
40
40
|
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
41
41
|
file=sys.stderr,
|
|
@@ -66,13 +66,15 @@ async def main() -> None:
|
|
|
66
66
|
"veta",
|
|
67
67
|
"color",
|
|
68
68
|
):
|
|
69
|
-
|
|
69
|
+
value = getattr(response.result.greeks, name)
|
|
70
|
+
reason = response.result.greeks.unavailable.get(name)
|
|
71
|
+
print(f" {name}: {value if value is not None else reason}")
|
|
70
72
|
print(f"Model: {response.result.pricing_model} ({response.result.model_version})")
|
|
71
73
|
print(f"Request ID: {response.metadata.request_id}")
|
|
72
74
|
for engine in response.metadata.engines:
|
|
73
75
|
print(f"Engine: {engine.name} {engine.version} ({engine.revision})")
|
|
74
76
|
# Missing commercial CU is unreported, not zero.
|
|
75
|
-
charged = response.metadata.
|
|
77
|
+
charged = response.metadata.cu_charged
|
|
76
78
|
print("Commercial CU charged:", charged if charged is not None else "not reported")
|
|
77
79
|
|
|
78
80
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Calculate the price and standard five Greeks for a synthetic European call.
|
|
2
|
+
|
|
3
|
+
Run: python examples/greeks_standard.py
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
from getpass import getpass
|
|
9
|
+
|
|
10
|
+
from morphiq_sdk import APIError, GreeksStandardRequest, MorphIQ, ResponseError, TransportError
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main() -> None:
|
|
14
|
+
# Set MORPHIQ_API_KEY in your environment, or enter it at the masked prompt.
|
|
15
|
+
api_key = os.environ.get("MORPHIQ_API_KEY") or getpass("MorphIQ API key: ")
|
|
16
|
+
|
|
17
|
+
# Synthetic European call; spot and strike use the same currency.
|
|
18
|
+
request = GreeksStandardRequest(
|
|
19
|
+
exercise_style="european",
|
|
20
|
+
option_type="call",
|
|
21
|
+
spot=100.0,
|
|
22
|
+
strike=100.0,
|
|
23
|
+
time_to_expiry_years=1.0, # Years from valuation.
|
|
24
|
+
risk_free_rate=0.05, # 5% annual rate.
|
|
25
|
+
dividend_yield=0.0,
|
|
26
|
+
volatility=0.20, # 20% annual volatility.
|
|
27
|
+
pricing_model="auto",
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
# The client uses https://api.morphiqlabs.com and closes its connection pool here.
|
|
32
|
+
with MorphIQ(api_key=api_key) as client:
|
|
33
|
+
response = client.greeks_standard(request)
|
|
34
|
+
except APIError as error:
|
|
35
|
+
print(f"HTTP {error.status_code}: {error.code}: {error.message}", file=sys.stderr)
|
|
36
|
+
print(f"Request ID: {error.request_id}", file=sys.stderr)
|
|
37
|
+
charged = error.metadata.cu_charged if error.metadata else None
|
|
38
|
+
print(
|
|
39
|
+
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
40
|
+
file=sys.stderr,
|
|
41
|
+
)
|
|
42
|
+
raise SystemExit(1) from None
|
|
43
|
+
except TransportError:
|
|
44
|
+
# Includes timeouts. The service may already have committed a charge.
|
|
45
|
+
raise SystemExit(
|
|
46
|
+
"No complete response; execution and charges may be unknown. No retry."
|
|
47
|
+
) from None
|
|
48
|
+
except ResponseError as error:
|
|
49
|
+
raise SystemExit(
|
|
50
|
+
f"Invalid response; request_id={error.request_id}. Charges may be unknown. No retry."
|
|
51
|
+
) from None
|
|
52
|
+
|
|
53
|
+
print(f"Price: {response.result.price}")
|
|
54
|
+
# API time derivatives are per year; vega/rho use unit volatility/rate.
|
|
55
|
+
print("Greeks (raw API units):")
|
|
56
|
+
for name in (
|
|
57
|
+
"delta",
|
|
58
|
+
"gamma",
|
|
59
|
+
"theta",
|
|
60
|
+
"vega",
|
|
61
|
+
"rho",
|
|
62
|
+
):
|
|
63
|
+
value = getattr(response.result.greeks, name)
|
|
64
|
+
reason = response.result.greeks.unavailable.get(name)
|
|
65
|
+
print(f" {name}: {value if value is not None else reason}")
|
|
66
|
+
print(f"Model: {response.result.pricing_model} ({response.result.model_version})")
|
|
67
|
+
print(f"Request ID: {response.metadata.request_id}")
|
|
68
|
+
for engine in response.metadata.engines:
|
|
69
|
+
print(f"Engine: {engine.name} {engine.version} ({engine.revision})")
|
|
70
|
+
# Missing commercial CU is unreported, not zero.
|
|
71
|
+
charged = response.metadata.cu_charged
|
|
72
|
+
print("Commercial CU charged:", charged if charged is not None else "not reported")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if __name__ == "__main__":
|
|
76
|
+
main()
|
|
@@ -52,7 +52,7 @@ def main() -> None:
|
|
|
52
52
|
except APIError as error:
|
|
53
53
|
print(f"HTTP {error.status_code}: {error.code}: {error.message}", file=sys.stderr)
|
|
54
54
|
print(f"Request ID: {error.request_id}", file=sys.stderr)
|
|
55
|
-
charged = error.metadata.
|
|
55
|
+
charged = error.metadata.cu_charged if error.metadata else None
|
|
56
56
|
print(
|
|
57
57
|
f"Commercial CU charged: {charged if charged is not None else 'not reported'}",
|
|
58
58
|
file=sys.stderr,
|
|
@@ -83,6 +83,22 @@ def main() -> None:
|
|
|
83
83
|
else:
|
|
84
84
|
print(f" Reason: {head.reason_code}")
|
|
85
85
|
|
|
86
|
+
volatility = response.result.volatility
|
|
87
|
+
if volatility is not None:
|
|
88
|
+
print("Volatility:", volatility.status)
|
|
89
|
+
if volatility.status == "available":
|
|
90
|
+
print(" Label:", volatility.prediction.label)
|
|
91
|
+
else:
|
|
92
|
+
print(" Reason:", volatility.reason_code)
|
|
93
|
+
crisis = response.result.crisis
|
|
94
|
+
if crisis is not None:
|
|
95
|
+
print("Crisis:", crisis.status)
|
|
96
|
+
if crisis.status == "unavailable":
|
|
97
|
+
print(" Reason:", crisis.reason_code)
|
|
98
|
+
else:
|
|
99
|
+
print(" Linear readout (not a probability):", crisis.score)
|
|
100
|
+
print(" Episode start price index:", crisis.episode_start_price_index)
|
|
101
|
+
|
|
86
102
|
# Scores are uncalibrated softmax values, not probabilities or p-values.
|
|
87
103
|
# Do not multiply heads. LOWER_VOL/HIGHER_VOL are relative model states,
|
|
88
104
|
# not historical volatility levels or price directions.
|
|
@@ -99,7 +115,7 @@ def main() -> None:
|
|
|
99
115
|
print("Request ID:", metadata.request_id)
|
|
100
116
|
for engine in metadata.engines:
|
|
101
117
|
print(f"Engine: {engine.name} {engine.version} ({engine.revision})")
|
|
102
|
-
charged = metadata.
|
|
118
|
+
charged = metadata.cu_charged
|
|
103
119
|
print("Commercial CU charged:", charged if charged is not None else "not reported")
|
|
104
120
|
|
|
105
121
|
|