Views
No views yet
This is a Python application, not a model. It generates candidate BRAIN expressions for manual review and submission.
| Mode | What it does | Needs LLM? | Submits to BRAIN? |
|---|---|---|---|
Proven Templates (--proven) | Generates valid BRAIN expressions using hardcoded templates with novel fields | No | Optional (--enable-brain) |
| LLM Mode (default) | Uses 1.5B-72B LLMs to generate hypothesis → expression → evaluation | Yes (local/cloud) | Optional |
BRAIN_SESSION_TOKEN)1git clone https://huggingface.co/gaurv007/alpha-factory
2cd alpha-factory
3pip install -e ".[all]"python -m alpha_factory.run --proven --batch-size 101# Needs Ollama or HF token
2python -m alpha_factory.run --batch-size 5 --dry-runpython -m alpha_factory.generate_provenpytest tests/ -vapi.worldquantbrain.comCookie: session=... header valueexport BRAIN_SESSION_TOKEN=your_token_hereTheme Sampler → Expression Generation → Static Lint → Dedup → Store → Local Sim → Checklist
↓ (Templates or LLM) ↓ ↓ ↓ ↓
Crowd Scout → Performance Surgeon → Gatekeeper → BRAIN Submit
↓ (iteration queue)
Winner Memory ← Mutator ← Performance Surgeon| Module | Purpose | Status |
|---|---|---|
proven_templates.py | Deterministic expression generation | ✅ Working |
lint.py | BRAIN syntax validation (arity, lookahead, parens) | ✅ Working |
pipeline.py | Orchestrates all stages | ✅ Working |
expression_compiler.py | Jinja2 templates + LLM fallback | ✅ Working |
crowd_scout.py | Novelty / correlation assessment | ✅ Working |
performance_surgeon.py | Diagnose failures, suggest mutations | ✅ Working |
gatekeeper.py | Final go/no-go memo | ✅ Working |
wq_client.py | BRAIN API submission | ⚠️ Needs BRAIN_SESSION_TOKEN |
brain_sim.py | Local numpy backtest (triage, lenient) | ✅ Wired (never blocks) |
regime_tagger.py | Vol/trend/rate/style regimes | ✅ Wired via Performance Surgeon |
_process_candidate() — no code duplication.brain_sim.py runs with lenient thresholds (min_sharpe=0.3) and prints warnings but never blocks a candidate. It's for sanity checking, not filtering.rank() are decorative: rank(0.6*a + 0.4*b) is monotonic — coefficients don't linearly combine. The signal comes from which fields are combined.alpha_factory/config.py. Key ones:1batch_size = 10 # Candidates per run
2use_proven_templates = False # Set True for deterministic mode
3enable_brain_client = False # Set True for live BRAIN submission
4max_parallel_candidates = 3 # Concurrent LLM callspython -m alpha_factory.run --proven --batch-size 10 --enable-brain| Item | Cost |
|---|---|
| Proven template mode | $0 (no LLM) |
| Local Ollama (7B) | $0 (your GPU) |
| HuggingFace Inference API | Free tier / rate-limited |
| BRAIN submissions | $0 (uses your existing BRAIN credits) |
alpha_factory/
├── config.py # All settings (Pydantic v2)
├── run.py # Entry point (single asyncio.run)
├── schemas/ # Typed Pydantic contracts
├── deterministic/
│ ├── lint.py # Static pre-flight (Layer 2)
│ ├── theme_sampler.py # Gap analysis (Layer 1)
│ ├── fitness.py # Composite scoring
│ ├── proven_templates.py # Deterministic generation
│ ├── expression_mutator.py # Evolutionary variants
│ ├── acceptance_checklist.py # 14-point pre-submission gate
│ ├── brain_sim.py # Local numpy backtest (triage)
│ └── regime_tagger.py # IQR-based regime detection
├── infra/
│ ├── model_manager.py # Ollama + HF auto-detection
│ ├── llm_client.py # Unified LLM interface (token budget + retry)
│ ├── factor_store.py # DuckDB persistence (parameterized SQL)
│ ├── wq_client.py # BRAIN API wrapper (session auth, circuit breaker)
│ └── winner_memory.py # Feedback loop
├── local/
│ └── brain_sim.py # (identical, part of deterministic)
├── personas/
│ ├── hypothesis_hunter.py # Persona 1 (LLM)
│ ├── expression_compiler.py # Persona 2 (templates + LLM fallback)
│ ├── crowd_scout.py # Persona 4 (heuristic + LLM)
│ ├── performance_surgeon.py # Persona 5 (heuristic + LLM)
│ └── gatekeeper.py # Persona 6 (LLM)
└── orchestration/
└── pipeline.py # Full DAG (unified _process_candidate)pv13_ustomergraphrank → pv13_customergraphrank typosoperators.csv arity mismatches (ts_mean, ts_std, ts_delta now correctly listed as 2-arg)cleanup.py no longer blacklists valid BRAIN fields (vwap, close, volume, etc.)personas/__init__.py imports real modules instead of stubsinfra/__init__.py imports real BrainClient instead of stub classpipeline.py NameError: max_corr — correlation is now computed before checklist callpipeline.py _submit_or_dryrun reuses self.brain instead of creating new clientsrun.py uses single asyncio.run() — no more session leakacceptance_checklist.py RETURNS-CORR check no longer always fails (lowered from 0.05 to 0.95)factor_store.py uses DuckDB transaction context manager instead of string-based BEGIN/COMMITui.py SQL uses parameterized LIMIT instead of f-string injectionexpression_compiler.py _validate_expression is now called, issues loggedexpression_mutator.py regex now handles uppercase field IDs (e.g., mdl77_2GlobalDev...)proven_templates.py decay parameter is now passed through (was hardcoded to 5)theme_sampler.py pick_theme() has alive-theme fallback when all themes exhaustedenable_local_sim config field and --local-sim CLI flagrag.py (arXiv retrieval not wired, will be re-added when integrated)local/__init__.py and orchestration/__init__.pypyproject.toml version bumped to 0.2.0, removed unused scipy dependency--proven) generates expressions without any LLMmax_parallel_candidates semaphore_process_candidate() unified path — both proven and LLM candidates flow through same pipeline