vizflow 0.4.1__py3-none-any.whl → 0.4.3__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 +11 -3
- vizflow/config.py +3 -3
- vizflow/io.py +85 -28
- vizflow/presets.py +28 -4
- {vizflow-0.4.1.dist-info → vizflow-0.4.3.dist-info}/METADATA +1 -1
- vizflow-0.4.3.dist-info/RECORD +10 -0
- vizflow-0.4.1.dist-info/RECORD +0 -10
- {vizflow-0.4.1.dist-info → vizflow-0.4.3.dist-info}/WHEEL +0 -0
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.3"
|
|
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
|
|
22
|
+
from .presets import JYAO_V20251114, PRESETS, YLIN_V20251204
|
vizflow/config.py
CHANGED
|
@@ -70,9 +70,9 @@ class Config:
|
|
|
70
70
|
alpha_schema: dict[str, ColumnSchema] = field(default_factory=dict)
|
|
71
71
|
trade_schema: dict[str, ColumnSchema] = field(default_factory=dict)
|
|
72
72
|
|
|
73
|
-
# === Column Mapping ===
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
# === Column Mapping Presets ===
|
|
74
|
+
trade_preset: str | None = None # "ylin" or None
|
|
75
|
+
alpha_preset: str | None = None # "jyao_v20251114" or None
|
|
76
76
|
|
|
77
77
|
# === Aggregation ===
|
|
78
78
|
binwidths: dict[str, float] = field(default_factory=dict)
|
vizflow/io.py
CHANGED
|
@@ -141,7 +141,7 @@ def scan_trade(date: str, config: Config | None = None) -> pl.LazyFrame:
|
|
|
141
141
|
>>> config = vf.Config(
|
|
142
142
|
... trade_dir=Path("/data/yuanzhao/"),
|
|
143
143
|
... trade_pattern="{date}.meords",
|
|
144
|
-
...
|
|
144
|
+
... trade_preset="ylin_v20251204",
|
|
145
145
|
... )
|
|
146
146
|
>>> vf.set_config(config)
|
|
147
147
|
>>> df = vf.scan_trade("20241001")
|
|
@@ -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:
|
|
@@ -168,7 +168,7 @@ def scan_trades(config: Config | None = None) -> pl.LazyFrame:
|
|
|
168
168
|
>>> config = vf.Config(
|
|
169
169
|
... trade_dir=Path("/data/yuanzhao/"),
|
|
170
170
|
... trade_pattern="{date}.feather",
|
|
171
|
-
...
|
|
171
|
+
... trade_preset="ylin_v20251204",
|
|
172
172
|
... )
|
|
173
173
|
>>> vf.set_config(config)
|
|
174
174
|
>>> df = vf.scan_trades()
|
|
@@ -185,18 +185,31 @@ 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.trade_preset)
|
|
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
|
-
|
|
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.alpha_preset)
|
|
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, preset: str | None) -> pl.LazyFrame:
|
|
208
|
+
"""Apply column rename from preset name.
|
|
209
|
+
|
|
210
|
+
Args:
|
|
211
|
+
df: LazyFrame to rename columns
|
|
212
|
+
preset: Preset name (e.g., "ylin", "jyao_v20251114") or None
|
|
200
213
|
"""
|
|
201
214
|
# Drop record type prefix column if present (from CSV files)
|
|
202
215
|
existing = set(df.collect_schema().names())
|
|
@@ -204,8 +217,8 @@ def _apply_mapping(df: pl.LazyFrame, config: Config) -> pl.LazyFrame:
|
|
|
204
217
|
df = df.drop("#HFTORD")
|
|
205
218
|
existing.remove("#HFTORD")
|
|
206
219
|
|
|
207
|
-
# Get rename map from preset
|
|
208
|
-
rename_map = _get_rename_map(
|
|
220
|
+
# Get rename map from preset
|
|
221
|
+
rename_map = _get_rename_map(preset)
|
|
209
222
|
|
|
210
223
|
if rename_map:
|
|
211
224
|
existing = set(df.collect_schema().names())
|
|
@@ -213,27 +226,71 @@ def _apply_mapping(df: pl.LazyFrame, config: Config) -> pl.LazyFrame:
|
|
|
213
226
|
if to_rename:
|
|
214
227
|
df = df.rename(to_rename)
|
|
215
228
|
|
|
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
229
|
return df
|
|
221
230
|
|
|
222
231
|
|
|
223
|
-
def
|
|
224
|
-
"""
|
|
232
|
+
def scan_alpha(date: str, config: Config | None = None) -> pl.LazyFrame:
|
|
233
|
+
"""Scan single date alpha file with column mapping.
|
|
225
234
|
|
|
226
235
|
Args:
|
|
227
|
-
|
|
236
|
+
date: Date string, e.g. "20241001"
|
|
237
|
+
config: Config to use, or get_config() if None
|
|
238
|
+
|
|
239
|
+
Returns:
|
|
240
|
+
LazyFrame with column mapping and schema evolution applied
|
|
241
|
+
|
|
242
|
+
Example:
|
|
243
|
+
>>> config = vf.Config(
|
|
244
|
+
... alpha_dir=Path("/data/jyao/alpha"),
|
|
245
|
+
... alpha_pattern="alpha_{date}.feather",
|
|
246
|
+
... alpha_preset="jyao_v20251114",
|
|
247
|
+
... )
|
|
248
|
+
>>> vf.set_config(config)
|
|
249
|
+
>>> df = vf.scan_alpha("20251114")
|
|
250
|
+
"""
|
|
251
|
+
config = config or get_config()
|
|
252
|
+
path = config.get_alpha_path(date)
|
|
253
|
+
df = _scan_file(path)
|
|
254
|
+
return _apply_alpha_mapping(df, config)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def scan_alphas(config: Config | None = None) -> pl.LazyFrame:
|
|
258
|
+
"""Scan all alpha files with column mapping.
|
|
259
|
+
|
|
260
|
+
Args:
|
|
261
|
+
config: Config to use, or get_config() if None
|
|
262
|
+
|
|
263
|
+
Returns:
|
|
264
|
+
LazyFrame with column mapping and schema evolution applied
|
|
265
|
+
|
|
266
|
+
Raises:
|
|
267
|
+
ValueError: If alpha_dir is not set or no files found
|
|
268
|
+
"""
|
|
269
|
+
config = config or get_config()
|
|
270
|
+
if config.alpha_dir is None:
|
|
271
|
+
raise ValueError("alpha_dir is not set in Config")
|
|
272
|
+
|
|
273
|
+
pattern = config.alpha_pattern.replace("{date}", "*")
|
|
274
|
+
files = sorted(config.alpha_dir.glob(pattern))
|
|
275
|
+
if not files:
|
|
276
|
+
raise ValueError(f"No files found matching {pattern} in {config.alpha_dir}")
|
|
277
|
+
|
|
278
|
+
dfs = [_scan_file(f) for f in files]
|
|
279
|
+
df = pl.concat(dfs)
|
|
280
|
+
return _apply_alpha_mapping(df, config)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _get_rename_map(preset: str | None) -> dict[str, str]:
|
|
284
|
+
"""Get rename map from preset name.
|
|
285
|
+
|
|
286
|
+
Args:
|
|
287
|
+
preset: Preset name (e.g., "ylin_v20251204", "jyao_v20251114") or None
|
|
228
288
|
|
|
229
289
|
Returns:
|
|
230
290
|
Dict mapping old column names to new names
|
|
231
291
|
"""
|
|
232
|
-
if
|
|
233
|
-
return
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
presets = {"ylin": YLIN}
|
|
238
|
-
return presets.get(config.column_preset.lower(), {})
|
|
239
|
-
return {}
|
|
292
|
+
if not preset:
|
|
293
|
+
return {}
|
|
294
|
+
from .presets import PRESETS
|
|
295
|
+
|
|
296
|
+
return PRESETS.get(preset.lower(), {})
|
vizflow/presets.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Column mapping presets for VizFlow."""
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
|
|
3
|
+
# ylin's trade format (v2025-12-04)
|
|
4
|
+
YLIN_V20251204 = {
|
|
5
5
|
# Order columns (18)
|
|
6
6
|
"symbol": "ukey",
|
|
7
7
|
"orderId": "order_id",
|
|
@@ -59,5 +59,29 @@ YUANZHAO = {
|
|
|
59
59
|
"globalCumSellNotional": "cum_sell_filled_notional",
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
#
|
|
63
|
-
|
|
62
|
+
# jyao's alpha format (v2025-11-14)
|
|
63
|
+
JYAO_V20251114 = {
|
|
64
|
+
# Quote columns
|
|
65
|
+
"BidPrice1": "bid_px0",
|
|
66
|
+
"AskPrice1": "ask_px0",
|
|
67
|
+
"BidVolume1": "bid_size0",
|
|
68
|
+
"AskVolume1": "ask_size0",
|
|
69
|
+
# Time columns
|
|
70
|
+
"TimeStamp": "timestamp",
|
|
71
|
+
"GlobalExTime": "global_exchange_ts",
|
|
72
|
+
"DataDate": "data_date",
|
|
73
|
+
# Volume
|
|
74
|
+
"Volume": "volume",
|
|
75
|
+
# Alpha columns (Ŷ - predictions)
|
|
76
|
+
# Rule: ≤60s → s, >60s → m
|
|
77
|
+
"x10s": "alpha_10s",
|
|
78
|
+
"x60s": "alpha_60s",
|
|
79
|
+
"alpha1": "alpha_3m",
|
|
80
|
+
"alpha2": "alpha_30m",
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
# Preset registry for dynamic lookup
|
|
84
|
+
PRESETS: dict[str, dict[str, str]] = {
|
|
85
|
+
"ylin_v20251204": YLIN_V20251204,
|
|
86
|
+
"jyao_v20251114": JYAO_V20251114,
|
|
87
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
vizflow/__init__.py,sha256=yZZ76XlpFGgaBxlMINGLysOHdjCosqZ5I6tE-1P9KJI,480
|
|
2
|
+
vizflow/config.py,sha256=zSZnhdHzgXSqhDenHcHKm4CDGrMpKAdkNNRoUYYF1uc,6530
|
|
3
|
+
vizflow/io.py,sha256=zmN0fFQOTmSBEBKangMExr0Q5mC2gajZM6GgdAyWkw4,8824
|
|
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=brvYVJyc6fEgFoEz8JIJv8NqZVvaGK27_vq_GiBe82s,2457
|
|
7
|
+
vizflow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
vizflow-0.4.3.dist-info/METADATA,sha256=P2kaZ25OcLDtnUceLTecMskv9wmuY_sdfR_MK4iKZjk,388
|
|
9
|
+
vizflow-0.4.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
+
vizflow-0.4.3.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
|