Upload README.md
Browse files
README.md
CHANGED
|
@@ -26,10 +26,12 @@ The pipeline runs:
|
|
| 26 |
3. **Static lint** β validates BRAIN syntax (operator arity, look-ahead, parentheses)
|
| 27 |
4. **Deduplication** β SHA256 hash to avoid duplicates
|
| 28 |
5. **Store** β persists to DuckDB for review
|
| 29 |
-
6. **
|
| 30 |
-
7. **
|
| 31 |
-
8. **
|
| 32 |
9. **BRAIN submission** β live submission (requires `BRAIN_SESSION_TOKEN`)
|
|
|
|
|
|
|
| 33 |
|
| 34 |
## Quick Start
|
| 35 |
|
|
@@ -81,8 +83,8 @@ BRAIN uses **session-based authentication** (browser cookies), not API keys. The
|
|
| 81 |
## Architecture
|
| 82 |
|
| 83 |
```
|
| 84 |
-
Theme Sampler β Expression Generation β Static Lint β Dedup β Store
|
| 85 |
-
β (Templates or LLM) β β
|
| 86 |
Crowd Scout β Performance Surgeon β Gatekeeper β BRAIN Submit
|
| 87 |
β (iteration queue)
|
| 88 |
Winner Memory β Mutator β Performance Surgeon
|
|
@@ -100,8 +102,8 @@ Winner Memory β Mutator β Performance Surgeon
|
|
| 100 |
| `performance_surgeon.py` | Diagnose failures, suggest mutations | β
Working |
|
| 101 |
| `gatekeeper.py` | Final go/no-go memo | β
Working |
|
| 102 |
| `wq_client.py` | BRAIN API submission | β οΈ Needs `BRAIN_SESSION_TOKEN` |
|
| 103 |
-
| `brain_sim.py` | Local numpy backtest
|
| 104 |
-
| `regime_tagger.py` | Vol/trend/rate/style regimes |
|
| 105 |
|
| 106 |
## Key Features
|
| 107 |
|
|
@@ -113,16 +115,16 @@ Winner Memory β Mutator β Performance Surgeon
|
|
| 113 |
- **Winner memory**: Tracks which field/archetype combinations work, feeds back to generation.
|
| 114 |
- **Expression mutator**: Auto-generates decay, horizon, neutralization, and sign-flip variants.
|
| 115 |
- **DuckDB store**: Persistent history of all alphas, metrics, and verdicts.
|
| 116 |
-
- **Retry logic**: LLM client retries transient failures (429, 502, 503, 504, timeout) with exponential backoff.
|
|
|
|
| 117 |
|
| 118 |
## Known Limitations
|
| 119 |
|
| 120 |
1. **BRAIN auth is session-based**: Token expires. No automatic refresh. You must re-copy from browser.
|
| 121 |
-
2. **Local simulation is
|
| 122 |
-
3. **
|
| 123 |
-
4. **
|
| 124 |
-
5. **
|
| 125 |
-
6. **Not a guarantee of profitable alphas**: This generates candidates. BRAIN's simulation is the ground truth.
|
| 126 |
|
| 127 |
## Configuration
|
| 128 |
|
|
@@ -154,7 +156,7 @@ python -m alpha_factory.run --proven --batch-size 10 --enable-brain
|
|
| 154 |
```
|
| 155 |
alpha_factory/
|
| 156 |
βββ config.py # All settings (Pydantic v2)
|
| 157 |
-
βββ run.py # Entry point
|
| 158 |
βββ schemas/ # Typed Pydantic contracts
|
| 159 |
βββ deterministic/
|
| 160 |
β βββ lint.py # Static pre-flight (Layer 2)
|
|
@@ -162,23 +164,25 @@ alpha_factory/
|
|
| 162 |
β βββ fitness.py # Composite scoring
|
| 163 |
β βββ proven_templates.py # Deterministic generation
|
| 164 |
β βββ expression_mutator.py # Evolutionary variants
|
| 165 |
-
β
|
|
|
|
|
|
|
| 166 |
βββ infra/
|
| 167 |
β βββ model_manager.py # Ollama + HF auto-detection
|
| 168 |
β βββ llm_client.py # Unified LLM interface (token budget + retry)
|
| 169 |
-
β βββ factor_store.py # DuckDB persistence
|
| 170 |
-
β βββ wq_client.py # BRAIN API wrapper (session auth)
|
| 171 |
β βββ winner_memory.py # Feedback loop
|
| 172 |
βββ local/
|
| 173 |
-
β βββ brain_sim.py #
|
| 174 |
βββ personas/
|
| 175 |
-
β βββ hypothesis_hunter.py # Persona 1
|
| 176 |
-
β βββ expression_compiler.py # Persona 2
|
| 177 |
-
β βββ crowd_scout.py # Persona 4
|
| 178 |
-
β βββ performance_surgeon.py # Persona 5
|
| 179 |
-
β βββ gatekeeper.py # Persona 6
|
| 180 |
βββ orchestration/
|
| 181 |
-
βββ pipeline.py # Full DAG
|
| 182 |
```
|
| 183 |
|
| 184 |
## Changelog v0.2.0
|
|
@@ -191,16 +195,29 @@ alpha_factory/
|
|
| 191 |
- **Fixed**: Expression compiler sign logic β now per-component, no global blind negation
|
| 192 |
- **Fixed**: LLM client stops error amplification (no more 3x API calls on auth/network failures)
|
| 193 |
- **Fixed**: LLM client enforces token budget (was declared but never checked)
|
| 194 |
-
- **Fixed**: LLM client adds retry logic with exponential backoff for transient failures
|
| 195 |
-
- **Fixed**:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
- **Fixed**: Removed orphan `rag.py` (arXiv retrieval not wired, will be re-added when integrated)
|
| 197 |
-
- **Fixed**: Added missing `local/__init__.py`
|
| 198 |
-
- **Fixed**:
|
| 199 |
- **New**: Proven template mode (`--proven`) generates expressions without any LLM
|
| 200 |
- **New**: Winner memory integration in pipeline (records winners/failures/iterations)
|
| 201 |
- **New**: Expression mutator integration (auto-generates decay/horizon/group/sign variants)
|
|
|
|
| 202 |
- **New**: Parallel batch processing with `max_parallel_candidates` semaphore
|
| 203 |
-
- **New**:
|
|
|
|
| 204 |
- **Updated**: Honest README that accurately describes what works and what doesn't
|
| 205 |
|
| 206 |
## License
|
|
@@ -210,19 +227,7 @@ MIT β use at your own risk. This is not financial advice. BRAIN simulations ar
|
|
| 210 |
<!-- ml-intern-provenance -->
|
| 211 |
## Generated by ML Intern
|
| 212 |
|
| 213 |
-
This
|
| 214 |
|
| 215 |
- Try ML Intern: https://smolagents-ml-intern.hf.space
|
| 216 |
- Source code: https://github.com/huggingface/ml-intern
|
| 217 |
-
|
| 218 |
-
## Usage
|
| 219 |
-
|
| 220 |
-
```python
|
| 221 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 222 |
-
|
| 223 |
-
model_id = 'gaurv007/alpha-factory'
|
| 224 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 225 |
-
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 226 |
-
```
|
| 227 |
-
|
| 228 |
-
For non-causal architectures, replace `AutoModelForCausalLM` with the appropriate `AutoModel` class.
|
|
|
|
| 26 |
3. **Static lint** β validates BRAIN syntax (operator arity, look-ahead, parentheses)
|
| 27 |
4. **Deduplication** β SHA256 hash to avoid duplicates
|
| 28 |
5. **Store** β persists to DuckDB for review
|
| 29 |
+
6. **Local sim** β lightweight numpy backtest as triage (lenient thresholds, never blocks)
|
| 30 |
+
7. **Acceptance checklist** β 14-point pre-submission gate
|
| 31 |
+
8. **Crowd Scout** β novelty assessment (LLM or heuristic)
|
| 32 |
9. **BRAIN submission** β live submission (requires `BRAIN_SESSION_TOKEN`)
|
| 33 |
+
10. **Performance Surgeon** β diagnoses weak alphas, suggests mutations
|
| 34 |
+
11. **Gatekeeper** β final go/no-go (LLM)
|
| 35 |
|
| 36 |
## Quick Start
|
| 37 |
|
|
|
|
| 83 |
## Architecture
|
| 84 |
|
| 85 |
```
|
| 86 |
+
Theme Sampler β Expression Generation β Static Lint β Dedup β Store β Local Sim β Checklist
|
| 87 |
+
β (Templates or LLM) β β β β
|
| 88 |
Crowd Scout β Performance Surgeon β Gatekeeper β BRAIN Submit
|
| 89 |
β (iteration queue)
|
| 90 |
Winner Memory β Mutator β Performance Surgeon
|
|
|
|
| 102 |
| `performance_surgeon.py` | Diagnose failures, suggest mutations | β
Working |
|
| 103 |
| `gatekeeper.py` | Final go/no-go memo | β
Working |
|
| 104 |
| `wq_client.py` | BRAIN API submission | β οΈ Needs `BRAIN_SESSION_TOKEN` |
|
| 105 |
+
| `brain_sim.py` | Local numpy backtest (triage, lenient) | β
Wired (never blocks) |
|
| 106 |
+
| `regime_tagger.py` | Vol/trend/rate/style regimes | β
Wired via Performance Surgeon |
|
| 107 |
|
| 108 |
## Key Features
|
| 109 |
|
|
|
|
| 115 |
- **Winner memory**: Tracks which field/archetype combinations work, feeds back to generation.
|
| 116 |
- **Expression mutator**: Auto-generates decay, horizon, neutralization, and sign-flip variants.
|
| 117 |
- **DuckDB store**: Persistent history of all alphas, metrics, and verdicts.
|
| 118 |
+
- **Retry logic**: LLM client retries transient failures (429, 502, 503, 504, timeout) with exponential backoff. Non-retryable errors (401, 400, OOM) abort immediately.
|
| 119 |
+
- **Unified pipeline**: Both proven and LLM paths flow through `_process_candidate()` β no code duplication.
|
| 120 |
|
| 121 |
## Known Limitations
|
| 122 |
|
| 123 |
1. **BRAIN auth is session-based**: Token expires. No automatic refresh. You must re-copy from browser.
|
| 124 |
+
2. **Local simulation is triage-only**: `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.
|
| 125 |
+
3. **LLM generation can hallucinate fields**: Static lint catches most errors, but field names from LLMs may not exist on BRAIN.
|
| 126 |
+
4. **Weights inside `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.
|
| 127 |
+
5. **Not a guarantee of profitable alphas**: This generates candidates. BRAIN's simulation is the ground truth.
|
|
|
|
| 128 |
|
| 129 |
## Configuration
|
| 130 |
|
|
|
|
| 156 |
```
|
| 157 |
alpha_factory/
|
| 158 |
βββ config.py # All settings (Pydantic v2)
|
| 159 |
+
βββ run.py # Entry point (single asyncio.run)
|
| 160 |
βββ schemas/ # Typed Pydantic contracts
|
| 161 |
βββ deterministic/
|
| 162 |
β βββ lint.py # Static pre-flight (Layer 2)
|
|
|
|
| 164 |
β βββ fitness.py # Composite scoring
|
| 165 |
β βββ proven_templates.py # Deterministic generation
|
| 166 |
β βββ expression_mutator.py # Evolutionary variants
|
| 167 |
+
β βββ acceptance_checklist.py # 14-point pre-submission gate
|
| 168 |
+
β βββ brain_sim.py # Local numpy backtest (triage)
|
| 169 |
+
β βββ regime_tagger.py # IQR-based regime detection
|
| 170 |
βββ infra/
|
| 171 |
β βββ model_manager.py # Ollama + HF auto-detection
|
| 172 |
β βββ llm_client.py # Unified LLM interface (token budget + retry)
|
| 173 |
+
β βββ factor_store.py # DuckDB persistence (parameterized SQL)
|
| 174 |
+
β βββ wq_client.py # BRAIN API wrapper (session auth, circuit breaker)
|
| 175 |
β βββ winner_memory.py # Feedback loop
|
| 176 |
βββ local/
|
| 177 |
+
β βββ brain_sim.py # (identical, part of deterministic)
|
| 178 |
βββ personas/
|
| 179 |
+
β βββ hypothesis_hunter.py # Persona 1 (LLM)
|
| 180 |
+
β βββ expression_compiler.py # Persona 2 (templates + LLM fallback)
|
| 181 |
+
β βββ crowd_scout.py # Persona 4 (heuristic + LLM)
|
| 182 |
+
β βββ performance_surgeon.py # Persona 5 (heuristic + LLM)
|
| 183 |
+
β βββ gatekeeper.py # Persona 6 (LLM)
|
| 184 |
βββ orchestration/
|
| 185 |
+
βββ pipeline.py # Full DAG (unified _process_candidate)
|
| 186 |
```
|
| 187 |
|
| 188 |
## Changelog v0.2.0
|
|
|
|
| 195 |
- **Fixed**: Expression compiler sign logic β now per-component, no global blind negation
|
| 196 |
- **Fixed**: LLM client stops error amplification (no more 3x API calls on auth/network failures)
|
| 197 |
- **Fixed**: LLM client enforces token budget (was declared but never checked)
|
| 198 |
+
- **Fixed**: LLM client adds retry logic with exponential backoff for transient failures
|
| 199 |
+
- **Fixed**: LLM client JSON parsing regex no longer strips all whitespace (was mangling responses)
|
| 200 |
+
- **Fixed**: `pipeline.py` `NameError: max_corr` β correlation is now computed before checklist call
|
| 201 |
+
- **Fixed**: `pipeline.py` `_submit_or_dryrun` reuses `self.brain` instead of creating new clients
|
| 202 |
+
- **Fixed**: `run.py` uses single `asyncio.run()` β no more session leak
|
| 203 |
+
- **Fixed**: `acceptance_checklist.py` RETURNS-CORR check no longer always fails (lowered from 0.05 to 0.95)
|
| 204 |
+
- **Fixed**: `factor_store.py` uses DuckDB transaction context manager instead of string-based BEGIN/COMMIT
|
| 205 |
+
- **Fixed**: `ui.py` SQL uses parameterized LIMIT instead of f-string injection
|
| 206 |
+
- **Fixed**: `expression_compiler.py` `_validate_expression` is now called, issues logged
|
| 207 |
+
- **Fixed**: `expression_mutator.py` regex now handles uppercase field IDs (e.g., `mdl77_2GlobalDev...`)
|
| 208 |
+
- **Fixed**: `proven_templates.py` decay parameter is now passed through (was hardcoded to 5)
|
| 209 |
+
- **Fixed**: `theme_sampler.py` `pick_theme()` has alive-theme fallback when all themes exhausted
|
| 210 |
+
- **Fixed**: Removed dead `enable_local_sim` config field and `--local-sim` CLI flag
|
| 211 |
- **Fixed**: Removed orphan `rag.py` (arXiv retrieval not wired, will be re-added when integrated)
|
| 212 |
+
- **Fixed**: Added missing `local/__init__.py` and `orchestration/__init__.py`
|
| 213 |
+
- **Fixed**: `pyproject.toml` version bumped to 0.2.0, removed unused `scipy` dependency
|
| 214 |
- **New**: Proven template mode (`--proven`) generates expressions without any LLM
|
| 215 |
- **New**: Winner memory integration in pipeline (records winners/failures/iterations)
|
| 216 |
- **New**: Expression mutator integration (auto-generates decay/horizon/group/sign variants)
|
| 217 |
+
- **New**: Acceptance checklist (14 checks, wired before BRAIN submission)
|
| 218 |
- **New**: Parallel batch processing with `max_parallel_candidates` semaphore
|
| 219 |
+
- **New**: 64+ comprehensive tests covering templates, lint, mutations, config, fitness, fields, groups
|
| 220 |
+
- **New**: `_process_candidate()` unified path β both proven and LLM candidates flow through same pipeline
|
| 221 |
- **Updated**: Honest README that accurately describes what works and what doesn't
|
| 222 |
|
| 223 |
## License
|
|
|
|
| 227 |
<!-- ml-intern-provenance -->
|
| 228 |
## Generated by ML Intern
|
| 229 |
|
| 230 |
+
This repository was generated by [ML Intern](https://github.com/huggingface/ml-intern), an agent for machine learning research and development on the Hugging Face Hub.
|
| 231 |
|
| 232 |
- Try ML Intern: https://smolagents-ml-intern.hf.space
|
| 233 |
- Source code: https://github.com/huggingface/ml-intern
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|