vizflow 0.5.7__py3-none-any.whl → 0.5.9__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 +2 -1
- vizflow/ops.py +9 -18
- vizflow/schema_evolution.py +2 -0
- vizflow/viz.py +35 -0
- {vizflow-0.5.7.dist-info → vizflow-0.5.9.dist-info}/METADATA +1 -1
- vizflow-0.5.9.dist-info/RECORD +11 -0
- vizflow-0.5.7.dist-info/RECORD +0 -10
- {vizflow-0.5.7.dist-info → vizflow-0.5.9.dist-info}/WHEEL +0 -0
vizflow/__init__.py
CHANGED
|
@@ -5,7 +5,7 @@ Usage:
|
|
|
5
5
|
import vizflow as vf
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
__version__ = "0.5.
|
|
8
|
+
__version__ = "0.5.8"
|
|
9
9
|
|
|
10
10
|
from .config import Config, get_config, set_config
|
|
11
11
|
from .io import (
|
|
@@ -19,6 +19,7 @@ from .io import (
|
|
|
19
19
|
)
|
|
20
20
|
from .market import CN, CRYPTO, Market, Session
|
|
21
21
|
from .ops import aggregate, bin, forward_return, mark_to_close, parse_time, sign_by_side
|
|
22
|
+
from .viz import add_tod
|
|
22
23
|
from .schema_evolution import (
|
|
23
24
|
JYAO_V20251114,
|
|
24
25
|
SCHEMAS,
|
vizflow/ops.py
CHANGED
|
@@ -11,19 +11,20 @@ def parse_time(
|
|
|
11
11
|
df: pl.LazyFrame,
|
|
12
12
|
timestamp_col: str = "ticktime",
|
|
13
13
|
) -> pl.LazyFrame:
|
|
14
|
-
"""Parse HHMMSSMMM timestamp to
|
|
14
|
+
"""Parse HHMMSSMMM timestamp to elapsed milliseconds.
|
|
15
15
|
|
|
16
|
-
Adds
|
|
17
|
-
- tod_{timestamp_col}: pl.Time (time-of-day HH:MM:SS.mmm) - good for plotting
|
|
16
|
+
Adds one column:
|
|
18
17
|
- elapsed_{timestamp_col}: pl.Int64 (milliseconds since market open)
|
|
19
18
|
|
|
19
|
+
For time-of-day column (pl.Time) for plotting, use vf.add_tod() separately.
|
|
20
|
+
|
|
20
21
|
Args:
|
|
21
22
|
df: Input LazyFrame
|
|
22
23
|
timestamp_col: Column with integer HHMMSSMMM format timestamps
|
|
23
24
|
e.g., 93012145 = 09:30:12.145, 142058425 = 14:20:58.425
|
|
24
25
|
|
|
25
26
|
Returns:
|
|
26
|
-
LazyFrame with
|
|
27
|
+
LazyFrame with elapsed column added
|
|
27
28
|
|
|
28
29
|
Raises:
|
|
29
30
|
RuntimeError: If config not set via set_config()
|
|
@@ -33,7 +34,7 @@ def parse_time(
|
|
|
33
34
|
>>> config = vf.Config(market="CN", input_dir=".", output_dir=".")
|
|
34
35
|
>>> vf.set_config(config)
|
|
35
36
|
>>> df = vf.parse_time(df, "ticktime")
|
|
36
|
-
>>> # Creates:
|
|
37
|
+
>>> # Creates: elapsed_ticktime (pl.Int64)
|
|
37
38
|
"""
|
|
38
39
|
config = get_config()
|
|
39
40
|
|
|
@@ -48,19 +49,8 @@ def parse_time(
|
|
|
48
49
|
(pl.col(timestamp_col) % 1000).alias("_ms"),
|
|
49
50
|
])
|
|
50
51
|
|
|
51
|
-
# Add time-of-day column (pl.Time)
|
|
52
|
-
# Convert to nanoseconds since midnight
|
|
53
|
-
tod_ns = (
|
|
54
|
-
pl.col("_hour") * 3_600_000_000_000
|
|
55
|
-
+ pl.col("_minute") * 60_000_000_000
|
|
56
|
-
+ pl.col("_second") * 1_000_000_000
|
|
57
|
-
+ pl.col("_ms") * 1_000_000
|
|
58
|
-
)
|
|
59
|
-
df = df.with_columns(tod_ns.cast(pl.Time).alias(f"tod_{timestamp_col}"))
|
|
60
|
-
|
|
61
52
|
# Add elapsed milliseconds (int)
|
|
62
53
|
# CN market: 09:30-11:30 (morning), 13:00-15:00 (afternoon)
|
|
63
|
-
# Using user's hardcoded logic
|
|
64
54
|
elapsed_ms = (
|
|
65
55
|
pl.when(pl.col("_hour") < 12)
|
|
66
56
|
.then(
|
|
@@ -226,11 +216,12 @@ def forward_return(
|
|
|
226
216
|
)
|
|
227
217
|
|
|
228
218
|
# Add forward price and calculate return (guard against zero price)
|
|
219
|
+
# Explicitly cast to Float64 to ensure consistent schema across dates
|
|
229
220
|
trade = joined.with_columns([
|
|
230
|
-
pl.col("_forward_price").alias(forward_col),
|
|
221
|
+
pl.col("_forward_price").cast(pl.Float64).alias(forward_col),
|
|
231
222
|
pl.when(pl.col(price_col) != 0)
|
|
232
223
|
.then((pl.col("_forward_price") - pl.col(price_col)) / pl.col(price_col))
|
|
233
|
-
.otherwise(pl.lit(None))
|
|
224
|
+
.otherwise(pl.lit(None, dtype=pl.Float64))
|
|
234
225
|
.alias(return_col),
|
|
235
226
|
]).drop(["_forward_time", "_alpha_time", "_forward_price"])
|
|
236
227
|
|
vizflow/schema_evolution.py
CHANGED
|
@@ -337,6 +337,8 @@ JYAO_V20251114 = SchemaEvolution(
|
|
|
337
337
|
# Symbol column - parse_dtype for CSV, cast_dtype for feather/IPC
|
|
338
338
|
# (feather files have embedded types, so cast is needed post-load)
|
|
339
339
|
"ukey": ColumnSpec(parse_dtype=pl.Int64, cast_dtype=pl.Int64),
|
|
340
|
+
# Time columns
|
|
341
|
+
"ticktime": ColumnSpec(parse_dtype=pl.Int64, cast_dtype=pl.Int64),
|
|
340
342
|
# Quote columns
|
|
341
343
|
"BidPrice1": ColumnSpec(rename_to="bid_px0", parse_dtype=pl.Float64),
|
|
342
344
|
"AskPrice1": ColumnSpec(rename_to="ask_px0", parse_dtype=pl.Float64),
|
vizflow/viz.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Visualization utilities for VizFlow."""
|
|
2
|
+
|
|
3
|
+
import polars as pl
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def add_tod(
|
|
7
|
+
df: pl.LazyFrame,
|
|
8
|
+
timestamp_col: str = "ticktime",
|
|
9
|
+
) -> pl.LazyFrame:
|
|
10
|
+
"""Add time-of-day column for plotting.
|
|
11
|
+
|
|
12
|
+
Converts HHMMSSMMM integer timestamp to pl.Time for visualization.
|
|
13
|
+
Note: pl.Time type is not supported by Delta Lake - use this only
|
|
14
|
+
for plotting, not for data that will be written to Delta Lake.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
df: Input LazyFrame with HHMMSSMMM timestamp column
|
|
18
|
+
timestamp_col: Column with integer HHMMSSMMM format timestamps
|
|
19
|
+
e.g., 93012145 = 09:30:12.145, 142058425 = 14:20:58.425
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
LazyFrame with tod_{timestamp_col} (pl.Time) column added
|
|
23
|
+
|
|
24
|
+
Example:
|
|
25
|
+
>>> df = vf.add_tod(df, "ticktime")
|
|
26
|
+
>>> # Creates: tod_ticktime (pl.Time)
|
|
27
|
+
"""
|
|
28
|
+
# Parse HHMMSSMMM to nanoseconds since midnight
|
|
29
|
+
tod_ns = (
|
|
30
|
+
(pl.col(timestamp_col) // 10000000) * 3_600_000_000_000
|
|
31
|
+
+ (pl.col(timestamp_col) // 100000 % 100) * 60_000_000_000
|
|
32
|
+
+ (pl.col(timestamp_col) // 1000 % 100) * 1_000_000_000
|
|
33
|
+
+ (pl.col(timestamp_col) % 1000) * 1_000_000
|
|
34
|
+
)
|
|
35
|
+
return df.with_columns(tod_ns.cast(pl.Time).alias(f"tod_{timestamp_col}"))
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
vizflow/__init__.py,sha256=KGksMU9wGsdGSbd2OgSHM2ofMZbTwgaCN92ZDEgASwU,614
|
|
2
|
+
vizflow/config.py,sha256=nPZPXlqQbaY8u_FAdtPShvb0mdx3e2TRaQ2CILzliAU,7192
|
|
3
|
+
vizflow/io.py,sha256=1T7t-L1ijrfEkE-gr4f45yiupJKA4-DxbJhsyN_tLnI,11939
|
|
4
|
+
vizflow/market.py,sha256=MtNz_nnZxC66Aq-i2PXEwaFCTknijFWYZUUv6798k2s,2493
|
|
5
|
+
vizflow/ops.py,sha256=cUFeDdWfMk2hG8hpevTz_Dfnzk3fnhTI79UwMGzUkHw,10534
|
|
6
|
+
vizflow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
vizflow/schema_evolution.py,sha256=HuyfHNGXUS82_oat1aSixd3msvOnBC9l5u0ec01blck,16447
|
|
8
|
+
vizflow/viz.py,sha256=dzcY72hWMVbxWIyjwfUW3Ot3CunaP7O4GLVUzzOjkbY,1212
|
|
9
|
+
vizflow-0.5.9.dist-info/METADATA,sha256=wrZtGCshKtCZDr96T8QfmYvdhBi7x2y0Bc_Fe5eAiC4,388
|
|
10
|
+
vizflow-0.5.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
11
|
+
vizflow-0.5.9.dist-info/RECORD,,
|
vizflow-0.5.7.dist-info/RECORD
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
vizflow/__init__.py,sha256=_jP6bp5U2iBFkPGTSLNwvOQay9XU_opNdrylF22iR9s,589
|
|
2
|
-
vizflow/config.py,sha256=nPZPXlqQbaY8u_FAdtPShvb0mdx3e2TRaQ2CILzliAU,7192
|
|
3
|
-
vizflow/io.py,sha256=1T7t-L1ijrfEkE-gr4f45yiupJKA4-DxbJhsyN_tLnI,11939
|
|
4
|
-
vizflow/market.py,sha256=MtNz_nnZxC66Aq-i2PXEwaFCTknijFWYZUUv6798k2s,2493
|
|
5
|
-
vizflow/ops.py,sha256=oR44HYKrfaXLh0SmbfXefl714UESSIC5lTNJBrR1kto,10858
|
|
6
|
-
vizflow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
vizflow/schema_evolution.py,sha256=3_qFIQJAgXUK0vQzanb355YVjytmfOACkelZlykIO8w,16349
|
|
8
|
-
vizflow-0.5.7.dist-info/METADATA,sha256=nkd-hejnIVFMaJzYnQP6EIHRkrJfBDsohONlj4zFVu4,388
|
|
9
|
-
vizflow-0.5.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
-
vizflow-0.5.7.dist-info/RECORD,,
|
|
File without changes
|