Skip to content

hitendras510/OpenAlpha-Brain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

OpenAlpha-Quant

🧠 Autonomous alpha research platform for WorldQuant BRAIN IQC 2026
LLM-powered closed-loop pipeline β€” Generate β†’ Validate β†’ Submit β†’ Mutate β†’ Repeat until BRAIN approves

Python FastAPI WorldQuant BRAIN License: MIT


What It Does

OpenAlpha-Quant runs as a fully autonomous agent that:

  1. Generates alpha expressions using an LLM (Groq / Gemini / OpenAI) guided by a rigorous IQC research mandate
  2. Validates locally β€” syntax, fingerprint anti-crowding, estimated metrics via exact IQC formulas
  3. Submits to WorldQuant BRAIN β€” real simulation via the BRAIN REST API
  4. Reads real BRAIN results β€” actual Sharpe, Fitness, Turnover + every gate check (LOW_SHARPE, LOW_FITNESS, LOW_SUB_UNIVERSE_SHARPE, SELF_CORRELATION, etc.)
  5. Mutates surgically β€” each failing BRAIN check triggers a specific ELM mutation injected back into the LLM up to 20 times per alpha
  6. Live Dashboard UI β€” watch the closed-loop optimization, view live metrics, exact WorldQuant gate failure text, and expression patches
  7. Dockerized Deployment β€” easily run the background service and UI in an isolated environment

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     OpenAlpha - Quant                           β”‚
β”‚                                                                 β”‚
β”‚   LLM (Groq/Gemini/OpenAI)                                      β”‚
β”‚        β”‚                                                        β”‚
β”‚        β–Ό                                                        β”‚
β”‚   [GENERATION]  Alpha expression + metrics + fingerprint        β”‚
β”‚        β”‚                                                        β”‚
β”‚        β–Ό                                                        β”‚
β”‚   [LOCAL VALIDATION]                                            β”‚
β”‚   β€’ Syntax (operators, parens, variable whitelist)              β”‚
β”‚   β€’ Fingerprint anti-crowding (5-dim POMDP memory)              β”‚
β”‚   β€’ Estimated IQC gate check (Sharpe/Fitness/Turnover)          β”‚
β”‚        β”‚ PASS                                                   β”‚
β”‚        β–Ό                                                        β”‚
β”‚   [BRAIN SUBMISSION]  POST /simulations β†’ poll β†’ COMPLETE       β”‚
β”‚        β”‚                                                        β”‚
β”‚        β–Ό                                                        β”‚
β”‚   [REAL GATE CHECKS]  checks[] from BRAIN API                   β”‚
β”‚   β€’ LOW_SHARPE β†’ ts_zscore + volatility norm + subindustry      β”‚
β”‚   β€’ LOW_FITNESS β†’ ts_decay_linear(expr, 10)                     β”‚
β”‚   β€’ LOW_SUB_UNIVERSE_SHARPE β†’ subindustry + interaction factors β”‚
β”‚   β€’ SELF_CORRELATION β†’ full structural pivot (3+ dims)          β”‚
β”‚   β€’ HIGH_TURNOVER β†’ increase decay d=6β†’10β†’15β†’20                 β”‚
β”‚   β€’ SIMULATION ERROR β†’ enforce variable whitelist               β”‚
β”‚        β”‚ FAIL β†’ inject targeted mutation β†’ back to LLM          β”‚
β”‚        β”‚ PASS ──────────────────────────────────────────────►   β”‚
β”‚                    Alpha saved in BRAIN "My Alphas" βœ“           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Start

Option 1: Docker (Recommended)

  1. Clone the repository:
    git clone git@github.com:hitendras510/OpenAlpha-Brain.git
    cd OpenAlpha-Brain
  2. Configure your credentials in .env (WorldQuant + LLM).
    cp .env.example .env
    # Edit .env with your credentials
  3. Start the application:
    docker-compose up -d --build
  4. Open the UI Dashboard: http://localhost:8000/static/index.html

Option 2: Local Python Execution

  1. Install dependencies:

    git clone git@github.com:hitendras510/OpenAlpha-Brain.git
    cd OpenAlpha-Brain
    pip install -r requirements.txt
  2. Configure .env:

    cp .env.example .env

    Edit .env:

    Variable Required Description
    LLM_PROVIDER βœ… groq / gemini / openai / anthropic
    LLM_MODEL βœ… e.g. llama-3.3-70b-versatile (Groq), gemini-1.5-flash
    LLM_API_KEY βœ… Your LLM provider API key
    BRAIN_EMAIL βœ… Your worldquantbrain.com account email
    BRAIN_PASSWORD βœ… Your worldquantbrain.com account password
    BRAIN_SUBMIT_ENABLED βœ… true to enable auto-submission to BRAIN

    Free LLM Keys

  3. Run the Backend:

    uvicorn main:app --port 8000
  4. Launch Dashboard: Navigate to http://localhost:8000/static/index.html and click Start.


Closed-Loop Mutation System

When BRAIN returns a simulation result, every failing check is mapped to a precise surgical mutation that gets injected into the LLM's next generation cycle:

BRAIN Check What It Means Mutation Applied
LOW_SHARPE Sharpe < 1.25 Switch rank() β†’ ts_zscore(), add volatility norm /ts_std_dev(close,20), tighten to subindustry
LOW_FITNESS Fitness ≀ 1.0 Wrap with ts_decay_linear(expr, 10) targeting 15–35% turnover
LOW_SUB_UNIVERSE_SHARPE Fails within industry groups Change neutralization to subindustry, add interaction rank(A)*rank(B)
HIGH_TURNOVER Turnover > 70% Increase decay d=6β†’10β†’15β†’20
LOW_TURNOVER Turnover < 1% Remove decay, shorter windows, use ts_delta()
SELF_CORRELATION Correlated with existing alphas Full 3-dim structural pivot to different factor family
CONCENTRATED_WEIGHT Weights too concentrated Add scale() + signed_power(expr, 0.5)
SIMULATION ERROR Invalid variable name Enforce variable whitelist, rewrite expression

The LLM also receives the exact real metric values from BRAIN (Sharpe, Fitness, Turnover, Returns) alongside each mutation instruction.


Confirmed BRAIN FastExpr Variables

Only these bare variable names work in BRAIN's FastExpr language:

Price/Volume : close, open, high, low, vwap, volume, adv20, returns, cap
Short Int    : short_ratio, days_to_cover
Analyst      : analyst_rating, price_target
Neutralize   : industry, subindustry, sector  (group_neutralize args only)

⚠️ Variables like earnings, sales, short_interest, institutional_ownership do not exist as bare names β€” BRAIN uses dataset-prefixed names accessed via Data Explorer.


IQC Gate Thresholds

Sharpe   β‰₯ 1.25   (target > 2.0)
Fitness  > 1.0    Formula: Sharpe Γ— sqrt(|Returns|) / max(Turnover, 0.125)
Turnover 1%–70%   Sweet spot: 15%–35%

API Reference

Endpoint Method Description
/health GET Server health check
/session/start POST Start a new research session
/session/{id} GET Get session state (status, passed alphas, BRAIN results)
/session/{id}/stop POST Stop a running session
/static/index.html GET Real-time research dashboard

Session Status Values

Status Meaning
GENERATING LLM is writing an alpha
VALIDATING Local gate checks running
SUBMITTING Alpha sent to BRAIN, polling for result
ITERATING BRAIN returned failures, LLM mutating
PASS Alpha passed all BRAIN checks βœ“
ERROR Unrecoverable error

Project Structure

OpenAlpha-Brain/
β”œβ”€β”€ main.py              # FastAPI server + session routes
β”œβ”€β”€ loop_engine.py       # Core autonomous research loop
β”œβ”€β”€ brain_client.py      # WorldQuant BRAIN REST API client
β”œβ”€β”€ prompts.py           # LLM system prompt + ELM mutation feedback builders
β”œβ”€β”€ llm_client.py        # Multi-provider LLM client (Groq/Gemini/OpenAI)
β”œβ”€β”€ validator.py         # Local syntax + IQC metric validator
β”œβ”€β”€ alpha_parser.py      # Parses LLM output into structured AlphaResult
β”œβ”€β”€ session_manager.py   # JSON-backed session persistence
β”œβ”€β”€ models.py            # Pydantic models (AlphaResult, BrainSubmissionResult, etc.)
β”œβ”€β”€ config.py            # Settings loaded from .env
β”œβ”€β”€ watch_session.py     # CLI watcher β€” runs until BRAIN PASS
β”œβ”€β”€ static/index.html    # Real-time dashboard
β”œβ”€β”€ .env.example         # Environment template
└── requirements.txt

POMDP Memory Architecture

Each research session maintains a belief state that prevents redundant exploration:

  • Topology Map β€” tracks which AST topologies have been explored (PASSED/FAILED/CROWDED)
  • Dataset Usage β€” counts attempts per factor family; forces pivot after 3 consecutive fails
  • Failure Catalog β€” logs each failure with fingerprint, metric values, mutation attempted
  • Open Frontiers β€” unexplored 5-dimensional fingerprint combinations
  • Rejected Motifs β€” topologies permanently retired for this session

Security

  • .env is gitignored β€” credentials never leave your machine
  • /sessions directory is gitignored β€” session state stays local
  • BRAIN auth uses HTTP Basic Auth β†’ session cookie (no API key storage)

License

MIT β€” see LICENSE


Built for WorldQuant IQC 2026 Β· Powered by Groq / Gemini Β· BRAIN API v1

About

An autonomous, closed-loop alpha mining platform for the **WorldQuant BRAIN IQC 2026** competition.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors