simudyne-pulse 0.9.0.dev5__tar.gz → 0.9.0.dev7__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.
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/PKG-INFO +2 -1
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/README.md +1 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/pyproject.toml +1 -1
- simudyne_pulse-0.9.0.dev7/src/simudyne/resources/data.py +470 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne/resources/simulation.py +351 -13
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne_pulse.egg-info/PKG-INFO +2 -1
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/tests/test_new_resources.py +133 -4
- simudyne_pulse-0.9.0.dev5/src/simudyne/resources/data.py +0 -372
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/LICENSE +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/setup.cfg +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne/__init__.py +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne/client.py +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne/exceptions.py +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne/resources/__init__.py +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne/resources/api_keys.py +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne/resources/fix.py +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne/resources/fm.py +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne/resources/profile.py +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne/resources/validation.py +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne_pulse.egg-info/SOURCES.txt +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne_pulse.egg-info/dependency_links.txt +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne_pulse.egg-info/requires.txt +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/src/simudyne_pulse.egg-info/top_level.txt +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/tests/test_api_contract.py +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/tests/test_retries.py +0 -0
- {simudyne_pulse-0.9.0.dev5 → simudyne_pulse-0.9.0.dev7}/tests/test_validation.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: simudyne-pulse
|
|
3
|
-
Version: 0.9.0.
|
|
3
|
+
Version: 0.9.0.dev7
|
|
4
4
|
Summary: Python SDK for the Simudyne Pulse synthetic market data API
|
|
5
5
|
Author-email: Simudyne <support@simudyne.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -195,6 +195,7 @@ client = PulseABM(api_key="pk_live_...") # or set SIMUDYNE_API_KEY
|
|
|
195
195
|
|
|
196
196
|
# Days the agent-based model can simulate
|
|
197
197
|
cal = client.data.calibrated_data(symbol="700.HK")
|
|
198
|
+
dates = [d["date"] for d in cal["symbols"][0]["dates"]]
|
|
198
199
|
|
|
199
200
|
# Run it, poll, read the generated book
|
|
200
201
|
job = client.simulation.run(
|
|
@@ -169,6 +169,7 @@ client = PulseABM(api_key="pk_live_...") # or set SIMUDYNE_API_KEY
|
|
|
169
169
|
|
|
170
170
|
# Days the agent-based model can simulate
|
|
171
171
|
cal = client.data.calibrated_data(symbol="700.HK")
|
|
172
|
+
dates = [d["date"] for d in cal["symbols"][0]["dates"]]
|
|
172
173
|
|
|
173
174
|
# Run it, poll, read the generated book
|
|
174
175
|
job = client.simulation.run(
|
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
"""Market data: what exists, what the agent-based model can simulate, and the
|
|
2
|
+
one action that moves a symbol-day from the first to the second.
|
|
3
|
+
|
|
4
|
+
Reached as ``client.data``. The three calls are one story:
|
|
5
|
+
|
|
6
|
+
available_data() every symbol-day in the registry
|
|
7
|
+
calibrate() calibrate one of them
|
|
8
|
+
calibrated_data() the ones the ABM can now simulate
|
|
9
|
+
|
|
10
|
+
A foundation-model run is prompted from anything in ``available_data``; an
|
|
11
|
+
agent-based run needs the day to appear in ``calibrated_data`` first.
|
|
12
|
+
|
|
13
|
+
``available_data`` and ``calibrated_data`` take the same filters and return the
|
|
14
|
+
same rows; the only difference is that the second keeps calibrated days only.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
AVAILABLE_DATA_PATH = "/data/available-data"
|
|
18
|
+
CALIBRATED_DATA_PATH = "/data/calibrated-data"
|
|
19
|
+
CALIBRATE_PATH = "/data/calibrate"
|
|
20
|
+
|
|
21
|
+
_FILTERS_DOC = """
|
|
22
|
+
symbol : str, optional
|
|
23
|
+
Exact symbol, e.g. "700" or "TSCO".
|
|
24
|
+
q : str, optional
|
|
25
|
+
Case-insensitive substring match over the symbol (and, for
|
|
26
|
+
calibrated days, the company name).
|
|
27
|
+
provider : str, optional
|
|
28
|
+
Data provider, e.g. "omd" or "bmll".
|
|
29
|
+
exchange : str, optional
|
|
30
|
+
Exchange protocol, e.g. "lse" or "hkex_securities".
|
|
31
|
+
date : str, optional
|
|
32
|
+
One trading date "YYYY-MM-DD". Keeps only instruments with that
|
|
33
|
+
day, and returns only that day. Not with ``date_from``/``date_to``.
|
|
34
|
+
date_from, date_to : str, optional
|
|
35
|
+
A date range "YYYY-MM-DD", inclusive.
|
|
36
|
+
calibration_status : {"calibrated", "failed", "in_progress"}, optional
|
|
37
|
+
Days whose LATEST calibration record says this. ``failed`` covers a
|
|
38
|
+
failure at any stage; the reason is in ``calibration_error``.
|
|
39
|
+
:meth:`calibrated_data` lists calibrated days only, so there
|
|
40
|
+
anything but "calibrated" matches nothing.
|
|
41
|
+
min_trades, max_trades, min_messages, max_messages, min_volume,
|
|
42
|
+
max_volume, min_spread_ticks, max_spread_ticks : number, optional
|
|
43
|
+
Bounds on a scanned day's measured stats. Demo tier.
|
|
44
|
+
tick_size, lot_size : float, optional
|
|
45
|
+
Scanned days with exactly this tick or lot size. Demo tier.
|
|
46
|
+
currency, instrument_type : str, optional
|
|
47
|
+
Scanned days in this currency (e.g. "GBp") or of this type
|
|
48
|
+
(e.g. "equity"). Demo tier.
|
|
49
|
+
calibratable : bool, optional
|
|
50
|
+
Scanned days that can (True) or cannot (False) be calibrated: a
|
|
51
|
+
day needs at least one trade and fewer than 10,000,000 messages.
|
|
52
|
+
Demo tier.
|
|
53
|
+
scanned_only : bool, default False
|
|
54
|
+
Only days the catalog has scanned. Demo tier.
|
|
55
|
+
include_stats : bool, default False
|
|
56
|
+
Add each scanned day's measured ``stats``. Demo tier; ``None`` on
|
|
57
|
+
every other tier.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
_ROWS_DOC = """
|
|
61
|
+
``{total, limit, offset, symbols}``, paged by instrument
|
|
62
|
+
(symbol, provider, exchange) so an instrument's dates are never
|
|
63
|
+
truncated; ``total`` is the match count before paging. Each
|
|
64
|
+
instrument has:
|
|
65
|
+
|
|
66
|
+
- symbol, provider, exchange
|
|
67
|
+
- company_name, instrument_type, currency, tick_size, lot_size
|
|
68
|
+
- date_count, calibrated_count, first_date, last_date
|
|
69
|
+
- avg_number_of_msgs, avg_volume_traded: over its calibrated days
|
|
70
|
+
- dates (list of dict), one per day:
|
|
71
|
+
|
|
72
|
+
- date (str), calibrated (bool)
|
|
73
|
+
- calibration_status: "calibrated", "failed", "in_progress", or
|
|
74
|
+
None if the day was never put through calibration, from the
|
|
75
|
+
day's LATEST calibration record
|
|
76
|
+
- calibration_stage, calibration_error, calibration_updated_at,
|
|
77
|
+
pulse_version, number_of_msgs, volume_traded, reference_price
|
|
78
|
+
- scanned, calibratable, not_calibratable_reason, event_counts,
|
|
79
|
+
stats: figures from the vendor data, demo tier only (None on
|
|
80
|
+
every other tier)
|
|
81
|
+
|
|
82
|
+
Filtering on a demo-tier field from another tier raises 403 rather
|
|
83
|
+
than returning an unfiltered answer.
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
#: On/off flags whose False is the server's default, so False is not sent.
|
|
88
|
+
#: (calibratable is not one: False asks for the days that CANNOT be calibrated.)
|
|
89
|
+
_DEFAULT_OFF_FLAGS = ("scanned_only", "include_stats")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _day_params(**filters) -> dict | None:
|
|
93
|
+
"""Query parameters for either catalog call, without unset filters."""
|
|
94
|
+
params = {
|
|
95
|
+
k: v for k, v in filters.items()
|
|
96
|
+
if v is not None and not (k in _DEFAULT_OFF_FLAGS and v is False)
|
|
97
|
+
}
|
|
98
|
+
return params or None
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class DataResource:
|
|
102
|
+
"""Browse the market data catalogue and calibrate days in it.
|
|
103
|
+
|
|
104
|
+
Reached as ``client.data``. Every simulation is pinned to a symbol-day, so
|
|
105
|
+
this is the resource that tells you which ``provider`` / ``exchange`` /
|
|
106
|
+
``symbol`` / ``cal_date`` combinations exist and which are ready to run.
|
|
107
|
+
|
|
108
|
+
Examples
|
|
109
|
+
--------
|
|
110
|
+
>>> catalog = client.data.calibrated_data(exchange="hkex_securities")
|
|
111
|
+
>>> for instrument in catalog["symbols"][:3]:
|
|
112
|
+
... print(instrument["symbol"], [d["date"] for d in instrument["dates"][:2]])
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
def __init__(self, client):
|
|
116
|
+
self._client = client
|
|
117
|
+
|
|
118
|
+
def available_data(
|
|
119
|
+
self,
|
|
120
|
+
model_id: str | None = None,
|
|
121
|
+
symbol: str | None = None,
|
|
122
|
+
q: str | None = None,
|
|
123
|
+
provider: str | None = None,
|
|
124
|
+
exchange: str | None = None,
|
|
125
|
+
date: str | None = None,
|
|
126
|
+
date_from: str | None = None,
|
|
127
|
+
date_to: str | None = None,
|
|
128
|
+
calibration_status: str | None = None,
|
|
129
|
+
min_trades: int | None = None,
|
|
130
|
+
max_trades: int | None = None,
|
|
131
|
+
min_messages: int | None = None,
|
|
132
|
+
max_messages: int | None = None,
|
|
133
|
+
min_volume: float | None = None,
|
|
134
|
+
max_volume: float | None = None,
|
|
135
|
+
min_spread_ticks: float | None = None,
|
|
136
|
+
max_spread_ticks: float | None = None,
|
|
137
|
+
tick_size: float | None = None,
|
|
138
|
+
lot_size: float | None = None,
|
|
139
|
+
currency: str | None = None,
|
|
140
|
+
instrument_type: str | None = None,
|
|
141
|
+
calibratable: bool | None = None,
|
|
142
|
+
scanned_only: bool = False,
|
|
143
|
+
include_stats: bool = False,
|
|
144
|
+
limit: int | None = None,
|
|
145
|
+
offset: int | None = None,
|
|
146
|
+
):
|
|
147
|
+
"""Every symbol-day in the data registry: what EXISTS, with its
|
|
148
|
+
calibration state.
|
|
149
|
+
|
|
150
|
+
The raw-data catalogue, so it answers both "what can a foundation model
|
|
151
|
+
be prompted with?" and "what could I calibrate?". :meth:`calibrated_data`
|
|
152
|
+
takes the same filters and returns the same rows, restricted to
|
|
153
|
+
calibrated days.
|
|
154
|
+
|
|
155
|
+
The catalogue holds the whole vendor universe (~15k symbols) and is
|
|
156
|
+
never returned whole, so narrow it with filters and page through it
|
|
157
|
+
with ``limit`` and ``offset``.
|
|
158
|
+
|
|
159
|
+
Parameters
|
|
160
|
+
----------
|
|
161
|
+
model_id : str, optional
|
|
162
|
+
A model from :meth:`~simudyne.resources.fm.FmResource.models`.
|
|
163
|
+
Keeps only the markets that model's ``supported_data`` declares, so
|
|
164
|
+
what comes back is exactly what it will accept at
|
|
165
|
+
:meth:`~simudyne.resources.simulation.SimulationResource.run` with
|
|
166
|
+
``engine="fm"``. A ``production_name`` (e.g. "flow-hkex-1-100M")
|
|
167
|
+
works too, matched as on ``run``. An unknown model raises (404),
|
|
168
|
+
and a name matching more than one model raises (400).
|
|
169
|
+
{filters}
|
|
170
|
+
limit : int, optional
|
|
171
|
+
Max instruments to return (1-200, default 50).
|
|
172
|
+
offset : int, optional
|
|
173
|
+
Instruments to skip, for paging alongside ``limit``.
|
|
174
|
+
|
|
175
|
+
Returns
|
|
176
|
+
-------
|
|
177
|
+
dict
|
|
178
|
+
{rows}
|
|
179
|
+
|
|
180
|
+
Raises
|
|
181
|
+
------
|
|
182
|
+
PulseAPIError
|
|
183
|
+
If the key is not pro or demo tier (403), or filters on a demo-tier
|
|
184
|
+
field from another tier (403); ``model_id`` names a model that is
|
|
185
|
+
not registered (404) or matches more than one (400); a date is not
|
|
186
|
+
``YYYY-MM-DD``, ``date`` is combined with a range,
|
|
187
|
+
``calibration_status`` is not one of the three values, ``limit`` is
|
|
188
|
+
outside 1-200 or ``offset`` is negative (422); or, with
|
|
189
|
+
``model_id``, the model registry (pulse-orchestrator) could not be
|
|
190
|
+
reached (502).
|
|
191
|
+
|
|
192
|
+
See Also
|
|
193
|
+
--------
|
|
194
|
+
calibrated_data : The subset the agent-based model can simulate.
|
|
195
|
+
calibrate : Move one symbol-day from here to there.
|
|
196
|
+
|
|
197
|
+
Examples
|
|
198
|
+
--------
|
|
199
|
+
Search the registry:
|
|
200
|
+
|
|
201
|
+
>>> page = client.data.available_data(q="tsc", exchange="lse")
|
|
202
|
+
>>> page["total"]
|
|
203
|
+
3
|
|
204
|
+
|
|
205
|
+
What one model can be prompted with, which is the usual pre-run call:
|
|
206
|
+
|
|
207
|
+
>>> page = client.data.available_data(model_id="pulse-lob-1", limit=20)
|
|
208
|
+
>>> first = page["symbols"][0]
|
|
209
|
+
>>> first["symbol"], [d["date"] for d in first["dates"][:2]]
|
|
210
|
+
('AZN', ['2026-06-22', '2026-06-23'])
|
|
211
|
+
|
|
212
|
+
Which of a symbol's days are calibrated, and why the others failed:
|
|
213
|
+
|
|
214
|
+
>>> entry = client.data.available_data(symbol="700")["symbols"][0]
|
|
215
|
+
>>> entry["date_count"], entry["calibrated_count"]
|
|
216
|
+
(60, 4)
|
|
217
|
+
>>> [(d["date"], d["calibration_error"]) for d in entry["dates"]
|
|
218
|
+
... if d["calibration_status"] == "failed"]
|
|
219
|
+
|
|
220
|
+
Days in a month whose latest calibration failed:
|
|
221
|
+
|
|
222
|
+
>>> page = client.data.available_data(
|
|
223
|
+
... exchange="lse", date_from="2025-07-01", date_to="2025-07-31",
|
|
224
|
+
... calibration_status="failed",
|
|
225
|
+
... )
|
|
226
|
+
|
|
227
|
+
Days that can be calibrated but are not yet (demo tier):
|
|
228
|
+
|
|
229
|
+
>>> page = client.data.available_data(
|
|
230
|
+
... exchange="lse", date_from="2025-07-01", date_to="2025-07-31",
|
|
231
|
+
... calibratable=True,
|
|
232
|
+
... )
|
|
233
|
+
"""
|
|
234
|
+
return self._client._request("GET", AVAILABLE_DATA_PATH, params=_day_params(
|
|
235
|
+
model_id=model_id, symbol=symbol, q=q, provider=provider, exchange=exchange,
|
|
236
|
+
date=date, date_from=date_from, date_to=date_to,
|
|
237
|
+
calibration_status=calibration_status,
|
|
238
|
+
min_trades=min_trades, max_trades=max_trades,
|
|
239
|
+
min_messages=min_messages, max_messages=max_messages,
|
|
240
|
+
min_volume=min_volume, max_volume=max_volume,
|
|
241
|
+
min_spread_ticks=min_spread_ticks, max_spread_ticks=max_spread_ticks,
|
|
242
|
+
tick_size=tick_size, lot_size=lot_size,
|
|
243
|
+
currency=currency, instrument_type=instrument_type,
|
|
244
|
+
calibratable=calibratable, scanned_only=scanned_only,
|
|
245
|
+
include_stats=include_stats, limit=limit, offset=offset,
|
|
246
|
+
))
|
|
247
|
+
|
|
248
|
+
def calibrated_data(
|
|
249
|
+
self,
|
|
250
|
+
symbol: str | None = None,
|
|
251
|
+
exchange: str | None = None,
|
|
252
|
+
provider: str | None = None,
|
|
253
|
+
date: str | None = None,
|
|
254
|
+
q: str | None = None,
|
|
255
|
+
date_from: str | None = None,
|
|
256
|
+
date_to: str | None = None,
|
|
257
|
+
calibration_status: str | None = None,
|
|
258
|
+
min_trades: int | None = None,
|
|
259
|
+
max_trades: int | None = None,
|
|
260
|
+
min_messages: int | None = None,
|
|
261
|
+
max_messages: int | None = None,
|
|
262
|
+
min_volume: float | None = None,
|
|
263
|
+
max_volume: float | None = None,
|
|
264
|
+
min_spread_ticks: float | None = None,
|
|
265
|
+
max_spread_ticks: float | None = None,
|
|
266
|
+
tick_size: float | None = None,
|
|
267
|
+
lot_size: float | None = None,
|
|
268
|
+
currency: str | None = None,
|
|
269
|
+
instrument_type: str | None = None,
|
|
270
|
+
calibratable: bool | None = None,
|
|
271
|
+
scanned_only: bool = False,
|
|
272
|
+
include_stats: bool = False,
|
|
273
|
+
limit: int | None = None,
|
|
274
|
+
offset: int | None = None,
|
|
275
|
+
):
|
|
276
|
+
"""Symbol-days the agent-based model can simulate: what is CALIBRATED.
|
|
277
|
+
|
|
278
|
+
A day is calibrated when its LATEST calibration record is a complete
|
|
279
|
+
model calibration, so a later failed re-run takes it out. Every day
|
|
280
|
+
here is a valid ``symbol`` / ``provider`` / ``exchange`` /
|
|
281
|
+
``cal_date`` for
|
|
282
|
+
:meth:`~simudyne.resources.simulation.SimulationResource.run` with
|
|
283
|
+
``engine="abm"``. Same filters and same rows as :meth:`available_data`;
|
|
284
|
+
:meth:`calibrate` is what moves a day from there to here.
|
|
285
|
+
|
|
286
|
+
Parameters
|
|
287
|
+
----------
|
|
288
|
+
{filters}
|
|
289
|
+
limit : int, optional
|
|
290
|
+
Max instruments to return, 1-1000. Omitted, the whole calibrated
|
|
291
|
+
catalogue comes back — it is far smaller than the registry.
|
|
292
|
+
offset : int, optional
|
|
293
|
+
Instruments to skip, for paging alongside ``limit``.
|
|
294
|
+
|
|
295
|
+
Returns
|
|
296
|
+
-------
|
|
297
|
+
dict
|
|
298
|
+
{rows}
|
|
299
|
+
|
|
300
|
+
Raises
|
|
301
|
+
------
|
|
302
|
+
PulseAPIError
|
|
303
|
+
If a filter on a demo-tier field comes from another tier (403), or
|
|
304
|
+
a date is not ``YYYY-MM-DD``, ``date`` is combined with a range,
|
|
305
|
+
``calibration_status`` is not one of the three values, ``limit`` is
|
|
306
|
+
outside 1-1000 or ``offset`` is negative (422). Available on every
|
|
307
|
+
tier.
|
|
308
|
+
|
|
309
|
+
See Also
|
|
310
|
+
--------
|
|
311
|
+
available_data : Everything that exists, calibrated or not.
|
|
312
|
+
|
|
313
|
+
Examples
|
|
314
|
+
--------
|
|
315
|
+
The whole calibrated catalogue:
|
|
316
|
+
|
|
317
|
+
>>> everything = client.data.calibrated_data()
|
|
318
|
+
>>> everything["total"]
|
|
319
|
+
412
|
|
320
|
+
|
|
321
|
+
One instrument, to see which dates it can be run for:
|
|
322
|
+
|
|
323
|
+
>>> hits = client.data.calibrated_data(symbol="700.HK")
|
|
324
|
+
>>> [d["date"] for d in hits["symbols"][0]["dates"]]
|
|
325
|
+
['2025-09-01', '2025-09-02', '2025-09-03']
|
|
326
|
+
|
|
327
|
+
Everything calibrated on one date, the usual way to pick a date that is
|
|
328
|
+
valid across several instruments:
|
|
329
|
+
|
|
330
|
+
>>> on_date = client.data.calibrated_data(date="2025-09-01")
|
|
331
|
+
|
|
332
|
+
Free-text search over ticker and company name, paged:
|
|
333
|
+
|
|
334
|
+
>>> page = client.data.calibrated_data(q="tencent", limit=10)
|
|
335
|
+
"""
|
|
336
|
+
return self._client._request("GET", CALIBRATED_DATA_PATH, params=_day_params(
|
|
337
|
+
symbol=symbol, q=q, provider=provider, exchange=exchange,
|
|
338
|
+
date=date, date_from=date_from, date_to=date_to,
|
|
339
|
+
calibration_status=calibration_status,
|
|
340
|
+
min_trades=min_trades, max_trades=max_trades,
|
|
341
|
+
min_messages=min_messages, max_messages=max_messages,
|
|
342
|
+
min_volume=min_volume, max_volume=max_volume,
|
|
343
|
+
min_spread_ticks=min_spread_ticks, max_spread_ticks=max_spread_ticks,
|
|
344
|
+
tick_size=tick_size, lot_size=lot_size,
|
|
345
|
+
currency=currency, instrument_type=instrument_type,
|
|
346
|
+
calibratable=calibratable, scanned_only=scanned_only,
|
|
347
|
+
include_stats=include_stats, limit=limit, offset=offset,
|
|
348
|
+
))
|
|
349
|
+
|
|
350
|
+
# The two calls share their filters and row shape, so their docs share the
|
|
351
|
+
# text too. (Docstrings are None under python -OO.)
|
|
352
|
+
for _method in (available_data, calibrated_data):
|
|
353
|
+
if _method.__doc__:
|
|
354
|
+
_method.__doc__ = _method.__doc__.replace(
|
|
355
|
+
"{filters}", _FILTERS_DOC.strip("\n").lstrip()
|
|
356
|
+
).replace("{rows}", _ROWS_DOC.strip("\n").lstrip())
|
|
357
|
+
del _method
|
|
358
|
+
|
|
359
|
+
def calibrate(
|
|
360
|
+
self,
|
|
361
|
+
symbol: str,
|
|
362
|
+
cal_date: str,
|
|
363
|
+
provider: str,
|
|
364
|
+
exchange: str,
|
|
365
|
+
simulations: int = None,
|
|
366
|
+
batch_size: int = None,
|
|
367
|
+
optimize_adj_params: bool = True,
|
|
368
|
+
):
|
|
369
|
+
"""Fit the agent-based model to one symbol-day.
|
|
370
|
+
|
|
371
|
+
Calibration is a data operation: its input is a day from
|
|
372
|
+
:meth:`available_data` and its output is an entry in
|
|
373
|
+
:meth:`calibrated_data`. It runs asynchronously — the call returns once
|
|
374
|
+
the job is queued, and the day appears in :meth:`calibrated_data` when
|
|
375
|
+
the pipeline finishes. Demo tier only.
|
|
376
|
+
|
|
377
|
+
A symbol is identified by four fields: ``provider``, ``exchange``,
|
|
378
|
+
``symbol`` and ``cal_date``.
|
|
379
|
+
|
|
380
|
+
Parameters
|
|
381
|
+
----------
|
|
382
|
+
symbol : str
|
|
383
|
+
Trading symbol, e.g. "9999.HK".
|
|
384
|
+
cal_date : str
|
|
385
|
+
Trading day in YYYY-MM-DD format.
|
|
386
|
+
provider : str
|
|
387
|
+
Data provider the symbol is sourced from: "omd" or "bmll".
|
|
388
|
+
exchange : str
|
|
389
|
+
Exchange protocol name, e.g. "hkex_securities".
|
|
390
|
+
simulations : int, optional
|
|
391
|
+
Number of simulations to run during calibration.
|
|
392
|
+
batch_size : int, optional
|
|
393
|
+
Batch size for calibration runs.
|
|
394
|
+
optimize_adj_params : bool, default True
|
|
395
|
+
Whether to optimise adjustment parameters.
|
|
396
|
+
|
|
397
|
+
Returns
|
|
398
|
+
-------
|
|
399
|
+
dict
|
|
400
|
+
status : str
|
|
401
|
+
"calibration_queued".
|
|
402
|
+
symbol : str
|
|
403
|
+
The symbol as submitted.
|
|
404
|
+
cal_date : str
|
|
405
|
+
The date as submitted.
|
|
406
|
+
|
|
407
|
+
There is no job id. Follow the day in :meth:`available_data`:
|
|
408
|
+
its ``calibration_status`` goes to "calibrated" when the pipeline
|
|
409
|
+
finishes, or to "failed" with the reason in ``calibration_error``.
|
|
410
|
+
|
|
411
|
+
Raises
|
|
412
|
+
------
|
|
413
|
+
PulseAPIError
|
|
414
|
+
If the key is not demo tier (403); ``provider`` or ``exchange`` is
|
|
415
|
+
not a recognised value (422); the day has no market data — a
|
|
416
|
+
weekend, an exchange holiday, a day the vendor did not deliver
|
|
417
|
+
(422); the catalog has scanned the day and it cannot be calibrated,
|
|
418
|
+
e.g. it has no trades (422, with the reason); or the calibration
|
|
419
|
+
service is unreachable (503). A day that is queued and then fails
|
|
420
|
+
shows up in :meth:`available_data` with ``calibration_status``
|
|
421
|
+
"failed" and the reason in ``calibration_error``.
|
|
422
|
+
|
|
423
|
+
See Also
|
|
424
|
+
--------
|
|
425
|
+
available_data : Days that exist and could be calibrated.
|
|
426
|
+
calibrated_data : Days already calibrated, where this one lands.
|
|
427
|
+
simudyne.resources.simulation.SimulationResource.run : Simulate a calibrated day.
|
|
428
|
+
|
|
429
|
+
Notes
|
|
430
|
+
-----
|
|
431
|
+
Calibration is only needed for a symbol-day that is not already
|
|
432
|
+
calibrated, and it is far slower than running against an existing
|
|
433
|
+
calibration. Check :meth:`calibrated_data` first — most instruments are
|
|
434
|
+
calibrated already.
|
|
435
|
+
|
|
436
|
+
Examples
|
|
437
|
+
--------
|
|
438
|
+
>>> job = client.data.calibrate(
|
|
439
|
+
... symbol="700.HK",
|
|
440
|
+
... cal_date="2025-09-02",
|
|
441
|
+
... provider="omd",
|
|
442
|
+
... exchange="hkex_securities",
|
|
443
|
+
... )
|
|
444
|
+
>>> job["status"]
|
|
445
|
+
'calibration_queued'
|
|
446
|
+
|
|
447
|
+
With an explicit budget, and adjustment-parameter optimisation off:
|
|
448
|
+
|
|
449
|
+
>>> job = client.data.calibrate(
|
|
450
|
+
... symbol="700.HK",
|
|
451
|
+
... cal_date="2025-09-02",
|
|
452
|
+
... provider="omd",
|
|
453
|
+
... exchange="hkex_securities",
|
|
454
|
+
... simulations=500,
|
|
455
|
+
... batch_size=50,
|
|
456
|
+
... optimize_adj_params=False,
|
|
457
|
+
... )
|
|
458
|
+
"""
|
|
459
|
+
payload: dict = {
|
|
460
|
+
"symbol": symbol,
|
|
461
|
+
"cal_date": cal_date,
|
|
462
|
+
"provider": provider,
|
|
463
|
+
"exchange": exchange,
|
|
464
|
+
"optimize_adj_params": optimize_adj_params,
|
|
465
|
+
}
|
|
466
|
+
if simulations is not None:
|
|
467
|
+
payload["simulations"] = simulations
|
|
468
|
+
if batch_size is not None:
|
|
469
|
+
payload["batch_size"] = batch_size
|
|
470
|
+
return self._client._request("POST", CALIBRATE_PATH, json=payload)
|