factorflow 0.1.0__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.
- factorflow/__init__.py +59 -0
- factorflow/bars.py +246 -0
- factorflow/batch.py +221 -0
- factorflow/events.py +610 -0
- factorflow/graph.py +177 -0
- factorflow/grid.py +298 -0
- factorflow/kernels.py +434 -0
- factorflow/live.py +554 -0
- factorflow/panel.py +181 -0
- factorflow/py.typed +0 -0
- factorflow/sim/__init__.py +22 -0
- factorflow/sim/__main__.py +210 -0
- factorflow/sim/bench.py +130 -0
- factorflow/sim/market.py +669 -0
- factorflow/sim/pipelines.py +147 -0
- factorflow/sim/replay.py +385 -0
- factorflow/sim/validate.py +464 -0
- factorflow/terms.py +1921 -0
- factorflow-0.1.0.dist-info/METADATA +368 -0
- factorflow-0.1.0.dist-info/RECORD +23 -0
- factorflow-0.1.0.dist-info/WHEEL +4 -0
- factorflow-0.1.0.dist-info/licenses/LICENSE +202 -0
- factorflow-0.1.0.dist-info/licenses/NOTICE +14 -0
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: factorflow
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Pipeline-style factor engine on a bar grid with batch and incremental (open-bar) execution
|
|
5
|
+
Project-URL: Repository, https://github.com/humdings/factorflow
|
|
6
|
+
Project-URL: Changelog, https://github.com/humdings/factorflow/blob/main/CHANGELOG.md
|
|
7
|
+
Project-URL: Documentation, https://humdings.github.io/factorflow/
|
|
8
|
+
Author-email: David Edwards <humdings@gmail.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Requires-Dist: exchange-calendars>=4.5
|
|
22
|
+
Requires-Dist: numpy>=2.0
|
|
23
|
+
Requires-Dist: pandas>=2.0
|
|
24
|
+
Requires-Dist: polars>=1.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: hypothesis>=6.100; extra == 'dev'
|
|
27
|
+
Requires-Dist: interrogate>=1.7; extra == 'dev'
|
|
28
|
+
Requires-Dist: pyright>=1.1.380; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
31
|
+
Provides-Extra: docs
|
|
32
|
+
Requires-Dist: mkdocs>=1.6; extra == 'docs'
|
|
33
|
+
Requires-Dist: mkdocstrings[python]>=0.27; extra == 'docs'
|
|
34
|
+
Provides-Extra: notebook
|
|
35
|
+
Requires-Dist: ipykernel>=7.4.0; extra == 'notebook'
|
|
36
|
+
Requires-Dist: matplotlib>=3.11.2; extra == 'notebook'
|
|
37
|
+
Requires-Dist: nbconvert>=7.17.2; extra == 'notebook'
|
|
38
|
+
Requires-Dist: nbformat>=5.11.1; extra == 'notebook'
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
|
|
41
|
+
# factorflow
|
|
42
|
+
|
|
43
|
+
[](https://github.com/humdings/factorflow/actions/workflows/ci.yml)
|
|
44
|
+
[](LICENSE)
|
|
45
|
+
[](https://pypi.org/project/factorflow/)
|
|
46
|
+
[](https://humdings.github.io/factorflow/)
|
|
47
|
+
|
|
48
|
+
factorflow evaluates factor, filter, and classifier expressions on bars. The same pipeline
|
|
49
|
+
runs two ways, and the two ways agree:
|
|
50
|
+
|
|
51
|
+
- **Batch.** `BatchEngine` computes every row of a history in one pass. Use it for research and backtests.
|
|
52
|
+
- **Live.** `LiveEngine` keeps that history and recomputes only the **open bar**, the last row, which is still provisional. `revise()` updates that row. `seal()` closes it. A sealed row matches the batch result on the same inputs. A revision matches a batch run that treats the open bar as final.
|
|
53
|
+
|
|
54
|
+
Every live value carries an open/sealed flag (`Snapshot.is_open`, and an `is_open` column in frames).
|
|
55
|
+
|
|
56
|
+
Bars are either clock-time (one grid for every asset) or information-driven (tick, volume, or dollar bars, per asset). The library does not load data and does not talk to a broker. You pass a `Panel` or a trade stream.
|
|
57
|
+
|
|
58
|
+
Inspired by [Zipline's Pipeline](https://github.com/quantopian/zipline) API. This is an independent implementation.
|
|
59
|
+
|
|
60
|
+

|
|
61
|
+
|
|
62
|
+
API reference: <https://humdings.github.io/factorflow/> (published from `main` once GitHub Pages is enabled). The PyPI badge starts working when the package is published. Until then, install from a checkout or from git.
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
Python 3.11 or newer.
|
|
67
|
+
|
|
68
|
+
From a checkout, with pip:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip install .
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
For tests and the notebook:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install -e ".[dev]"
|
|
78
|
+
pip install -e ".[notebook]"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
With [uv](https://docs.astral.sh/uv/), which is what the Nix shell and CI use:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
uv sync
|
|
85
|
+
uv run python examples/quickstart.py
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
With Nix, from the flake:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
nix develop # uv + Python, UV_PYTHON set
|
|
92
|
+
nix build # the package
|
|
93
|
+
nix flake check # build and tests, skipping tests marked slow
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Another Nix project can take this flake as an input and use the overlay. `python3.pkgs.factorflow` is then on that package set:
|
|
97
|
+
|
|
98
|
+
```nix
|
|
99
|
+
inputs.factorflow.url = "github:humdings/factorflow";
|
|
100
|
+
nixpkgs.overlays = [ inputs.factorflow.overlays.default ];
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The package version in this tree is 0.1.0. It is not on PyPI yet. Install from a checkout or from git:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
pip install "factorflow @ git+https://github.com/humdings/factorflow.git"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Quickstart
|
|
110
|
+
|
|
111
|
+
`examples/quickstart.py` is the listing below. It builds a seeded random walk, scores it, checks that the live engine matches batch, then builds volume bars and clock bars from a handful of trades. No data files.
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
python examples/quickstart.py
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
"""Self-contained factorflow quickstart on synthetic data.
|
|
119
|
+
|
|
120
|
+
No market feed and no saved fixtures: prices are a seeded random walk, and the
|
|
121
|
+
clock comes from ``BarGrid``. Run from a checkout with the package installed:
|
|
122
|
+
|
|
123
|
+
python examples/quickstart.py
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
from __future__ import annotations
|
|
127
|
+
|
|
128
|
+
import numpy as np
|
|
129
|
+
|
|
130
|
+
import factorflow as ff
|
|
131
|
+
|
|
132
|
+
NS = 1_000_000_000
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class RangePos(ff.Factor):
|
|
136
|
+
"""Where the latest value sits in its rolling high-low range, in ``[0, 1]``.
|
|
137
|
+
|
|
138
|
+
A window with any missing input, or a zero range, is missing (NaN).
|
|
139
|
+
``compute`` receives ``(T_in, N)`` blocks and returns ``T_in - window + 1`` rows.
|
|
140
|
+
Batch calls it on the whole history. Live calls it on exactly ``window`` rows
|
|
141
|
+
and reads row 0, so both paths run this function.
|
|
142
|
+
"""
|
|
143
|
+
|
|
144
|
+
def __init__(self, source: ff.Factor, window: int):
|
|
145
|
+
if window < 2:
|
|
146
|
+
raise ValueError("window must be >= 2")
|
|
147
|
+
self.inputs = (source,)
|
|
148
|
+
self.window = int(window)
|
|
149
|
+
self.params = (self.window,)
|
|
150
|
+
|
|
151
|
+
def compute(self, blocks, prev=None):
|
|
152
|
+
x = np.asarray(blocks[0], dtype=np.float64)
|
|
153
|
+
w = self.window
|
|
154
|
+
out = np.empty((x.shape[0] - w + 1, x.shape[1]), dtype=np.float64)
|
|
155
|
+
for i in range(out.shape[0]):
|
|
156
|
+
window = x[i : i + w]
|
|
157
|
+
lo = np.min(window, axis=0)
|
|
158
|
+
hi = np.max(window, axis=0)
|
|
159
|
+
span = hi - lo
|
|
160
|
+
with np.errstate(invalid="ignore", divide="ignore"):
|
|
161
|
+
pos = (window[-1] - lo) / span
|
|
162
|
+
missing = np.isnan(window).any(axis=0) | (span == 0)
|
|
163
|
+
out[i] = np.where(missing, np.nan, pos)
|
|
164
|
+
return out
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def main() -> None:
|
|
168
|
+
rng = np.random.default_rng(0)
|
|
169
|
+
assets = ("AAA", "BBB", "CCC", "DDD")
|
|
170
|
+
n_bars, n = 40, len(assets)
|
|
171
|
+
|
|
172
|
+
# 24/7 one-minute bars. grace=0 seals a bar as soon as time reaches its end.
|
|
173
|
+
# "5min", "1h" and "1d" are the same idea; "XNYS" uses the exchange calendar.
|
|
174
|
+
grid = ff.BarGrid("24/7", "1min", grace=0)
|
|
175
|
+
starts, ends = grid.bars("2026-01-05", "2026-01-05")
|
|
176
|
+
starts, ends = starts[:n_bars], ends[:n_bars]
|
|
177
|
+
|
|
178
|
+
shock = rng.normal(0, 0.004, size=(n_bars, n))
|
|
179
|
+
close = 100 * np.exp(np.cumsum(shock, axis=0))
|
|
180
|
+
volume = rng.integers(50, 500, size=(n_bars, n)).astype(np.float64)
|
|
181
|
+
sector = np.tile(np.array([0, 0, 1, 1], dtype=np.int64), (n_bars, 1))
|
|
182
|
+
panel = ff.Panel(ends, assets, {"close": close, "volume": volume, "sector": sector}, starts)
|
|
183
|
+
|
|
184
|
+
close_t = ff.Column("close")
|
|
185
|
+
volume_t = ff.Column("volume")
|
|
186
|
+
sector_t = ff.Column("sector", ff.Classifier)
|
|
187
|
+
ret = close_t.pct_change(1)
|
|
188
|
+
universe = (close_t * volume_t).rolling_mean(10).top(3)
|
|
189
|
+
score = close_t.pct_change(10).zscore(groupby=sector_t, mask=universe)
|
|
190
|
+
pipe = ff.Pipeline({"score": score, "ret": ret, "range_pos": RangePos(close_t, 10)}, screen=universe)
|
|
191
|
+
|
|
192
|
+
batch = ff.BatchEngine().run(pipe, panel)
|
|
193
|
+
print(batch.frame().tail(4))
|
|
194
|
+
|
|
195
|
+
# Warm the live engine on every sealed bar but the last, then revise that open bar.
|
|
196
|
+
live = ff.LiveEngine(pipe, panel.head(n_bars - 1), grid)
|
|
197
|
+
last = n_bars - 1
|
|
198
|
+
live.set_open("close", close[last])
|
|
199
|
+
live.set_open("volume", volume[last])
|
|
200
|
+
live.set_open("sector", sector[last])
|
|
201
|
+
snap = live.revise()
|
|
202
|
+
assert snap.is_open
|
|
203
|
+
sealed = live.seal()
|
|
204
|
+
assert sealed.is_open is False
|
|
205
|
+
for name in ("score", "ret", "range_pos"):
|
|
206
|
+
np.testing.assert_array_equal(sealed.values[name], batch.values[name][last])
|
|
207
|
+
print("sealed live row matches batch, including the custom factor")
|
|
208
|
+
|
|
209
|
+
# Information-driven bars. Twelve trades of 10 shares close a bar every 30 shares.
|
|
210
|
+
ts = np.arange(12) * NS
|
|
211
|
+
price = 100 + np.arange(12, dtype=np.float64)
|
|
212
|
+
size = np.full(12, 10.0)
|
|
213
|
+
bars, open_bar = ff.build_event_bars(ts, price, size, "volume", ff.Fixed(30))
|
|
214
|
+
assert len(bars) == 4 and open_bar is None
|
|
215
|
+
print(f"volume bars: {len(bars)} sealed, no open bar")
|
|
216
|
+
|
|
217
|
+
# Clock bars from a few trades. Empty minutes carry the previous close forward.
|
|
218
|
+
base = int(starts[0])
|
|
219
|
+
trade_ts = np.array([base + NS, base + 20 * NS, base + 5 * NS])
|
|
220
|
+
order = np.argsort(trade_ts)
|
|
221
|
+
trades = ff.Trades(
|
|
222
|
+
asset=np.array([0, 0, 1])[order],
|
|
223
|
+
ts=trade_ts[order],
|
|
224
|
+
price=np.array([10.0, 12.0, 20.0])[order],
|
|
225
|
+
size=np.array([5.0, 1.0, 4.0])[order],
|
|
226
|
+
)
|
|
227
|
+
built = ff.build_time_bars(trades, ("AAA", "BBB"), starts[:3], ends[:3])
|
|
228
|
+
np.testing.assert_array_equal(built.columns["close"][:, 0], [12.0, 12.0, 12.0])
|
|
229
|
+
np.testing.assert_array_equal(built.columns["volume"][:, 0], [6.0, 0.0, 0.0])
|
|
230
|
+
print("clock bars: first minute traded, later minutes forward-filled the close")
|
|
231
|
+
|
|
232
|
+
xnys = ff.BarGrid("XNYS", "1min")
|
|
233
|
+
early = xnys.bars("2026-11-27", "2026-11-27")[1]
|
|
234
|
+
regular = xnys.bars("2026-11-30", "2026-11-30")[1]
|
|
235
|
+
holiday = xnys.bars("2026-11-26", "2026-11-26")[1]
|
|
236
|
+
print(f"XNYS 1min bars: early close {len(early)}, regular session {len(regular)}, holiday {len(holiday)}")
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
if __name__ == "__main__":
|
|
240
|
+
main()
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
The run ends with:
|
|
244
|
+
|
|
245
|
+
```text
|
|
246
|
+
sealed live row matches batch, including the custom factor
|
|
247
|
+
volume bars: 4 sealed, no open bar
|
|
248
|
+
clock bars: first minute traded, later minutes forward-filled the close
|
|
249
|
+
XNYS 1min bars: early close 210, regular session 390, holiday 0
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`2026-11-26` is Thanksgiving (no session). `2026-11-27` is an early close, 210 minute bars instead of 390.
|
|
253
|
+
|
|
254
|
+
## Concepts
|
|
255
|
+
|
|
256
|
+
### Panels, columns, pipelines
|
|
257
|
+
|
|
258
|
+
A `Panel` is a dense time-by-asset block. `times` are bar-end timestamps in nanoseconds UTC. `columns` maps a name to a `(T, N)` array. `Panel.from_frame` builds one from a long polars frame with `ts` and `asset` columns.
|
|
259
|
+
|
|
260
|
+
`Column("close")` reads a float column. `Column("sector", Classifier)` reads integer group codes (`-1` is missing). `BarData` is the columns a bar builder fills: `open`, `high`, `low`, `close`, `volume`, `dollar`, `n_ticks`, and the filter `has_trade`.
|
|
261
|
+
|
|
262
|
+
Factors support arithmetic and comparisons. Comparisons produce filters. Useful built-ins include `shift`, `delta`, `pct_change`, `rolling_sum`, `rolling_mean`, `rolling_std`, `rolling_min`, `rolling_max`, `ts_rank`, `rolling_cov`, `rolling_corr`, `rolling_beta`, `ewm_mean`, `rank`, `zscore`, `demean`, `top`, and `bottom`. `rank`, `zscore`, and `demean` take `mask=` and `groupby=`. `where(condition, a, b)` is the conditional.
|
|
263
|
+
|
|
264
|
+
A `Pipeline` names the outputs and may set a `screen` filter. `BatchEngine().run(pipeline, panel)` returns a `BatchResult`. `result.frame()` is a long polars frame of the rows that pass the screen. `result.values` still holds the full `(T, N)` arrays.
|
|
265
|
+
|
|
266
|
+
Windows that contain a missing value yield a missing value. That matches the usual Pipeline rule.
|
|
267
|
+
|
|
268
|
+
### Batch and live
|
|
269
|
+
|
|
270
|
+
`LiveEngine(pipeline, history, grid)` warms from `history`, which should already be sealed bars, and opens the next bar on `grid`.
|
|
271
|
+
|
|
272
|
+
- `tick(asset, ts, price, size)` folds a trade into the open bar. With a grid, it first seals any bar whose end plus grace is at or before `ts`.
|
|
273
|
+
- `set_bar(...)` replaces one asset's open OHLCV, for when a data source already publishes the in-progress bar.
|
|
274
|
+
- `set_open(column, values)` sets a column that is not a bar field (a sector code, a signal) on the open row.
|
|
275
|
+
- `revise()` recomputes the open row and returns a `Snapshot` with `is_open=True`. It does not commit state.
|
|
276
|
+
- `seal()` commits the open row and starts the next one. Missing assets carry the previous close forward and set volume to zero.
|
|
277
|
+
- `advance(now)` seals every bar with `end + grace <= now`, including empty bars.
|
|
278
|
+
|
|
279
|
+
Pass callables in `observers`. They are called with each snapshot whose outputs changed.
|
|
280
|
+
|
|
281
|
+
Without a grid, the caller decides when a bar ends and calls `seal(ts)`. That is how event bars drive a pipeline.
|
|
282
|
+
|
|
283
|
+
Each kernel is one function of a window of rows. Batch calls it on the whole history. Live calls it on the last `window` rows and keeps row 0. Both run the same arithmetic in the same order, which is why sealed rows match.
|
|
284
|
+
|
|
285
|
+
### Custom factors
|
|
286
|
+
|
|
287
|
+
Subclass `Factor` (or `Filter`, or `Classifier`). Set `inputs`, `window`, and `params`, and implement `compute(blocks, prev=None)`. `blocks[i]` has shape `(T_in, N)`. Return an array of shape `(T_in - window + 1, N)`. `RangePos` in the quickstart is a complete example.
|
|
288
|
+
|
|
289
|
+
`params` is part of the term's identity, so two windows of the same class are not collapsed into one node. `columnwise = True` (the default) means output column `j` depends only on input column `j`. Set `columnwise = False` for a term that mixes assets, and set `rowwise = True` if you implement `compute_row` instead of a whole-window `compute`.
|
|
290
|
+
|
|
291
|
+
### Bar sizes
|
|
292
|
+
|
|
293
|
+
A clock grid is a calendar times a frequency:
|
|
294
|
+
|
|
295
|
+
| Construction | What you get |
|
|
296
|
+
|---|---|
|
|
297
|
+
| `BarGrid("XNYS", "1d")` | One bar per regular session. Grace defaults to 0. The last bar of a session ends at the close, so early closes are shorter days. |
|
|
298
|
+
| `BarGrid("XNYS", "1min")` | Regular-session minutes, 390 on a full day. Grace defaults to 2 seconds. |
|
|
299
|
+
| `BarGrid("XNYS", "5min")`, `"1h"`, `"30s"` | The same calendar, other frequencies. `parse_freq` accepts `s`, `min`, `h`, and `d`. |
|
|
300
|
+
| `BarGrid("24/7", "1min")` | A continuous UTC clock, including weekends. `"247"`, `"ALWAYS_OPEN"`, and `"CRYPTO"` are the same calendar. |
|
|
301
|
+
|
|
302
|
+
`grid.bars(start, end)` returns `(starts, ends)` in nanoseconds UTC for every session date from `start` through `end`. Bars are half-open `[start, end)` and labeled by `end`. A trade at `ts` belongs to the first bar with `end > ts`.
|
|
303
|
+
|
|
304
|
+
`build_time_bars(trades, assets, starts, ends)` aggregates a `Trades` stream (parallel arrays, sorted by timestamp) onto those bars. An empty bar repeats the previous close and stores zero volume. Before an asset's first trade the close is missing.
|
|
305
|
+
|
|
306
|
+
Information-driven bars close when a measure reaches a threshold. The measure is `1` (tick), `size` (volume), or `price * size` (dollar).
|
|
307
|
+
|
|
308
|
+
```python
|
|
309
|
+
ff.build_event_bars(
|
|
310
|
+
ts, price, size, "dollar", ff.AdaptiveDaily(bars_per_day=50, lookback_days=20, initial=1_000_000)
|
|
311
|
+
)
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
`Fixed(value)` holds the threshold constant. `AdaptiveDaily` sets each day's threshold from the mean daily measure over the previous `lookback_days` completed days, divided by `bars_per_day`. Days with no trades are skipped, and the threshold does not use the current day's volume. Until enough days exist, `initial` is the threshold.
|
|
315
|
+
|
|
316
|
+
`overshoot="close"` (the default) puts the whole crossing trade in the bar it completes, so the measure can exceed the threshold by less than one trade. `overshoot="split"` cuts that trade so each bar holds exactly the threshold. Tick bars are never split.
|
|
317
|
+
|
|
318
|
+
`EventPipeline(pipeline, builder, history, asset=...)` runs one asset live: each sealed event bar seals a row, and the open event bar is the open row. `update(ts, price, size)` returns those snapshots.
|
|
319
|
+
|
|
320
|
+
Event bars are not a shared clock. To rank assets against each other, sample each asset's last sealed event bar onto a grid with `sample_panel` (batch) or `AsofSampler` (live). The sample uses the last event bar with `end` strictly before the grid bar's end. Open event bars are not sampled.
|
|
321
|
+
|
|
322
|
+
Details, including the point-in-time rule for adaptive thresholds, are in [`docs/BARS.md`](docs/BARS.md).
|
|
323
|
+
|
|
324
|
+
## A larger synthetic market
|
|
325
|
+
|
|
326
|
+
`factorflow.sim` builds a seeded market with a known factor model, so you can check the engine without a data feed. Equities follow an exchange calendar. A second book trades every hour of the week. The generator plants a signal with a known information coefficient.
|
|
327
|
+
|
|
328
|
+
This run uses 20 names, 40 daily sessions, and two intraday sessions. The first
|
|
329
|
+
intraday session warms the minute engine; the second is replayed and checked
|
|
330
|
+
against batch. One intraday session leaves the minute replay with nothing to seal.
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
python -m factorflow.sim validate --names 20 --history-days 40 --intraday-days 2
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
The same entry point takes `demo` and `bench`. `demo` replays the last session through `LiveEngine` and exits non-zero if any sealed row differs from batch. `--seconds` is how long the live table runs, in wall-clock seconds.
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
python -m factorflow.sim demo --names 20 --history-days 60 --intraday-days 2 --seconds 1 --speed 600
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
`examples/demo.ipynb` is that simulation with plots. Execute it with the notebook extra installed:
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
python -m nbconvert --execute --to notebook --inplace examples/demo.ipynb
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
## Development
|
|
349
|
+
|
|
350
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) and the [code of conduct](CODE_OF_CONDUCT.md).
|
|
351
|
+
Security reports go through [private vulnerability reporting](https://github.com/humdings/factorflow/security/advisories/new). See [SECURITY.md](SECURITY.md).
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
pytest
|
|
355
|
+
ruff check .
|
|
356
|
+
pyright
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
The API reference is generated from the docstrings and published to <https://humdings.github.io/factorflow/> after GitHub Pages is enabled.
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
pip install -e ".[docs]"
|
|
363
|
+
mkdocs build --strict
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
## License
|
|
367
|
+
|
|
368
|
+
Apache License 2.0. Copyright 2026 David Edwards. See `LICENSE` and `NOTICE`.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
factorflow/__init__.py,sha256=tbtkJ33iMF4D8P1lOiEhO7XNphcewMJKQtQizkfggYo,1396
|
|
2
|
+
factorflow/bars.py,sha256=pc3D-sXXoBZ-x5MAzIELW-HaZ5U9UedyEFA7YseOeyo,8334
|
|
3
|
+
factorflow/batch.py,sha256=5dGsuU0ejQpeAmwDsBPTci3GAzLhudaMkM7MF16J_5Q,7761
|
|
4
|
+
factorflow/events.py,sha256=Ne1gyzGQN-fSFJf28gO3jo5pxw1-yQUT8WO0vIHhF6Y,21277
|
|
5
|
+
factorflow/graph.py,sha256=zD6zP3bDas4oMMZIThaLzVCfvUWPW93ynLy6FllUQ-o,6196
|
|
6
|
+
factorflow/grid.py,sha256=HkopN1Lh-MQK33rWn5zd2OYziyNTMVD5M1psmaDXQ1k,10976
|
|
7
|
+
factorflow/kernels.py,sha256=hXvRy_5pZvntNVc-TnX4_3EyBVsuqo9MtbeJxsCqySo,13046
|
|
8
|
+
factorflow/live.py,sha256=BSpJdWnlbXmFlPXQFHdGVUNP-aIOdm4CBWv_g0Ck1xw,21050
|
|
9
|
+
factorflow/panel.py,sha256=YSXHkS0nwnvHQ8iRgZkDEhrYEiMlJppO-nACezRgEtk,6270
|
|
10
|
+
factorflow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
factorflow/terms.py,sha256=IgyMBI9CWl07JaXnjwncSUG-2n0Q_55T175cIwmCb1c,53323
|
|
12
|
+
factorflow/sim/__init__.py,sha256=DZ4i6xUyo64ovSkGyPGbjvR3X8_THgPebSaEUtlt6rA,742
|
|
13
|
+
factorflow/sim/__main__.py,sha256=j3zK_Od9Wy17NWmaBLY--RIqnIGkQu082v4ePDnCAME,7933
|
|
14
|
+
factorflow/sim/bench.py,sha256=jW1Tw8CiKY2H--rYMUpOrEvZM9J9-so2VVavJBpQXuY,4822
|
|
15
|
+
factorflow/sim/market.py,sha256=Iwo2hr3bE9HPnJruYej6NSPA_OMoieUW3-wpBMvW_5U,26068
|
|
16
|
+
factorflow/sim/pipelines.py,sha256=j6OmRRZ7oo8fzz_7KfkScdqm0lsc7oXsrLnJFS0dZr8,5123
|
|
17
|
+
factorflow/sim/replay.py,sha256=cy5yoBhgOxSKBDLf1XHWM9EocvHyT9mWDXQJfgbH-4A,14635
|
|
18
|
+
factorflow/sim/validate.py,sha256=IEJSrLVtY9XyfYwDcotcz3vn2_em_47j8h6CwYfKPKs,17071
|
|
19
|
+
factorflow-0.1.0.dist-info/METADATA,sha256=_WrvotI7O-Oh3pOK0YObYxn3Y2KX9KZEXt9b1nRt7QE,17682
|
|
20
|
+
factorflow-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
21
|
+
factorflow-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
22
|
+
factorflow-0.1.0.dist-info/licenses/NOTICE,sha256=6ycixDkPJrQDQL7Bc2bSf3A39mA83nUSMlW4w3YnH9g,565
|
|
23
|
+
factorflow-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
factorflow
|
|
2
|
+
Copyright 2026 David Edwards
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|