brain-decorrelator
Strategy-agnostic alpha decorrelation engine with AST-diff motifs, asymmetric veto memory, and plugin-based orthogonalization axes.
brain_decorrelator transforms correlated alpha expressions into orthogonal variants that pass WorldQuant BRAIN's correlation gate ($|\rho| < 0.70$) while preserving underlying economic Sharpe. Powered by AST-diff motif extraction and Asymmetric Veto Control (AlphaMemo, Yu et al. 2026), the engine proactively prunes known dead-end factor regions and prevents redundant submissions.
Installation
pip install brain-decorrelator
Quickstart
1. Basic Multi-Axis Decorrelation
from brain_decorrelator import DecorrelationEngine
engine = DecorrelationEngine()
# Automatically applies all 10 registered orthogonal axes
variants = engine.generate_orthogonal_variants(
base_expr="ts_decay_linear(implied_volatility_call_30, 10)",
archetype="iv_term_structure",
base_sharpe=1.65,
)
for v in variants:
print(f"[{v.axis_name}] -> {v.expression}")
2. AlphaMemo Asymmetric Veto Control
from brain_decorrelator import DecorrelationEngine, VetoMemory
# Initialize persistent collision memory
memory = VetoMemory(db_path="collisions.db")
engine = DecorrelationEngine(veto_memory=memory)
# If an alpha collided with peer 'alpha_WjbgwKPo' on BRAIN, record and prune:
variants = engine.generate_orthogonal_variants(
base_expr="group_neutralize(rank(close), subindustry)",
archetype="momentum",
colliding_id="alpha_WjbgwKPo",
universe="TOP3000",
)
3. Fast Expression AST Parser & Diff
from brain_decorrelator import parse_ast, unparse_ast
from brain_decorrelator.ast_engine import find_differing_subtrees
ast1 = parse_ast("ts_decay_linear(close, 10)")
ast2 = parse_ast("ts_decay_linear(volume, 10)")
# Extract differing operational motif
diffs = find_differing_subtrees(ast1, ast2)
print("Subtree difference:", diffs)
The 10 Orthogonal Axes
| Axis | Name | Transformation Logic | WorldQuant BRAIN Syntax | Typical $\rho$ | Sharpe Retention |
|---|---|---|---|---|---|
| 1 | Velocity Shift | Phase shift via rate-of-change and decay | ts_decay_linear(ts_delta(expr, 5), 10) |
0.35–0.50 | $85-92%$ |
| 2 | Calendar Spread | Differential across curve tenors | (field_30 - field_90) |
0.30–0.45 | $92-105%$ |
| 3 | Volume Regime | Liquidity-conditional trade gate | trade_when(volume > adv20 * 1.15, expr, -1) |
0.38–0.55 | $88-94%$ |
| 4 | Volatility Regime | Variance regime conditional gate | trade_when(volatility_120 > ts_mean(volatility_120, 20), expr, -1) |
0.45–0.60 | $90-96%$ |
| 5 | Neutralization Rotate | Subindustry ↔ Sector rotation | group_neutralize(rank(expr), sector) |
0.42–0.58 | $95-110%$ |
| 6 | Cross-Sectional Rank | Non-linear group ranking | group_rank(expr, subindustry) |
0.40–0.52 | $92-98%$ |
| 7 | Sector Demean (New) | Sector vs Subindustry residualization | group_neutralize(rank(expr) - group_rank(expr, sector), subindustry) |
0.25–0.40 | $95-108%$ |
| 8 | Vol Scaling (New) | Return volatility normalization | ts_decay_linear(expr / (ts_std_dev(returns, 60) + 0.001), 20) |
0.35–0.48 | $94-102%$ |
| 9 | Gram-Schmidt (New) | Market equity beta deflation | group_neutralize(rank(rank(expr) - 0.25 * rank(beta_spy)), group) |
0.30–0.42 | $90-95%$ |
| 10 | Decay Dilation (New) | Turnover compression (18d-30d) | ts_decay_linear(expr, 22) |
0.28–0.38 | $105-120%$ |
Extending with Custom Plugins
from brain_decorrelator import AxisPlugin, register_axis
@register_axis
class MoneynessInversionAxis(AxisPlugin):
name = "Axis 11 (Moneyness Inversion)"
def apply(self, expr: str, context: dict) -> list[str]:
return [f"-({expr})"]
Architecture
brain_decorrelator/
├── ast_engine/ # AlphaMemo AST parsing, tree diffing, and motif extraction
│ ├── parser.py # Tokenizer & Fast Expression recursive-descent parser
│ ├── diff.py # Tree-edit distance and structural motif signature
│ └── transformer.py # AST subtree mutation and identifier replacement
├── veto_memory/ # AlphaMemo asymmetric veto memory & collision store
│ ├── store.py # SQLite & in-memory collision cache
│ └── veto_gate.py # Pre-submission candidate pruning gate
├── axes/ # 10 built-in orthogonalization axes
│ ├── universal.py # Velocity, Calendar, Volume, Volatility, Neutralization, Rank
│ ├── sector_demean.py # Sector vs Subindustry residualization
│ ├── regime_conditional.py # Volatility return scaling
│ ├── gram_schmidt.py # Market beta deflation
│ └── decay_extension.py # Horizon dilation (turnover < 4.5%)
├── plugin.py # AxisPlugin ABC + thread-safe registry
├── engine.py # Master DecorrelationEngine orchestrator
└── py.typed # PEP 561 compliance marker
Testing
pytest tests/ -v
License
Released under the MIT License. Maintained by Xtley001.
Metadata
Release files for brain-decorrelator 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| brain_decorrelator-0.2.0.tar.gz | 21.7 kB | Without provenance | Details for brain_decorrelator-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| brain_decorrelator-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for brain_decorrelator-0.2.0-py3-none-any.whl |
Total release size: 44.2 kB
Release files / brain_decorrelator-0.2.0.tar.gz
| Download URL | brain_decorrelator-0.2.0.tar.gz |
|---|---|
| Size | 21.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fcd2eaa3a87a7313f78557256ff5c566e6ae7488d5e764990f57dcc3f650039a
|
|
BLAKE2b-256 checksum How to use checksums |
d50308463ccd79cce2af99ba5cf2a839f29a86e2d2f793ea467537fcaecae1aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.17
|
Release files / brain_decorrelator-0.2.0-py3-none-any.whl
| Download URL | brain_decorrelator-0.2.0-py3-none-any.whl |
|---|---|
| Size | 22.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9f6e96d5d1f01ca3499c7efd896547f5adf6eecc1a4aa7ff7213b0bcfc1fa803
|
|
BLAKE2b-256 checksum How to use checksums |
0b473cbb846c13902be6ccde4cc04d93c92203d26a332d450b649e11077e9f27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.17
|
Security for brain-decorrelator 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.