Commit Graph

31 Commits

Author SHA1 Message Date
Adriano 889903fdae feat(dashboard): streamlit skeleton + Overview page + data layer
Aggiunge scheletro multipage Streamlit per Phase 1:
- modulo data.py con helper (list_runs_df, get_run_overview,
  generations_df, evaluations_df, genomes_df) sopra Repository.
- streamlit_app.py entry point con DB_PATH da env.
- pages/01_overview.py per elenco run + metriche + config JSON.
- smoke test import di multi_swarm.dashboard.data.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 20:33:08 +02:00
Adriano 91d160be6f feat(orchestrator): end-to-end Phase 1 runner with persistence
Loop GA completo: build_initial_population -> hypothesis.propose ->
falsification + adversarial -> compute_fitness -> persistenza ->
next_generation. Stato run/gen/genomes/evals/cost/findings su SQLite,
elite skip-eval, run marcato failed su eccezione.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 20:28:35 +02:00
Adriano 430b874b26 feat(agents): market summary builder for hypothesis prompt
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 20:24:23 +02:00
Adriano 0f06b056f2 feat(ga): initial population generator with cognitive style coverage
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 20:22:04 +02:00
Adriano c2a7a62763 feat(ga): generation summary stats (median/max/p90/entropy)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 20:20:12 +02:00
Adriano 34f88865da feat(persistence): SQLite schema + repository for runs/genomes/evals/cost
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 20:18:08 +02:00
Adriano 65dda09aff feat(ga): next_generation step (elitism + tournament + mutate/crossover)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 20:15:21 +02:00
Adriano 3f36ad65dd feat(ga): tournament selection + elitism
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 20:12:51 +02:00
Adriano 71cfcf786f feat(ga): fitness v0 (DSR - dd_penalty * max_dd, kill on adversarial high)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 20:11:13 +02:00
Adriano 3fbd5eba5e feat(agents): hand-crafted adversarial with heuristic checks
Implementa AdversarialAgent con check euristici hand-crafted:
no_trades (HIGH), degenerate (HIGH), overtrading/undertrading (MEDIUM).
Severity come StrEnum (UP042 clean), pipeline AST -> compile -> backtest
-> findings allineata a FalsificationAgent.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 20:07:56 +02:00
Adriano 15cb6b37aa feat(agents): hand-crafted falsification (compile→backtest→DSR)
Pipeline AST -> compile_strategy -> BacktestEngine -> Sharpe/DSR/DD.
Caso zero-trade ritorna report tutto-zero. n_trials_dsr correzione
multiple-testing parametrizzata via init.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 20:05:01 +02:00
Adriano 654ab7b6d9 feat(agents): hypothesis agent with prompt template + s-expr extraction
Aggiunge HypothesisAgent che invoca LLMClient con system/user template
parametrizzati sul genoma e sul MarketSummary, poi estrae la S-expression
(da fence markdown lisp/scheme/sexp o testo nudo), la parsa e la valida.
Restituisce HypothesisProposal con strategy=None + parse_error in caso di
output malformato, mantenendo sempre il CompletionResult per accounting.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 20:01:31 +02:00
Adriano a6f32dd4d8 feat(llm): cost tracker with per-tier pricing and breakdown
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:57:51 +02:00
Adriano a9261452e0 feat(llm): unified client for OpenRouter (Qwen) + Anthropic (Sonnet)
LLMClient instrada richieste in base a ModelTier del genome:
- Tier C -> Qwen 2.5 72B via OpenRouter (chat completions)
- Tier B -> Sonnet 4.6 via Anthropic (messages API)
CompletionResult dataclass frozen con text, tokens, tier, model.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:54:39 +02:00
Adriano 93d0a9e848 feat(genome): uniform crossover for hypothesis genomes
Aggiunge `uniform_crossover` che eredita ogni campo da p1 o p2
con probabilita' 0.5, popola `parent_ids=[p1.id, p2.id]` e incrementa
la generazione. Deterministico dato lo stesso `random.Random` seed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:51:44 +02:00
Adriano 80f4477f72 feat(genome): deterministic mutation operators (numeric + categorical)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:48:22 +02:00
Adriano 42a95a52b5 feat(genome): HypothesisAgentGenome with deterministic id and serde
Dataclass per genoma agente ipotesi con campi prompt/feature/temperature/
top_p/model_tier/lookback/style + parent_ids/generation. Id sha1[:16]
deterministico su contenuto canonico (feature_access ordinate, float
arrotondati). to_dict/from_dict per persistenza.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:45:07 +02:00
Adriano 26c328d541 feat(protocol): AST compiler to (df -> Series[Side]) signal fn
Implementa compile_strategy che produce funzione df -> Series[Side]
con valutazione regole in ordine, prima-che-matcha vince, FLAT default
e NaN per warmup degli indicatori.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:40:28 +02:00
Adriano 052f323790 feat(protocol): semantic validator for AST
Aggiunge validatore semantico per AST Strategy: arity check su
verbi logici/comparatori/data, whitelist indicatori
(sma, rsi, atr, macd, realized_vol) e feature OHLCV.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:34:03 +02:00
Adriano 19035812c3 feat(protocol): grammatica S-expression (15 verbi) + parser
Aggiunge il modulo `multi_swarm.protocol` con la grammatica del DSL di
strategia (15 verbi: 4 azioni, 3 logici, 3 comparatori, 4 dati, `when`
e `strategy`) e un parser che produce un AST tipizzato (Strategy/Rule/
Node). Lessing delegato a sexpdata, validazione del set di verbi e
forma `(when <cond> <action>)` gestita dal parser. Sollevata ParseError
su top-level malformato, strategia vuota, verbi sconosciuti o azioni
non terminali.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:30:54 +02:00
Adriano 7290900dc7 feat(cerbero): tools wrapper for Phase 1 indicator subset
Espone sma/rsi/atr/macd/realized_vol/funding_rate sopra CerberoClient
delegando a call_tool(exchange, tool, args).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:27:34 +02:00
Adriano 14b1b84a47 feat(cerbero): HTTP client with bearer + bot-tag + retry
Client minimale verso Cerbero MCP unified server con header
Authorization Bearer e X-Bot-Tag su ogni richiesta. Retry esponenziale
solo su ConnectionError (non su 4xx). 4xx/5xx -> RuntimeError.

Switch da httpx a requests per allineamento con libreria mock
`responses` (httpx richiederebbe respx). httpx resta in deps per usi
futuri. Aggiunto types-requests ai dev deps per mypy strict.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:25:00 +02:00
Adriano b61bbaf13c feat(metrics): Deflated Sharpe Ratio (Bailey & Lopez de Prado)
Aggiunge expected_max_sharpe e deflated_sharpe_ratio per correggere
multiple testing nella valutazione di strategie. Considera skewness,
kurtosis e numero di trial.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:21:35 +02:00
Adriano 2687ce7dd2 feat(metrics): Sharpe + max drawdown + total return
Metriche base per valutazione strategie: Sharpe annualizzato
(default 8760 periodi/anno per dati orari), max drawdown
percentuale dalla curva equity, total return cumulativo.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:18:48 +02:00
Adriano 9301ab9051 feat(backtest): event-driven engine with 1-bar exec delay
Engine sincrono bar-per-bar con delay 1: segnale a t-1 esegue a open di t
per evitare lookahead. Position sizing 1 unit, fees su entry+exit,
mark-to-market su close, chiusura forzata posizione open a fine serie.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:15:05 +02:00
Adriano 36e05233d0 feat(backtest): Order/Position/Trade dataclasses with fees
Side StrEnum (long/short/flat), frozen dataclasses con calcolo
unrealized_pnl per Position e gross/fees/net_pnl per Trade
(fees in basis point, default 5bp). 4 test TDD passing,
ruff + mypy strict clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:11:27 +02:00
Adriano d30f981421 feat(data): expanding walk-forward splits
Aggiunge expanding_walk_forward e dataclass Split per generare fold
walk-forward con train che cresce e test sulla finestra successiva.
Rispetta min_train_days e ritorna lista vuota su fold troppo piccoli.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:08:43 +02:00
Adriano 116879400a fix(data): restore pagination early-break + update test count
Code review on b977c37 flagged: with dataset smaller than limit=1000
(typical Phase 1 case), the loop made an extra HTTP request that
returned duplicate rows. Restored `if len(rows) < limit: break`
after extending. Test assertion adjusted from 2 to 1 calls.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:06:50 +02:00
Adriano b977c371e5 feat(data): OHLCV loader via ccxt with parquet cache
Adjust .gitignore to keep src/multi_swarm/data/ tracked (only
top-level /data/ cache directory remains ignored).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:01:25 +02:00
Adriano b73416f482 feat(config): pydantic settings loader from .env
Aggiunge Settings (BaseSettings) che carica configurazione da
variabili d'ambiente / file .env, con validazione obbligatoria
dei segreti Cerbero testnet e OpenRouter.

Test:
- test_settings_loads_from_env: happy path via monkeypatch.setenv
- test_settings_requires_tokens: ValidationError quando token
  obbligatori mancano (forza _env_file=None per isolare il test
  da eventuale .env locale popolato).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 18:55:04 +02:00
Adriano 362ffb33a8 chore: project skeleton with uv + pyproject + deps
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 18:49:27 +02:00