prometheus-qengine 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- prometheus_qengine-1.0.0/LICENSE +21 -0
- prometheus_qengine-1.0.0/PKG-INFO +132 -0
- prometheus_qengine-1.0.0/README.md +112 -0
- prometheus_qengine-1.0.0/prometheus_qengine/client.py +84 -0
- prometheus_qengine-1.0.0/prometheus_qengine/enums.py +16 -0
- prometheus_qengine-1.0.0/prometheus_qengine/exceptions.py +15 -0
- prometheus_qengine-1.0.0/prometheus_qengine/init.py +16 -0
- prometheus_qengine-1.0.0/prometheus_qengine/models.py +63 -0
- prometheus_qengine-1.0.0/prometheus_qengine.egg-info/PKG-INFO +132 -0
- prometheus_qengine-1.0.0/prometheus_qengine.egg-info/SOURCES.txt +13 -0
- prometheus_qengine-1.0.0/prometheus_qengine.egg-info/dependency_links.txt +1 -0
- prometheus_qengine-1.0.0/prometheus_qengine.egg-info/requires.txt +3 -0
- prometheus_qengine-1.0.0/prometheus_qengine.egg-info/top_level.txt +1 -0
- prometheus_qengine-1.0.0/pyproject.toml +29 -0
- prometheus_qengine-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Prometheus Quant Engine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: prometheus-qengine
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Python SDK for the Prometheus Quant Engine (HPC Monte Carlo)
|
|
5
|
+
Author-email: Prometheus Quant Engineering <dev@prometheusquantengine.com>
|
|
6
|
+
Project-URL: Homepage, https://prometheusquantengine.com
|
|
7
|
+
Project-URL: Documentation, https://prometheusquantengine.com/web-docs
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: requests>=2.25.0
|
|
17
|
+
Requires-Dist: pydantic>=2.0.0
|
|
18
|
+
Requires-Dist: pandas>=1.3.0
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# Prometheus Quant Engine: Python SDK
|
|
22
|
+
|
|
23
|
+
[](https://badge.fury.io/py/prometheus-qengine)
|
|
24
|
+
[](https://pypi.org/project/prometheus-qengine/)
|
|
25
|
+
[](https://opensource.org/licenses/MIT)
|
|
26
|
+
|
|
27
|
+
**Prometheus Quant Engine** is an institutional-grade, High-Performance Computing (HPC) API for pricing path-dependent and exotic derivatives.
|
|
28
|
+
|
|
29
|
+
This SDK abstracts the complexity of our underlying C++ OpenMP infrastructure, allowing quantitative developers to offload massive stochastic matrices (up to 1,000,000,000 trajectories) directly from Python, completely bypassing the Global Interpreter Lock (GIL) and native memory bottlenecks.
|
|
30
|
+
|
|
31
|
+
## 🚀 Key Architectural Features
|
|
32
|
+
|
|
33
|
+
* **Strict Mathematical Validation:** Built on top of `Pydantic V2`. The SDK catches logical errors (e.g., negative time, invalid barrier boundaries) locally before wasting network latency or compute credits.
|
|
34
|
+
* **Deterministic Idempotency:** Built-in Double-Spend protection. If a network partition occurs, retrying the exact same request with the same `Idempotency-Key` yields the cached mathematical matrix at strictly zero cost.
|
|
35
|
+
* **Asynchronous Polling Abstraction:** Massive workloads ($N \times M > 50\text{M}$ steps) are seamlessly routed to our Celery HPC cluster. The SDK abstracts the long-polling lifecycle—you just call `.price()` and receive the finalized DataFrame.
|
|
36
|
+
* **Pandas Native:** Seamless integration with `pandas` for immediate volatility surface plotting and quantitative analysis.
|
|
37
|
+
|
|
38
|
+
## 📦 Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install prometheus-qengine
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 🔑 Authentication & Free Compute Ledger
|
|
45
|
+
|
|
46
|
+
To execute simulations, you need a Master API Key.
|
|
47
|
+
Register at [prometheusquantengine.com](https://prometheusquantengine.com) to instantly receive **50 Free Compute Credits** (equivalent to 12.5 Billion stochastic path evolutions).
|
|
48
|
+
|
|
49
|
+
## 💻 Quickstart: European Options
|
|
50
|
+
|
|
51
|
+
European options are evaluated via highly optimized Control Variates to tighten the Confidence Interval (CI) in record time.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from prometheus_qengine import PrometheusClient, EuropeanOption, OptionType
|
|
55
|
+
|
|
56
|
+
# 1. Initialize the client
|
|
57
|
+
client = PrometheusClient(api_key="pmt_live_your_secure_api_key")
|
|
58
|
+
|
|
59
|
+
# 2. Define the exact quantitative parameters
|
|
60
|
+
option = EuropeanOption(
|
|
61
|
+
s_0=100.0,
|
|
62
|
+
strike=100.0,
|
|
63
|
+
volatility=0.20,
|
|
64
|
+
time_to_maturity=1.0,
|
|
65
|
+
risk_free_rate=0.05,
|
|
66
|
+
option_type=OptionType.CALL,
|
|
67
|
+
n_simulations=10_000_000,
|
|
68
|
+
label="Quickstart_European_Call"
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# 3. Dispatch to the C++ Engine
|
|
72
|
+
result = client.price(option)
|
|
73
|
+
|
|
74
|
+
# 4. Analyze the output natively in Pandas
|
|
75
|
+
df = result.to_pandas()
|
|
76
|
+
print(df[["fair_value", "delta", "gamma", "vega", "credits_cost"]])
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## ⚡ Heavy Workloads: Barrier Options (HPC Routing)
|
|
80
|
+
|
|
81
|
+
When pricing complex path-dependent instruments with step-function discontinuities (like Knock-Out barriers), dense trajectory matrices are required to stabilize the Gamma ($\Gamma$).
|
|
82
|
+
|
|
83
|
+
If your configuration exceeds 50 million total computational steps, the SDK automatically routes the payload to the asynchronous Celery broker and handles the polling loop silently.
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from prometheus_qengine import PrometheusClient, BarrierOption, OptionType, BarrierType
|
|
87
|
+
|
|
88
|
+
client = PrometheusClient(api_key="pmt_live_your_secure_api_key")
|
|
89
|
+
|
|
90
|
+
heavy_barrier = BarrierOption(
|
|
91
|
+
s_0=100.0,
|
|
92
|
+
strike=100.0,
|
|
93
|
+
volatility=0.25,
|
|
94
|
+
time_to_maturity=1.0,
|
|
95
|
+
risk_free_rate=0.05,
|
|
96
|
+
option_type=OptionType.PUT,
|
|
97
|
+
n_simulations=1_000_000, # 1 Million Paths
|
|
98
|
+
m_steps=252, # Daily observations
|
|
99
|
+
barrier_type=BarrierType.DOWN_AND_OUT,
|
|
100
|
+
barrier_level=85.0
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# The SDK detects 252,000,000 total steps.
|
|
104
|
+
# It delegates the matrix to the C++ cluster and waits for the resolution.
|
|
105
|
+
result = client.price(heavy_barrier)
|
|
106
|
+
|
|
107
|
+
print(f"Fair Value computed: {result.fair_value}")
|
|
108
|
+
print(f"Confidence Interval: [{result.ci_lower}, {result.ci_upper}]")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## 🛡️ Error Handling & Limits
|
|
112
|
+
|
|
113
|
+
The SDK translates HTTP status codes into strict Pythonic exceptions:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from prometheus_qengine.exceptions import InsufficientCreditsError, AuthenticationError
|
|
117
|
+
|
|
118
|
+
try:
|
|
119
|
+
result = client.price(option)
|
|
120
|
+
except InsufficientCreditsError as e:
|
|
121
|
+
print("Ledger depleted. Recharge required.")
|
|
122
|
+
except AuthenticationError as e:
|
|
123
|
+
print("Invalid API Key.")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 📚 Documentation & Research
|
|
127
|
+
|
|
128
|
+
For in-depth mathematical proofs regarding our Finite Difference implementations, False Sharing mitigation in OpenMP, and structural REST API architecture, visit our [Papers](https://prometheusquantengine.com/papers) and [Api-docs](https://prometheusquantengine.com/web-docs).
|
|
129
|
+
|
|
130
|
+
## 📄 License
|
|
131
|
+
|
|
132
|
+
This SDK is distributed under the MIT License. See [`LICENSE`](https://github.com/Prometheus-Quant-Engineering/prometheus-quant-python/blob/main/LICENSE) for more information.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Prometheus Quant Engine: Python SDK
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/prometheus-qengine)
|
|
4
|
+
[](https://pypi.org/project/prometheus-qengine/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
**Prometheus Quant Engine** is an institutional-grade, High-Performance Computing (HPC) API for pricing path-dependent and exotic derivatives.
|
|
8
|
+
|
|
9
|
+
This SDK abstracts the complexity of our underlying C++ OpenMP infrastructure, allowing quantitative developers to offload massive stochastic matrices (up to 1,000,000,000 trajectories) directly from Python, completely bypassing the Global Interpreter Lock (GIL) and native memory bottlenecks.
|
|
10
|
+
|
|
11
|
+
## 🚀 Key Architectural Features
|
|
12
|
+
|
|
13
|
+
* **Strict Mathematical Validation:** Built on top of `Pydantic V2`. The SDK catches logical errors (e.g., negative time, invalid barrier boundaries) locally before wasting network latency or compute credits.
|
|
14
|
+
* **Deterministic Idempotency:** Built-in Double-Spend protection. If a network partition occurs, retrying the exact same request with the same `Idempotency-Key` yields the cached mathematical matrix at strictly zero cost.
|
|
15
|
+
* **Asynchronous Polling Abstraction:** Massive workloads ($N \times M > 50\text{M}$ steps) are seamlessly routed to our Celery HPC cluster. The SDK abstracts the long-polling lifecycle—you just call `.price()` and receive the finalized DataFrame.
|
|
16
|
+
* **Pandas Native:** Seamless integration with `pandas` for immediate volatility surface plotting and quantitative analysis.
|
|
17
|
+
|
|
18
|
+
## 📦 Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install prometheus-qengine
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 🔑 Authentication & Free Compute Ledger
|
|
25
|
+
|
|
26
|
+
To execute simulations, you need a Master API Key.
|
|
27
|
+
Register at [prometheusquantengine.com](https://prometheusquantengine.com) to instantly receive **50 Free Compute Credits** (equivalent to 12.5 Billion stochastic path evolutions).
|
|
28
|
+
|
|
29
|
+
## 💻 Quickstart: European Options
|
|
30
|
+
|
|
31
|
+
European options are evaluated via highly optimized Control Variates to tighten the Confidence Interval (CI) in record time.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from prometheus_qengine import PrometheusClient, EuropeanOption, OptionType
|
|
35
|
+
|
|
36
|
+
# 1. Initialize the client
|
|
37
|
+
client = PrometheusClient(api_key="pmt_live_your_secure_api_key")
|
|
38
|
+
|
|
39
|
+
# 2. Define the exact quantitative parameters
|
|
40
|
+
option = EuropeanOption(
|
|
41
|
+
s_0=100.0,
|
|
42
|
+
strike=100.0,
|
|
43
|
+
volatility=0.20,
|
|
44
|
+
time_to_maturity=1.0,
|
|
45
|
+
risk_free_rate=0.05,
|
|
46
|
+
option_type=OptionType.CALL,
|
|
47
|
+
n_simulations=10_000_000,
|
|
48
|
+
label="Quickstart_European_Call"
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# 3. Dispatch to the C++ Engine
|
|
52
|
+
result = client.price(option)
|
|
53
|
+
|
|
54
|
+
# 4. Analyze the output natively in Pandas
|
|
55
|
+
df = result.to_pandas()
|
|
56
|
+
print(df[["fair_value", "delta", "gamma", "vega", "credits_cost"]])
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## ⚡ Heavy Workloads: Barrier Options (HPC Routing)
|
|
60
|
+
|
|
61
|
+
When pricing complex path-dependent instruments with step-function discontinuities (like Knock-Out barriers), dense trajectory matrices are required to stabilize the Gamma ($\Gamma$).
|
|
62
|
+
|
|
63
|
+
If your configuration exceeds 50 million total computational steps, the SDK automatically routes the payload to the asynchronous Celery broker and handles the polling loop silently.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from prometheus_qengine import PrometheusClient, BarrierOption, OptionType, BarrierType
|
|
67
|
+
|
|
68
|
+
client = PrometheusClient(api_key="pmt_live_your_secure_api_key")
|
|
69
|
+
|
|
70
|
+
heavy_barrier = BarrierOption(
|
|
71
|
+
s_0=100.0,
|
|
72
|
+
strike=100.0,
|
|
73
|
+
volatility=0.25,
|
|
74
|
+
time_to_maturity=1.0,
|
|
75
|
+
risk_free_rate=0.05,
|
|
76
|
+
option_type=OptionType.PUT,
|
|
77
|
+
n_simulations=1_000_000, # 1 Million Paths
|
|
78
|
+
m_steps=252, # Daily observations
|
|
79
|
+
barrier_type=BarrierType.DOWN_AND_OUT,
|
|
80
|
+
barrier_level=85.0
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
# The SDK detects 252,000,000 total steps.
|
|
84
|
+
# It delegates the matrix to the C++ cluster and waits for the resolution.
|
|
85
|
+
result = client.price(heavy_barrier)
|
|
86
|
+
|
|
87
|
+
print(f"Fair Value computed: {result.fair_value}")
|
|
88
|
+
print(f"Confidence Interval: [{result.ci_lower}, {result.ci_upper}]")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 🛡️ Error Handling & Limits
|
|
92
|
+
|
|
93
|
+
The SDK translates HTTP status codes into strict Pythonic exceptions:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from prometheus_qengine.exceptions import InsufficientCreditsError, AuthenticationError
|
|
97
|
+
|
|
98
|
+
try:
|
|
99
|
+
result = client.price(option)
|
|
100
|
+
except InsufficientCreditsError as e:
|
|
101
|
+
print("Ledger depleted. Recharge required.")
|
|
102
|
+
except AuthenticationError as e:
|
|
103
|
+
print("Invalid API Key.")
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## 📚 Documentation & Research
|
|
107
|
+
|
|
108
|
+
For in-depth mathematical proofs regarding our Finite Difference implementations, False Sharing mitigation in OpenMP, and structural REST API architecture, visit our [Papers](https://prometheusquantengine.com/papers) and [Api-docs](https://prometheusquantengine.com/web-docs).
|
|
109
|
+
|
|
110
|
+
## 📄 License
|
|
111
|
+
|
|
112
|
+
This SDK is distributed under the MIT License. See [`LICENSE`](https://github.com/Prometheus-Quant-Engineering/prometheus-quant-python/blob/main/LICENSE) for more information.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import uuid
|
|
3
|
+
import time
|
|
4
|
+
import logging
|
|
5
|
+
from typing import Union
|
|
6
|
+
|
|
7
|
+
from .models import EuropeanOption, AsianOption, BarrierOption, SimulationResult
|
|
8
|
+
from .exceptions import AuthenticationError, InsufficientCreditsError, EngineComputationError, PrometheusError
|
|
9
|
+
|
|
10
|
+
logging.basicConfig(format='%(levelname)s: %(message)s')
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
class PrometheusClient:
|
|
14
|
+
def __init__(self, api_key: str, base_url: str = "https://api.prometheusquantengine.com/api/v1"):
|
|
15
|
+
if not api_key:
|
|
16
|
+
raise AuthenticationError("API Key is required to instantiate the Prometheus Client.")
|
|
17
|
+
|
|
18
|
+
self.api_key = api_key
|
|
19
|
+
self.base_url = base_url.rstrip("/")
|
|
20
|
+
self._session = requests.Session()
|
|
21
|
+
self._session.headers.update({"X-API-Key": self.api_key})
|
|
22
|
+
|
|
23
|
+
def price(
|
|
24
|
+
self,
|
|
25
|
+
option: Union[EuropeanOption, AsianOption, BarrierOption],
|
|
26
|
+
idempotency_key: str = None,
|
|
27
|
+
poll_interval: int = 2
|
|
28
|
+
) -> SimulationResult:
|
|
29
|
+
"""
|
|
30
|
+
Submits the mathematical payload to the C++ Engine.
|
|
31
|
+
Automatically handles synchronous routing and asynchronous HPC polling.
|
|
32
|
+
"""
|
|
33
|
+
# Auto-generate idempotency protection if not explicitly provided
|
|
34
|
+
idem_key = idempotency_key or str(uuid.uuid4())
|
|
35
|
+
|
|
36
|
+
headers = {
|
|
37
|
+
"Idempotency-Key": idem_key,
|
|
38
|
+
"Content-Type": "application/json"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
url = f"{self.base_url}/simulations"
|
|
42
|
+
payload = option.model_dump(mode='json', exclude_none=True)
|
|
43
|
+
|
|
44
|
+
response = self._session.post(url, json=payload, headers=headers)
|
|
45
|
+
|
|
46
|
+
self._handle_http_errors(response)
|
|
47
|
+
data = response.json()
|
|
48
|
+
|
|
49
|
+
# 1. Asynchronous HPC Offload Detected
|
|
50
|
+
if "task_id" in data:
|
|
51
|
+
task_id = data["task_id"]
|
|
52
|
+
logger.info(f"Massive workload detected. Delegated to Celery HPC. Task ID: {task_id}")
|
|
53
|
+
return self._poll_hpc_cluster(task_id, poll_interval)
|
|
54
|
+
|
|
55
|
+
# 2. Synchronous Execution
|
|
56
|
+
return SimulationResult(**data)
|
|
57
|
+
|
|
58
|
+
def _poll_hpc_cluster(self, task_id: str, poll_interval: int) -> SimulationResult:
|
|
59
|
+
"""Internal method to abstract the long-polling architecture from the developer."""
|
|
60
|
+
url = f"{self.base_url}/simulations/task/{task_id}"
|
|
61
|
+
|
|
62
|
+
while True:
|
|
63
|
+
response = self._session.get(url)
|
|
64
|
+
self._handle_http_errors(response)
|
|
65
|
+
data = response.json()
|
|
66
|
+
status = data.get("status")
|
|
67
|
+
|
|
68
|
+
if status == "SUCCESS":
|
|
69
|
+
return SimulationResult(**data)
|
|
70
|
+
elif status in ["FAILURE", "REVOKED"]:
|
|
71
|
+
raise EngineComputationError("C++ Engine collapsed during execution. Credits refunded.")
|
|
72
|
+
|
|
73
|
+
time.sleep(poll_interval)
|
|
74
|
+
|
|
75
|
+
def _handle_http_errors(self, response: requests.Response):
|
|
76
|
+
"""Translates REST errors into Pythonic Exceptions."""
|
|
77
|
+
if response.status_code >= 400:
|
|
78
|
+
if response.status_code == 401:
|
|
79
|
+
raise AuthenticationError("Invalid API Key.")
|
|
80
|
+
elif response.status_code == 402:
|
|
81
|
+
raise InsufficientCreditsError("Insufficient Compute Credits. Please recharge your ledger.")
|
|
82
|
+
else:
|
|
83
|
+
error_msg = response.json().get("detail", response.text)
|
|
84
|
+
raise PrometheusError(f"HTTP {response.status_code}: {error_msg}")
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
class OptionType(str, Enum):
|
|
4
|
+
CALL = "Call"
|
|
5
|
+
PUT = "Put"
|
|
6
|
+
|
|
7
|
+
class BarrierType(str, Enum):
|
|
8
|
+
DOWN_AND_OUT = "DownAndOut"
|
|
9
|
+
DOWN_AND_IN = "DownAndIn"
|
|
10
|
+
UP_AND_OUT = "UpAndOut"
|
|
11
|
+
UP_AND_IN = "UpAndIn"
|
|
12
|
+
|
|
13
|
+
class SimulationType(str, Enum):
|
|
14
|
+
EUROPEAN = "European"
|
|
15
|
+
ASIAN = "Asian"
|
|
16
|
+
BARRIER = "Barrier"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class PrometheusError(Exception):
|
|
2
|
+
"""Base exception for Prometheus SDK."""
|
|
3
|
+
pass
|
|
4
|
+
|
|
5
|
+
class AuthenticationError(PrometheusError):
|
|
6
|
+
"""Raised when the API Key is invalid or missing."""
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
class InsufficientCreditsError(PrometheusError):
|
|
10
|
+
"""Raised when the account lacks compute credits (HTTP 402)."""
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
class EngineComputationError(PrometheusError):
|
|
14
|
+
"""Raised when the C++ engine fails to compute the matrix."""
|
|
15
|
+
pass
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from .client import PrometheusClient
|
|
2
|
+
from .models import EuropeanOption, AsianOption, BarrierOption, SimulationResult
|
|
3
|
+
from .enums import OptionType, BarrierType
|
|
4
|
+
from .exceptions import PrometheusError, InsufficientCreditsError
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"PrometheusClient",
|
|
8
|
+
"EuropeanOption",
|
|
9
|
+
"AsianOption",
|
|
10
|
+
"BarrierOption",
|
|
11
|
+
"SimulationResult",
|
|
12
|
+
"OptionType",
|
|
13
|
+
"BarrierType",
|
|
14
|
+
"PrometheusError",
|
|
15
|
+
"InsufficientCreditsError"
|
|
16
|
+
]
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from pydantic import BaseModel, Field, model_validator
|
|
2
|
+
from typing import Optional, Literal
|
|
3
|
+
from .enums import OptionType, BarrierType, SimulationType
|
|
4
|
+
import pandas as pd
|
|
5
|
+
|
|
6
|
+
class BaseSimulationPayload(BaseModel):
|
|
7
|
+
s_0: float = Field(..., gt=0.0, description="Initial Asset Price (Spot)")
|
|
8
|
+
strike: float = Field(..., gt=0.0, description="Strike Price")
|
|
9
|
+
volatility: float = Field(..., gt=0.0, le=5.0, description="Annualized Volatility")
|
|
10
|
+
time_to_maturity: float = Field(..., gt=0.0, description="Time to maturity in years")
|
|
11
|
+
risk_free_rate: float = Field(..., description="Annualized Risk-Free Rate")
|
|
12
|
+
option_type: OptionType
|
|
13
|
+
n_simulations: int = Field(..., ge=10000, le=1000000000)
|
|
14
|
+
label: Optional[str] = None
|
|
15
|
+
|
|
16
|
+
simulation_type: SimulationType
|
|
17
|
+
|
|
18
|
+
class EuropeanOption(BaseSimulationPayload):
|
|
19
|
+
simulation_type: Literal[SimulationType.EUROPEAN] = SimulationType.EUROPEAN
|
|
20
|
+
|
|
21
|
+
class AsianOption(BaseSimulationPayload):
|
|
22
|
+
simulation_type: Literal[SimulationType.ASIAN] = SimulationType.ASIAN
|
|
23
|
+
m_steps: int = Field(..., gt=0, description="Number of temporal observation steps")
|
|
24
|
+
|
|
25
|
+
class BarrierOption(BaseSimulationPayload):
|
|
26
|
+
simulation_type: Literal[SimulationType.BARRIER] = SimulationType.BARRIER
|
|
27
|
+
m_steps: int = Field(..., gt=0)
|
|
28
|
+
barrier_type: BarrierType
|
|
29
|
+
barrier_level: float = Field(..., gt=0.0)
|
|
30
|
+
|
|
31
|
+
@model_validator(mode='after')
|
|
32
|
+
def validate_barrier_logic(self):
|
|
33
|
+
"""Mathematically validates that the barrier makes logical sense before computing."""
|
|
34
|
+
if self.barrier_type in [BarrierType.DOWN_AND_OUT, BarrierType.DOWN_AND_IN]:
|
|
35
|
+
if self.barrier_level >= self.s_0:
|
|
36
|
+
raise ValueError("For Down barriers, barrier_level must be strictly below s_0.")
|
|
37
|
+
elif self.barrier_type in [BarrierType.UP_AND_OUT, BarrierType.UP_AND_IN]:
|
|
38
|
+
if self.barrier_level <= self.s_0:
|
|
39
|
+
raise ValueError("For Up barriers, barrier_level must be strictly above s_0.")
|
|
40
|
+
return self
|
|
41
|
+
|
|
42
|
+
class SimulationResult(BaseModel):
|
|
43
|
+
id: str
|
|
44
|
+
user_id: str
|
|
45
|
+
simulation_type: str
|
|
46
|
+
credits_cost: float
|
|
47
|
+
created_at: str
|
|
48
|
+
label: Optional[str] = None
|
|
49
|
+
fair_value: float
|
|
50
|
+
ci_lower: float
|
|
51
|
+
ci_upper: float
|
|
52
|
+
delta: Optional[float] = None
|
|
53
|
+
gamma: Optional[float] = None
|
|
54
|
+
vega: Optional[float] = None
|
|
55
|
+
rho: Optional[float] = None
|
|
56
|
+
is_gamma_stable: Optional[bool] = None
|
|
57
|
+
|
|
58
|
+
def to_pandas(self) -> pd.DataFrame:
|
|
59
|
+
"""Transforms the payload into a clean Pandas DataFrame for quant analysis."""
|
|
60
|
+
df = pd.DataFrame([self.model_dump()])
|
|
61
|
+
# Optional: Set 'id' as index for cleaner display
|
|
62
|
+
df.set_index('id', inplace=True)
|
|
63
|
+
return df
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: prometheus-qengine
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Python SDK for the Prometheus Quant Engine (HPC Monte Carlo)
|
|
5
|
+
Author-email: Prometheus Quant Engineering <dev@prometheusquantengine.com>
|
|
6
|
+
Project-URL: Homepage, https://prometheusquantengine.com
|
|
7
|
+
Project-URL: Documentation, https://prometheusquantengine.com/web-docs
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: requests>=2.25.0
|
|
17
|
+
Requires-Dist: pydantic>=2.0.0
|
|
18
|
+
Requires-Dist: pandas>=1.3.0
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# Prometheus Quant Engine: Python SDK
|
|
22
|
+
|
|
23
|
+
[](https://badge.fury.io/py/prometheus-qengine)
|
|
24
|
+
[](https://pypi.org/project/prometheus-qengine/)
|
|
25
|
+
[](https://opensource.org/licenses/MIT)
|
|
26
|
+
|
|
27
|
+
**Prometheus Quant Engine** is an institutional-grade, High-Performance Computing (HPC) API for pricing path-dependent and exotic derivatives.
|
|
28
|
+
|
|
29
|
+
This SDK abstracts the complexity of our underlying C++ OpenMP infrastructure, allowing quantitative developers to offload massive stochastic matrices (up to 1,000,000,000 trajectories) directly from Python, completely bypassing the Global Interpreter Lock (GIL) and native memory bottlenecks.
|
|
30
|
+
|
|
31
|
+
## 🚀 Key Architectural Features
|
|
32
|
+
|
|
33
|
+
* **Strict Mathematical Validation:** Built on top of `Pydantic V2`. The SDK catches logical errors (e.g., negative time, invalid barrier boundaries) locally before wasting network latency or compute credits.
|
|
34
|
+
* **Deterministic Idempotency:** Built-in Double-Spend protection. If a network partition occurs, retrying the exact same request with the same `Idempotency-Key` yields the cached mathematical matrix at strictly zero cost.
|
|
35
|
+
* **Asynchronous Polling Abstraction:** Massive workloads ($N \times M > 50\text{M}$ steps) are seamlessly routed to our Celery HPC cluster. The SDK abstracts the long-polling lifecycle—you just call `.price()` and receive the finalized DataFrame.
|
|
36
|
+
* **Pandas Native:** Seamless integration with `pandas` for immediate volatility surface plotting and quantitative analysis.
|
|
37
|
+
|
|
38
|
+
## 📦 Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install prometheus-qengine
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 🔑 Authentication & Free Compute Ledger
|
|
45
|
+
|
|
46
|
+
To execute simulations, you need a Master API Key.
|
|
47
|
+
Register at [prometheusquantengine.com](https://prometheusquantengine.com) to instantly receive **50 Free Compute Credits** (equivalent to 12.5 Billion stochastic path evolutions).
|
|
48
|
+
|
|
49
|
+
## 💻 Quickstart: European Options
|
|
50
|
+
|
|
51
|
+
European options are evaluated via highly optimized Control Variates to tighten the Confidence Interval (CI) in record time.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from prometheus_qengine import PrometheusClient, EuropeanOption, OptionType
|
|
55
|
+
|
|
56
|
+
# 1. Initialize the client
|
|
57
|
+
client = PrometheusClient(api_key="pmt_live_your_secure_api_key")
|
|
58
|
+
|
|
59
|
+
# 2. Define the exact quantitative parameters
|
|
60
|
+
option = EuropeanOption(
|
|
61
|
+
s_0=100.0,
|
|
62
|
+
strike=100.0,
|
|
63
|
+
volatility=0.20,
|
|
64
|
+
time_to_maturity=1.0,
|
|
65
|
+
risk_free_rate=0.05,
|
|
66
|
+
option_type=OptionType.CALL,
|
|
67
|
+
n_simulations=10_000_000,
|
|
68
|
+
label="Quickstart_European_Call"
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# 3. Dispatch to the C++ Engine
|
|
72
|
+
result = client.price(option)
|
|
73
|
+
|
|
74
|
+
# 4. Analyze the output natively in Pandas
|
|
75
|
+
df = result.to_pandas()
|
|
76
|
+
print(df[["fair_value", "delta", "gamma", "vega", "credits_cost"]])
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## ⚡ Heavy Workloads: Barrier Options (HPC Routing)
|
|
80
|
+
|
|
81
|
+
When pricing complex path-dependent instruments with step-function discontinuities (like Knock-Out barriers), dense trajectory matrices are required to stabilize the Gamma ($\Gamma$).
|
|
82
|
+
|
|
83
|
+
If your configuration exceeds 50 million total computational steps, the SDK automatically routes the payload to the asynchronous Celery broker and handles the polling loop silently.
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from prometheus_qengine import PrometheusClient, BarrierOption, OptionType, BarrierType
|
|
87
|
+
|
|
88
|
+
client = PrometheusClient(api_key="pmt_live_your_secure_api_key")
|
|
89
|
+
|
|
90
|
+
heavy_barrier = BarrierOption(
|
|
91
|
+
s_0=100.0,
|
|
92
|
+
strike=100.0,
|
|
93
|
+
volatility=0.25,
|
|
94
|
+
time_to_maturity=1.0,
|
|
95
|
+
risk_free_rate=0.05,
|
|
96
|
+
option_type=OptionType.PUT,
|
|
97
|
+
n_simulations=1_000_000, # 1 Million Paths
|
|
98
|
+
m_steps=252, # Daily observations
|
|
99
|
+
barrier_type=BarrierType.DOWN_AND_OUT,
|
|
100
|
+
barrier_level=85.0
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# The SDK detects 252,000,000 total steps.
|
|
104
|
+
# It delegates the matrix to the C++ cluster and waits for the resolution.
|
|
105
|
+
result = client.price(heavy_barrier)
|
|
106
|
+
|
|
107
|
+
print(f"Fair Value computed: {result.fair_value}")
|
|
108
|
+
print(f"Confidence Interval: [{result.ci_lower}, {result.ci_upper}]")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## 🛡️ Error Handling & Limits
|
|
112
|
+
|
|
113
|
+
The SDK translates HTTP status codes into strict Pythonic exceptions:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from prometheus_qengine.exceptions import InsufficientCreditsError, AuthenticationError
|
|
117
|
+
|
|
118
|
+
try:
|
|
119
|
+
result = client.price(option)
|
|
120
|
+
except InsufficientCreditsError as e:
|
|
121
|
+
print("Ledger depleted. Recharge required.")
|
|
122
|
+
except AuthenticationError as e:
|
|
123
|
+
print("Invalid API Key.")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## 📚 Documentation & Research
|
|
127
|
+
|
|
128
|
+
For in-depth mathematical proofs regarding our Finite Difference implementations, False Sharing mitigation in OpenMP, and structural REST API architecture, visit our [Papers](https://prometheusquantengine.com/papers) and [Api-docs](https://prometheusquantengine.com/web-docs).
|
|
129
|
+
|
|
130
|
+
## 📄 License
|
|
131
|
+
|
|
132
|
+
This SDK is distributed under the MIT License. See [`LICENSE`](https://github.com/Prometheus-Quant-Engineering/prometheus-quant-python/blob/main/LICENSE) for more information.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
prometheus_qengine/client.py
|
|
5
|
+
prometheus_qengine/enums.py
|
|
6
|
+
prometheus_qengine/exceptions.py
|
|
7
|
+
prometheus_qengine/init.py
|
|
8
|
+
prometheus_qengine/models.py
|
|
9
|
+
prometheus_qengine.egg-info/PKG-INFO
|
|
10
|
+
prometheus_qengine.egg-info/SOURCES.txt
|
|
11
|
+
prometheus_qengine.egg-info/dependency_links.txt
|
|
12
|
+
prometheus_qengine.egg-info/requires.txt
|
|
13
|
+
prometheus_qengine.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prometheus_qengine
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "prometheus-qengine"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Prometheus Quant Engineering", email="dev@prometheusquantengine.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "Official Python SDK for the Prometheus Quant Engine (HPC Monte Carlo)"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
19
|
+
"Topic :: Scientific/Engineering :: Mathematics",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"requests>=2.25.0",
|
|
23
|
+
"pydantic>=2.0.0",
|
|
24
|
+
"pandas>=1.3.0"
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
"Homepage" = "https://prometheusquantengine.com"
|
|
29
|
+
"Documentation" = "https://prometheusquantengine.com/web-docs"
|