docs: Cerebral Valley Opus 4.7 hackathon submission packet

- AIReasoner default model now claude-opus-4-7 (was sonnet-4-6); pipeline
  reads ai.model from config and passes to constructor. The reasoner
  class attribute is also Opus 4.7 so any caller without explicit model
  defaults to the hackathon model
- README hero gains a "Built with Claude Opus 4.7" badge + a line linking
  to the Cerebral Valley × Anthropic hackathon page
- New SUBMISSION.md — copy-paste blocks for every field of the
  submission form: name, taglines, short / long description, "how Claude
  is used" detail, GitHub URL, demo instructions, tags, tech stack,
  team, license, and a final pre-submission checklist
This commit is contained in:
LEGSTECH Optimizer
2026-04-25 13:00:53 +00:00
parent a584f46891
commit 51a73c953b
4 changed files with 146 additions and 4 deletions
+4
View File
@@ -1,7 +1,11 @@
# APEX — AIPowered MT5 EA Optimizer
[![Built with Claude Opus 4.7](https://img.shields.io/badge/Built%20with-Claude%20Opus%204.7-7c3aed?style=flat-square)](https://www.anthropic.com/news/claude-opus-4-7) [![License: MIT](https://img.shields.io/badge/License-MIT-10b981?style=flat-square)](LICENSE) [![Demo Mode](https://img.shields.io/badge/Demo-No%20MT5%20required-00d4aa?style=flat-square)](demo/run_demo.py)
> **An AI trader thinking out loud while it tests, fails, and improves a strategy.**
> Built with **[Claude Opus 4.7](https://www.anthropic.com/news/claude-opus-4-7)** for the [Cerebral Valley × Anthropic — Built with Opus 4.7 hackathon](https://cerebralvalley.ai/e/built-with-4-7-hackathon).
APEX is an autonomous optimizer for MetaTrader 5 Expert Advisors. Instead of bruteforcing
parameters with grid search, an LLM reads each backtest result, decides which parameter to
change and why, then runs the next backtest — iterating toward profitfactor / drawdown /
+131
View File
@@ -0,0 +1,131 @@
# APEX — Cerebral Valley × Anthropic "Built with Opus 4.7" Hackathon Submission
Copypaste blocks for the submission form. Every field below is also a heading
so you can `Ctrl+F` to it.
---
## Project name
**APEX** — Autonomous Performance Evaluator (AIdriven MT5 EA Optimizer)
---
## Oneliner (≤140 chars)
> An AI trader thinking out loud — Claude Opus 4.7 reads each backtest, decides what to change, and iterates toward profitfactor / drawdown targets.
## Tagline (≤80 chars)
> Watch Claude Opus 4.7 optimize a trading strategy in real time.
---
## Short description (≤300 chars)
APEX turns Claude Opus 4.7 into an autonomous tradingstrategy optimizer for MetaTrader 5. The model reads every backtest, decides what parameters to change and why, then runs the next test — streaming its reasoning live to a dashboard until quality targets are met.
---
## Long description (~500 words — the "what does it do" field)
Most strategy optimizers are bruteforce grid searches: pick a metric, sweep N parameters, pray. The user gets a winning configuration but no idea *why* it won, no confidence in *whether* it'll generalize, and no transparency into the search process.
**APEX replaces the grid with an AI loop.** Claude Opus 4.7 reads each backtest result, looks at the full iteration history, considers the parameter schema and quality targets, and returns a structured `{changes: [{param, value, reason}], confidence, goal_status}` — concrete, boundschecked parameter values for the next test, plus the reasoning that produced them. Every change, every reason, and every Claude token streams live to a dashboard so the user watches the AI think.
The pipeline runs three phases:
1. **Exploration** — LatinHypercube sampling builds a broad map of profitable parameter regions
2. **AI Iteration** — Opus 4.7 takes over, hillclimbing toward userset quality targets (PF ≥ X, DD ≤ Y, Calmar ≥ Z), with stuckdetection and randomescape when the loop converges to a local optimum
3. **Validation** — outofsample backtest on unseen dates + ±20% sensitivity nudge on the top parameter → verdict (RECOMMENDED / RISKY / NOT_RELIABLE)
The dashboard exposes everything the AI is doing as it happens:
- **Live AI Thinking Feed** — Claude's reasoning streams tokenbytoken via SSE with a typing cursor
- **Parameter Changes** — every iteration shows `prev → new` with the reason
- **Validation Activity** — each OOS / sensitivity test renders with live metrics
- **Replay Scrubber** — drag through every step that led to the winning configuration with metrics and AI analysis at each step
- **Compare Runs** — sidebyside metric and parameter diff for any 24 runs
- **Early Termination** — clear banner when targets are hit, budget exhausted, or the AI is stuck
- **Discord/Slack webhook** when an optimization completes
For judges without MT5: there's a **demo mode** (`python -m demo.run_demo`) that synthesizes deterministicbutrealistic backtests so the entire AI loop, validation, and verdict flow run endtoend with no MT5 install. Roughly 35% of Phase 1 samples and 30% of OOS runs realistically fail, so verdicts genuinely span RECOMMENDED / RISKY / NOT_RELIABLE.
The point isn't a better trading strategy — it's a working pattern for **AIasdriver of a longrunning optimization loop**, with the AI's reasoning fully visible. That pattern transfers to any iterative search problem where humans currently gridsweep blindly: ML hyperparameter tuning, A/B variant generation, adcreative optimization, infrastructure cost tuning.
---
## Built with
Claude Opus 4.7 (the reasoning loop), Flask + FlaskSocketIO (realtime UI), Python 3.11, Pandas + NumPy, Pydantic, Anthropic Messages API with SSE streaming, MetaTrader 5 Strategy Tester (real backtests).
---
## How Claude Opus 4.7 is used (the "what AI features did you use" field)
- **`suggest_next_params()` — Opus 4.7 is the loop driver.** It receives the full parameter schema, the iteration history (last 15 runs with metrics + changes), and the user's quality targets, and returns structured JSON with concrete parameter values, perchange reasoning, a confidence score, and a goalstatus breakdown (which targets are met). This is the loadbearing call — it's what turns the optimizer from a grid search into an agent.
- **`analyze()` — Perrun diagnostics.** A second Opus 4.7 call interprets each backtest's metrics + analyzer findings + recent run history and returns headline / diagnosis / patterns / suggestions / risk flags. Powers the AI Summary panel.
- **SSE streaming** — both calls run with `stream=true`. Each text delta forwards to the dashboard as `ai_thinking_chunk` events so the user sees Claude's reasoning type out tokenbytoken. Single growing bubble per call with a blinking cursor that finalises on `end`.
- **Hot model swap** — users can change model (`claude-opus-4-7``claude-sonnet-4-6``claude-haiku-4-5`) midrun via Settings. The next iteration uses the new model without restart.
---
## GitHub URL
https://github.com/tonnylegacy/MT5_Optimizer
---
## Demo URL
No hosted demo (the app runs locally to drive a local MT5 install). For judges:
- **Static**: open `screenshots/apex_demo.gif` in the repo (6frame timelapse of one autonomous run)
- **Run it**: `git clone … && pip install -r requirements.txt && python -m demo.run_demo` → opens at `http://localhost:5000` with synthetic backtests, no MT5 required
- **With API key**: set `ANTHROPIC_API_KEY` env var to see live Claude reasoning stream into the Thinking Feed
---
## Video / GIF
`screenshots/apex_demo.gif` (438 KB, GitHubembedded in README hero)
---
## Team
Solo build — `tonnylegacy`
---
## Tags
`mt5` `metatrader5` `trading` `quant` `optimization` `claude-opus-4-7` `anthropic` `ai-agents` `agentic-loops` `python` `flask` `socketio` `streaming-ui`
---
## Tech stack
`Python 3.11` · `Anthropic Messages API (SSE streaming)` · `Claude Opus 4.7` · `Flask` · `FlaskSocketIO` · `Pandas / NumPy / Pydantic` · `MetaTrader 5 Strategy Tester`
---
## License
MIT
---
## Submission checklist
- [x] Repo public on GitHub: <https://github.com/tonnylegacy/MT5_Optimizer>
- [x] LICENSE file (MIT)
- [x] README with pitch + screenshots + install + architecture diagram
- [x] No leaked API keys (config.yaml gitignored, envvar fallback wired, GET /api/settings masks key)
- [x] `config.example.yaml` template for users
- [x] Animated demo GIF in `screenshots/apex_demo.gif`
- [x] Demo mode that runs without MT5 (`python -m demo.run_demo`)
- [x] Opus 4.7 is the default model (config + AIReasoner class default)
- [x] Streaming reasoning visible to the user (SSE → `ai_thinking_chunk`)
- [ ] Recorded a 3060 second screen capture for any "video" field — *do this last; the GIF can substitute*
- [ ] Submission form filled — *paste blocks above into the Cerebral Valley form when it opens*
+4 -2
View File
@@ -73,11 +73,13 @@ class AIReasoner:
Falls back gracefully if API key is missing or call fails.
"""
MODEL = "claude-sonnet-4-6"
MODEL = "claude-opus-4-7" # default — overridden by config.ai.model when present
API_URL = "https://api.anthropic.com/v1/messages"
TIMEOUT = 30 # seconds
def __init__(self, api_key: Optional[str] = None):
def __init__(self, api_key: Optional[str] = None, model: Optional[str] = None):
if model:
self.MODEL = model
# If the caller passes a placeholder like "${ANTHROPIC_API_KEY}" or an
# empty string, treat it as missing and fall back to the env var.
candidate = (api_key or "").strip()
+7 -2
View File
@@ -240,9 +240,14 @@ class OptimizationPipeline:
ranker = ResultRanker(weights=cfg.scoring_weights)
budget = BudgetManager(cfg.budget_minutes)
# Initialize AI reasoning layer
# Initialize AI reasoning layer (model + timeout from config)
api_key = load_api_key(self.config_path)
self._ai_reasoner = AIReasoner(api_key=api_key)
ai_cfg = (self.cfg.get("ai") or {})
model = ai_cfg.get("model") or "claude-opus-4-7"
self._ai_reasoner = AIReasoner(api_key=api_key, model=model)
if "timeout_seconds" in ai_cfg:
try: self._ai_reasoner.TIMEOUT = int(ai_cfg["timeout_seconds"])
except Exception: pass
# Stream Claude's reasoning tokens to the dashboard as they arrive.
# The Live AI Thinking Feed listens for `ai_thinking_chunk` events.
try: