# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## What this repo is A **manual Excel-first backtesting journal** for blackbox trading signals (M2D strategy primarily). There is no live data ingestion, no broker integration, no vision pipeline — the user types each trade into `data/backtest.xlsx` and Excel formulas compute everything else. The Python codebase is one script that regenerates the workbook template. The project was recently rebooted (commit `0179217`) — an earlier vision/screenshot extraction pipeline was removed in favor of this manual Excel approach. Do not reintroduce vision/OCR/auto-extraction features unless explicitly asked. Documentation and UI strings are in **Romanian**; keep them Romanian when editing. ## Commands ```powershell pip install openpyxl # one-time python scripts/generate_template.py # regenerate data/backtest.xlsx (Config + Trades only) python scripts/generate_dashboard.py # regenerate data/Dashboard.xlsx din backtest.xlsx ``` `refresh_dashboard.bat` (rădăcina repo) = wrapper dublu-click: rulează `generate_dashboard.py` și deschide `Dashboard.xlsx`. No test suite, linter, or build step exists. The only "build" is regenerating the Excel. **Destructive caveat**: `generate_template.py` **overwrites `data/backtest.xlsx` with no prompt**. The user's logged trades live in that file. Before running it (or asking the user to), confirm they have a backup or that the file is empty/sample-only. ## Architecture Three artifacts work together; understand all three before editing any: ### 1. `scripts/generate_template.py` — the only code `build_workbook()` builds `data/backtest.xlsx` = **2 sheets only** (Config + Trades). `build_dashboard()` still lives here but is **no longer added to backtest.xlsx** — it is reused by `scripts/generate_dashboard.py` to build the separate `data/Dashboard.xlsx` (see "Dashboard separat" below). - **Config** sheet — editable params (Account Size, Risk %) and dropdown source lists. - **Trades** sheet — `MAX_ROWS=500` pre-populated rows. Yellow cells = user input (date, time, strategy, indicator, TF, direction, SL/TP %, outcome). Blue cells = derived via formula (Zi, Sesiune, then per-strategy `R_*`, `$_*`, `Bal_*`). Grey cells = helper columns (`Win_*`, `Peak_*`, `DD_*`) consumed by Dashboard. - **Dashboard** (`build_dashboard`, emitted into the separate `Dashboard.xlsx`) — reads from Trades ranges via `SUMIF`/`AVERAGEIF`/`COUNTIF`; renders metrics table, glossary, per-Session/Strategy/Indicator/Direction breakdowns, ferestre candidate, prop compliance. **No equity-curve chart** (removed — Dashboard is pure-tabular). Column-name → letter mapping is held in the `COL` dict, built from `TRADES_HEADERS = INPUT_HEADERS + DERIVED_HEADERS + HELPER_HEADERS`. **Never hardcode column letters** — adding/reordering a header shifts every letter. Always look up via `COL["..."]`. ### 2. The 5 management strategies — core domain concept Every trade is simulated through 5 management overlays in parallel. Keys (`STRAT_KEYS`) and their R-multiple formula builders (`R_FN`) must stay in sync: | Key | Label | Formula entry point | |---|---|---| | `tp0only` | TP0 only | `_f_r_tp0only` | | `tp1only` | TP1 only | `_f_r_tp1only` | | `tp2only` | TP2 only | `_f_r_tp2only` | | `hybrid_be` | Hybrid + BE | `_f_r_hybrid_be` | | `hybrid_nobe` | Hybrid no BE | `_f_r_hybrid_nobe` | For each strategy and each trade row, six columns are emitted: `R_*`, `$_*`, `Bal_*`, `Win_*`, `Peak_*`, `DD_*`. Adding a 6th strategy means: append to `STRAT_KEYS` + `STRAT_LABELS`, add an `_f_r_` formula, register it in `R_FN`, and the rest (Trades columns, Dashboard table column, equity-curve series) flows automatically. The R-multiple formulas encode trader assumptions — the truth table is documented in `README.md` and `STOPPING_RULE.md`; changing one is a strategy decision, not a refactor. ### 3. Session derivation (M2D-specific) The `Sesiune` column is computed by `_f_session` from `Data` + `Ora RO` (Romanian time) using nested IFs encoding the M2D session windows (A1/A2/A3/B/C/D/Other). The buckets and times come from `strategie_M2D.md`. If asked to add a new session bucket, edit `_f_session` and `SESSIONS` together — Dashboard's PER SESIUNE breakdown iterates over `SESSIONS`. ## Decision gates — `STOPPING_RULE.md` `STOPPING_RULE.md` is a **signed document** (the user committed it as a commitment). It defines GO LIVE / EXTEND / ABANDON thresholds: `N≥40`, `WR≥55%`, `Expectancy≥+0.20R`. Treat these numbers as fixed unless the user explicitly asks to renegotiate them — do not "improve" them in passing. ## Ferestre v2 — analiză edge/fereastră (scripts/generate_ferestre_v2.py) Analiză separată care găsește **fereastra de timp (ora RO) cu cel mai bun raport edge / nr. tranzacții / durată**, fără să breach-uiască contul prop. Citește `data/backtest.xlsx` **read-only** și scrie un fișier nou `data/Ferestre_v2.xlsx` (NU atinge workbook-ul cu tranzacții; date_grafic rămâne sheet vizibil ca să se randeze chart-ul). **Reluare după ce Marius adaugă tranzacții noi:** ```powershell python scripts/generate_ferestre_v2.py ``` Totul se recalculează automat din `backtest.xlsx` (R/$ deja calculate de Excel; scriptul nu recalculează formule). Conține: Concluzii, Tabel unic cu toate variantele, validări Forward 1 (lunar) / Forward 2 (train-test 70/30) / Walk-forward (3 felii) pe toate ferestrele, bootstrap CI, calendar, grafic echitate. **ÎNAINTE de analiză — verifică typo-uri de tastare în Trades** (TP%/SL% cu zecimală lipsă umflă fals edge-ul). Cele găsite și corectate manual: #314 (TP2 17→0.17), #298 (TP0 0.5→0.05), #240 (TP1 0.8→0.08). La date noi, caută valori TP/SL ≥1 sau TP0>TP1>TP2 inversate și confirmă cu Marius înainte de a corecta. **Findings curente (330 trade-uri, ian–mai 2026, doar `hybrid_be` e pozitiv pe ansamblu ~+0.05R):** edge-ul vine din CÂND, nu din management; 18:00–19:00 RO = zonă moartă; ora de start optimă = 19:15. Trei configurații recomandate: **A** 19:15–20:15 (1h, edge max/timp min), **B** 19:45–21:45 prima (cea mai robustă pe toate validările), **W** 19:15–22:15 prima (volum/bani max raportat la timp; +30 min până la 22:45 aduc doar ~+$61). Filtrele direcționale (buy) par mai bune dar pică out-of-sample. Edge subțire → ipoteze de confirmat live. ## Dashboard separat (scripts/generate_dashboard.py) `backtest.xlsx` ajunsese ~39 MB și se salva greu. Cauza NU erau tranzacțiile, ci **sheet-ul Dashboard** (~4.200 coloane-helper ascunse → ~2,1M celule cu formule în `calcChain.xml`). Soluție: Dashboard-ul a fost scos din fișierul editat zilnic într-un fișier separat, generat la comandă (același tipar ca Ferestre v2). **Cele 3 fișiere:** - `data/backtest.xlsx` — **editat zilnic**, doar Config + Trades (~0.8 MB, rapid la salvat). - `data/Dashboard.xlsx` — **generat read-only** de `generate_dashboard.py` din backtest.xlsx. Conține un sheet `Trades` ascuns cu **valori statice** (copiate din cache-ul Excel) + sheet-ul Dashboard cu formulele reutilizate din `build_dashboard()`. Marius nu-l editează niciodată — se regenerează. - `data/Ferestre_v2.xlsx` — analiza edge/fereastră (separată, vezi mai sus). **Reluare după tranzacții noi:** ```powershell # întâi: deschide & SALVEAZĂ backtest.xlsx în Excel (populează cache-ul de valori R_/$_/Bal_) python scripts/generate_dashboard.py # sau dublu-click refresh_dashboard.bat ``` `generate_dashboard.py` citește `backtest.xlsx` **read-only, `data_only=True`** — ia valorile DEJA calculate de Excel (nu recalculează formule). **Constrângere:** dacă nu ai salvat în Excel după ultima editare, cache-ul lipsește și Dashboard-ul iese gol (aceeași condiție ca Ferestre v2). **Sincronizare:** la comandă (rulezi scriptul/bat-ul), NU live. Marius a ales explicit acest model. **Migrare unică — `scripts/strip_dashboard.py`:** scoate sheet-ul Dashboard din `backtest.xlsx` existent (39 MB → ~0.8 MB). NU folosește openpyxl pentru rescriere (ar șterge cele 12 dropdown-uri **x14** din Trades). Face **chirurgie pe zip**: elimină doar partea Dashboard + drawings/charts + `calcChain.xml` + definedName-ul orfan, lăsând XML-ul Config/Trades byte-cu-byte intact. Cere `--yes` și face backup automat. Alternativă 100% sigură: șterge tab-ul Dashboard manual în Excel (click-dreapta → Delete → Save). **Rulează doar cu acordul lui Marius** (e destructiv pe fișierul real). **Escape hatch dimensiune Dashboard.xlsx:** `Config!B17` (Activează filtru Prima) = `NU` reduce drastic grid-ul de ferestre → Dashboard.xlsx mult mai mic/rapid. ## Reference docs - `strategie_M2D.md` — M2D setup rules (color-coded dot bands on TF mare/mic, SL/TP placement, session filters). - `calendar_evenimente.yaml` — manual news calendar (FOMC/NFP/CPI). Read-only context; not parsed by code. - `README.md` — user-facing workflow + R-multiple truth table. ## Working in this repo - The user is **Marius**, a discretionary trader doing his own backtest, not an engineer building a product. Prefer minimal, legible changes to the Excel template over abstractions. The audience is one person logging trades, not a team. - When changing formulas in `generate_template.py`, regenerate the workbook and inspect at least one row's outputs before declaring done — a formula typo silently breaks the entire downstream Dashboard. - The git user is `Marius` on branch `master` (not `main`); PRs are not the workflow here, direct commits to `master` are. ## gstack Use the `/browse` skill from gstack for all web browsing. Never use `mcp__claude-in-chrome__*` tools. Available gstack skills: `/office-hours`, `/plan-ceo-review`, `/plan-eng-review`, `/plan-design-review`, `/design-consultation`, `/design-shotgun`, `/design-html`, `/review`, `/ship`, `/land-and-deploy`, `/canary`, `/benchmark`, `/browse`, `/connect-chrome`, `/qa`, `/qa-only`, `/design-review`, `/setup-browser-cookies`, `/setup-deploy`, `/setup-gbrain`, `/retro`, `/investigate`, `/document-release`, `/document-generate`, `/codex`, `/cso`, `/autoplan`, `/plan-devex-review`, `/devex-review`, `/careful`, `/freeze`, `/guard`, `/unfreeze`, `/gstack-upgrade`, `/learn`.