vizflow 0.4.1__py3-none-any.whl → 0.4.2__py3-none-any.whl
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.
vizflow/__init__.py
CHANGED
|
@@ -5,10 +5,18 @@ Usage:
|
|
|
5
5
|
import vizflow as vf
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
__version__ = "0.4.
|
|
8
|
+
__version__ = "0.4.2"
|
|
9
9
|
|
|
10
10
|
from .config import ColumnSchema, Config, get_config, set_config
|
|
11
|
-
from .io import
|
|
11
|
+
from .io import (
|
|
12
|
+
load_alpha,
|
|
13
|
+
load_calendar,
|
|
14
|
+
load_trade,
|
|
15
|
+
scan_alpha,
|
|
16
|
+
scan_alphas,
|
|
17
|
+
scan_trade,
|
|
18
|
+
scan_trades,
|
|
19
|
+
)
|
|
12
20
|
from .market import CN, CRYPTO, Market, Session
|
|
13
21
|
from .ops import aggregate, bin, parse_time
|
|
14
|
-
from .presets import YLIN
|
|
22
|
+
from .presets import JYAO_V20251114, YLIN
|
vizflow/io.py
CHANGED
|
@@ -149,7 +149,7 @@ def scan_trade(date: str, config: Config | None = None) -> pl.LazyFrame:
|
|
|
149
149
|
config = config or get_config()
|
|
150
150
|
path = config.get_trade_path(date)
|
|
151
151
|
df = _scan_file(path)
|
|
152
|
-
return
|
|
152
|
+
return _apply_trade_mapping(df, config)
|
|
153
153
|
|
|
154
154
|
|
|
155
155
|
def scan_trades(config: Config | None = None) -> pl.LazyFrame:
|
|
@@ -185,19 +185,27 @@ def scan_trades(config: Config | None = None) -> pl.LazyFrame:
|
|
|
185
185
|
# Concatenate all files using lazy scanning
|
|
186
186
|
dfs = [_scan_file(f) for f in files]
|
|
187
187
|
df = pl.concat(dfs)
|
|
188
|
-
return
|
|
188
|
+
return _apply_trade_mapping(df, config)
|
|
189
189
|
|
|
190
190
|
|
|
191
|
-
def
|
|
192
|
-
"""Apply column rename + schema evolution.
|
|
191
|
+
def _apply_trade_mapping(df: pl.LazyFrame, config: Config) -> pl.LazyFrame:
|
|
192
|
+
"""Apply column rename + schema evolution for trade data."""
|
|
193
|
+
df = _apply_rename(df, config)
|
|
194
|
+
for col_name, schema in config.trade_schema.items():
|
|
195
|
+
df = df.with_columns(pl.col(col_name).cast(schema.cast_to))
|
|
196
|
+
return df
|
|
193
197
|
|
|
194
|
-
Args:
|
|
195
|
-
df: Input LazyFrame
|
|
196
|
-
config: Config with mapping settings
|
|
197
198
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
def _apply_alpha_mapping(df: pl.LazyFrame, config: Config) -> pl.LazyFrame:
|
|
200
|
+
"""Apply column rename + schema evolution for alpha data."""
|
|
201
|
+
df = _apply_rename(df, config)
|
|
202
|
+
for col_name, schema in config.alpha_schema.items():
|
|
203
|
+
df = df.with_columns(pl.col(col_name).cast(schema.cast_to))
|
|
204
|
+
return df
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _apply_rename(df: pl.LazyFrame, config: Config) -> pl.LazyFrame:
|
|
208
|
+
"""Apply column rename from preset or custom mapping."""
|
|
201
209
|
# Drop record type prefix column if present (from CSV files)
|
|
202
210
|
existing = set(df.collect_schema().names())
|
|
203
211
|
if "#HFTORD" in existing:
|
|
@@ -213,13 +221,60 @@ def _apply_mapping(df: pl.LazyFrame, config: Config) -> pl.LazyFrame:
|
|
|
213
221
|
if to_rename:
|
|
214
222
|
df = df.rename(to_rename)
|
|
215
223
|
|
|
216
|
-
# Schema evolution (type casting) - use renamed column names
|
|
217
|
-
for col_name, schema in config.trade_schema.items():
|
|
218
|
-
df = df.with_columns(pl.col(col_name).cast(schema.cast_to))
|
|
219
|
-
|
|
220
224
|
return df
|
|
221
225
|
|
|
222
226
|
|
|
227
|
+
def scan_alpha(date: str, config: Config | None = None) -> pl.LazyFrame:
|
|
228
|
+
"""Scan single date alpha file with column mapping.
|
|
229
|
+
|
|
230
|
+
Args:
|
|
231
|
+
date: Date string, e.g. "20241001"
|
|
232
|
+
config: Config to use, or get_config() if None
|
|
233
|
+
|
|
234
|
+
Returns:
|
|
235
|
+
LazyFrame with column mapping and schema evolution applied
|
|
236
|
+
|
|
237
|
+
Example:
|
|
238
|
+
>>> config = vf.Config(
|
|
239
|
+
... alpha_dir=Path("/data/jyao/alpha"),
|
|
240
|
+
... alpha_pattern="alpha_{date}.feather",
|
|
241
|
+
... column_preset="jyao_v20251114",
|
|
242
|
+
... )
|
|
243
|
+
>>> vf.set_config(config)
|
|
244
|
+
>>> df = vf.scan_alpha("20251114")
|
|
245
|
+
"""
|
|
246
|
+
config = config or get_config()
|
|
247
|
+
path = config.get_alpha_path(date)
|
|
248
|
+
df = _scan_file(path)
|
|
249
|
+
return _apply_alpha_mapping(df, config)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def scan_alphas(config: Config | None = None) -> pl.LazyFrame:
|
|
253
|
+
"""Scan all alpha files with column mapping.
|
|
254
|
+
|
|
255
|
+
Args:
|
|
256
|
+
config: Config to use, or get_config() if None
|
|
257
|
+
|
|
258
|
+
Returns:
|
|
259
|
+
LazyFrame with column mapping and schema evolution applied
|
|
260
|
+
|
|
261
|
+
Raises:
|
|
262
|
+
ValueError: If alpha_dir is not set or no files found
|
|
263
|
+
"""
|
|
264
|
+
config = config or get_config()
|
|
265
|
+
if config.alpha_dir is None:
|
|
266
|
+
raise ValueError("alpha_dir is not set in Config")
|
|
267
|
+
|
|
268
|
+
pattern = config.alpha_pattern.replace("{date}", "*")
|
|
269
|
+
files = sorted(config.alpha_dir.glob(pattern))
|
|
270
|
+
if not files:
|
|
271
|
+
raise ValueError(f"No files found matching {pattern} in {config.alpha_dir}")
|
|
272
|
+
|
|
273
|
+
dfs = [_scan_file(f) for f in files]
|
|
274
|
+
df = pl.concat(dfs)
|
|
275
|
+
return _apply_alpha_mapping(df, config)
|
|
276
|
+
|
|
277
|
+
|
|
223
278
|
def _get_rename_map(config: Config) -> dict[str, str]:
|
|
224
279
|
"""Get rename map from preset name or custom dict.
|
|
225
280
|
|
|
@@ -232,8 +287,11 @@ def _get_rename_map(config: Config) -> dict[str, str]:
|
|
|
232
287
|
if config.column_rename:
|
|
233
288
|
return config.column_rename
|
|
234
289
|
if config.column_preset:
|
|
235
|
-
from .presets import YLIN
|
|
290
|
+
from .presets import JYAO_V20251114, YLIN
|
|
236
291
|
|
|
237
|
-
presets = {
|
|
292
|
+
presets = {
|
|
293
|
+
"ylin": YLIN,
|
|
294
|
+
"jyao_v20251114": JYAO_V20251114,
|
|
295
|
+
}
|
|
238
296
|
return presets.get(config.column_preset.lower(), {})
|
|
239
297
|
return {}
|
vizflow/presets.py
CHANGED
|
@@ -61,3 +61,24 @@ YUANZHAO = {
|
|
|
61
61
|
|
|
62
62
|
# Alias: ylin (Yuanzhao's username)
|
|
63
63
|
YLIN = YUANZHAO
|
|
64
|
+
|
|
65
|
+
# jyao's alpha format (v2025-11-14)
|
|
66
|
+
JYAO_V20251114 = {
|
|
67
|
+
# Quote columns
|
|
68
|
+
"BidPrice1": "bid_px0",
|
|
69
|
+
"AskPrice1": "ask_px0",
|
|
70
|
+
"BidVolume1": "bid_size0",
|
|
71
|
+
"AskVolume1": "ask_size0",
|
|
72
|
+
# Time columns
|
|
73
|
+
"TimeStamp": "timestamp",
|
|
74
|
+
"GlobalExTime": "global_exchange_ts",
|
|
75
|
+
"DataDate": "data_date",
|
|
76
|
+
# Volume
|
|
77
|
+
"Volume": "volume",
|
|
78
|
+
# Alpha columns (Ŷ - predictions)
|
|
79
|
+
# Rule: ≤60s → s, >60s → m
|
|
80
|
+
"x10s": "alpha_10s",
|
|
81
|
+
"x60s": "alpha_60s",
|
|
82
|
+
"alpha1": "alpha_3m",
|
|
83
|
+
"alpha2": "alpha_30m",
|
|
84
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
vizflow/__init__.py,sha256=xqq6sMoOrly9Jo3B2mAJSe2yyeH5-h2862p9r5LUWf0,461
|
|
2
|
+
vizflow/config.py,sha256=IiVau-4WyO_7NOWlR7Tw58RpDeGFYBbgkNzH7xuQIUg,6544
|
|
3
|
+
vizflow/io.py,sha256=gtejbHRmgbClOGXrj6qfPw7Rz2LWmIFk2ohqlkPlY48,8874
|
|
4
|
+
vizflow/market.py,sha256=MtNz_nnZxC66Aq-i2PXEwaFCTknijFWYZUUv6798k2s,2493
|
|
5
|
+
vizflow/ops.py,sha256=NL-Gtv-m_O1hv-0RUb9Wt43916HsQ5tYK_0e_uKR90w,4062
|
|
6
|
+
vizflow/presets.py,sha256=3mkwDeAJqYAKnMzOWTHzevdsAmRzsgk0Y83Ml5aGXKM,2357
|
|
7
|
+
vizflow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
vizflow-0.4.2.dist-info/METADATA,sha256=_ASajAOnZZG49eLujsUzjHnCxJGj69Sryhjnf-pV1Qs,388
|
|
9
|
+
vizflow-0.4.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
+
vizflow-0.4.2.dist-info/RECORD,,
|
vizflow-0.4.1.dist-info/RECORD
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
vizflow/__init__.py,sha256=s03IltxCkl4odJo8ywVERpOD8Dl0GqOaKhFyELjGwM4,387
|
|
2
|
-
vizflow/config.py,sha256=IiVau-4WyO_7NOWlR7Tw58RpDeGFYBbgkNzH7xuQIUg,6544
|
|
3
|
-
vizflow/io.py,sha256=Z2W-jU8nrX52DjzzXCxfHkKSWl3AGnIUC3cFDg4dCTk,6906
|
|
4
|
-
vizflow/market.py,sha256=MtNz_nnZxC66Aq-i2PXEwaFCTknijFWYZUUv6798k2s,2493
|
|
5
|
-
vizflow/ops.py,sha256=NL-Gtv-m_O1hv-0RUb9Wt43916HsQ5tYK_0e_uKR90w,4062
|
|
6
|
-
vizflow/presets.py,sha256=RdxlFouysHBH8IftQx3v5e9Mq82DznxZFbMxv4w1vnA,1825
|
|
7
|
-
vizflow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
vizflow-0.4.1.dist-info/METADATA,sha256=qRa3pRup8YXzTvR9kxBFmhNZR_BBqsR1CkYrOa3t-As,388
|
|
9
|
-
vizflow-0.4.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
-
vizflow-0.4.1.dist-info/RECORD,,
|
|
File without changes
|