◆FORGEfeature-oriented rule generation engine
GitHub ↗ PyPI ↗

Quantitative research · Python

Every pattern
deserves an honest verdict.

FORGE is an open-source engine for the systematic discovery of algorithmic trading rules from historical market data. It takes a KPI table, extracts events with stable temporal structure, measures their predictive power, and puts them through a realistic backtest — strictly separating every stage so the signal never "learns" the future ahead of time.

5
pipeline modules
0
dependencies beyond numpy/pandas
4
possible verdicts
MIT
license

The problem

"It would have worked in the past" is the most dangerous sentence in quant research.

Given enough time, any pattern can be made to look like an edge: just pick the right thresholds after seeing the returns. FORGE exists to close three recurring gaps, one by one.

01

Look-ahead bias

If an event's threshold is chosen by looking at how much it returns, the threshold already "knows" the future. Every backtest that follows is circular, not predictive.

02

In-sample optimisation

Searching for the best horizon, take-profit and filter on the same data used to measure the Profit Factor produces a PF that reflects sample noise, not real structure.

03

Statistics ≠ profitability

A statistically predictive event is not automatically profitable: fees, unfilled limit orders and horizons that must close regardless change everything.

5-module pipeline

Each module answers exactly one question, and passes forward only a formal artefact.

No module accesses the next module's data. No threshold is recalibrated after discovery. The flow runs in one direction only: from the KPI table to the final report.

0

Market Context regime classification

Classifies every bar of the KPI table by market regime across 5 levels, so the discovered edge can later be read for context dependency too.

Output → regime, regime_stable
1

Event Discovery no forward return

Discovers boolean conditions purely from the temporal structure of indicators — frequency, dispersion, monthly stability. The forward return never enters this module.

Output → list[EventCandidate]
2

Alpha Discovery data-derived target

First exposure to the forward return. Horizon, direction and take-profit are never assumed: they are measured per event and confirmed on an out-of-sample tail never touched before.

Output → list[AlphaContract]
3

Rule Discovery realistic backtest

Order mechanics, per-side fees, market or limit entry, walk-forward validation on rolling windows. This is where the operational verdict is born.

Output → EDGE / PARTIAL-EDGE / NON-EDGE + operational parameters
4

Rule Registry cross-ticker generalisation

Deduplicates discovered rules, re-backtests them on other assets, and classifies them by genericity. Produces a flat table and a self-contained HTML report.

Output → table + report.html (inline SVG, no CDN)

Three concepts, three boundaries

Event, Alpha, Rule: from market to signal, no shortcuts.

A trading signal is born only at the intersection of all three assessments — never from just one of them.

"Is this market configuration stable and repeatable?"

Event

A boolean condition on distributional thresholds — percentiles computed on the specific asset, not absolute values — fixed before a single forward return is ever computed.

Gate → ConsistencyGate (frequency, dispersion, no forward return)

"Does this event statistically predict an oriented return?"

Alpha

Horizon, direction and take-profit derived from the data by scanning a grid and standardising against a circular rotation null — never imposed by the user.

Gate → direction ≠ "undetermined" (the only hard gate)

"Is this alpha profitable under real order mechanics?"

Rule

A backtest with fees, realistic fills and walk-forward validation on rolling train/test windows — the final verdict, not an estimate.

Gate → EDGE / PARTIAL-EDGE / NON-EDGE / INSUFFICIENT-DATA

The final output

Never a black-box score. Always a reasoned verdict.

Rule Discovery integrates hard and soft gates — Profit Factor, win rate, deflated Sharpe, regime dependency, walk-forward consistency — into one of the four outcomes below.

EDGE

PF ≥ 2.0, win rate ≥ 55%, walk-forward consistency ≥ 50%, beats the session-level rotation null.

PARTIAL-EDGE

Clears the hard gates but not every EDGE gate: real evidence, not yet operationally solid.

NON-EDGE

PF < 1.5, every month negative, or no configuration with an adequate fill rate.

INSUFFICIENT-DATA

OOS evidence too thin for a confident judgement — not tradeable, but not discarded: re-assessed as more data arrives.

What it prevents, not what it promises

Four invariants the pipeline cannot violate.

InvariantWhat it prevents
Module 1 never sees the forward return Look-ahead bias in event selection
Thresholds are immutable after discovery Threshold optimisation on the evaluation sample
Horizon, direction and take-profit are derived from data per event Economic assumptions pre-baking the result
The tradeable verdict is gated by walk-forward OOS (Module 3) Post-hoc confirmation of a foregone conclusion

Quick start

From KPI table to validated rules, in a single call.

FORGE depends solely on numpy and pandas. All statistical primitives — Spearman, t-test, OU regression, Benjamini-Hochberg FDR, incomplete beta — are implemented in pure numpy: no dependency on scipy, statsmodels or ML libraries.

$ pip install forgedge
single ticker
from forgedge import forge

kpi = pd.read_parquet("kpi_table.parquet")
result = forge(kpi, ticker="BTCUSDC", timeframe="1H")

print(result.summary())
# one row per candidate + rule_verdict

print(result.registry.summary())
# Module 4 — catalogued rules
multi-ticker + report
from forgedge import forge_multi

frames = {"BTCUSDC": btc, "ETHUSDC": eth}
results, registry = forge_multi(frames, timeframe="1H")

# GENERIC: rule holds on ≥ 2/3 of tickers
df = registry.flat_table()

html = registry.html_report(timeframe="1H")
open("report.html", "w").write(html)
# inline SVG, self-contained, no CDN