diff --git a/.gitignore b/.gitignore index 3d84c3e..d6d1a85 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ logs/ build/ dist/ *.egg + +# Pythagoras source PDFs (local only, not tracked) +src/strategy_pythagoras/Pythagoras/*.pdf diff --git a/pyproject.toml b/pyproject.toml index 5e0daed..602ec92 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,14 +10,16 @@ requires-python = ">=3.13" dependencies = [ "multi-swarm-core", "strategy-crypto", + "strategy-pythagoras", ] [tool.uv.workspace] -members = ["src/multi_swarm_core", "src/strategy_crypto"] +members = ["src/multi_swarm_core", "src/strategy_crypto", "src/strategy_pythagoras"] [tool.uv.sources] multi-swarm-core = { workspace = true } strategy-crypto = { workspace = true } +strategy-pythagoras = { workspace = true } [dependency-groups] dev = [ @@ -42,7 +44,7 @@ python_version = "3.13" strict = true [tool.pytest.ini_options] -testpaths = ["src/multi_swarm_core/tests", "src/strategy_crypto/tests"] +testpaths = ["src/multi_swarm_core/tests", "src/strategy_crypto/tests", "src/strategy_pythagoras/tests"] addopts = "-v --tb=short --import-mode=importlib" markers = [ "integration: tests that require external services (Cerbero, LLM API)", diff --git a/src/strategy_pythagoras/README.md b/src/strategy_pythagoras/README.md new file mode 100644 index 0000000..7fd4e36 --- /dev/null +++ b/src/strategy_pythagoras/README.md @@ -0,0 +1,78 @@ +# strategy_pythagoras + +Strategia di trading basata sul framework **Pythagoras-Malanga** +(candle-pattern + geometria frattale), evoluta via GA sul core +`multi_swarm_core`. Workspace member del monorepo `multi_swarm_coevolutive`. + +## Scope + +Pipeline coevolutiva su candele OHLC: il GA del core esplora combinazioni +di indicatori candle-pattern, geometria pitagorica e ratio frattali, e +produce strategie JSON freezate. Questo member le esegue in +**paper-trading forward-test** ed espone una dashboard NiceGUI per +analisi invarianza scala/tick e candle. + +## Layout + +``` +strategy_pythagoras/ +├── backend/ paper trading runner (PaperExecutor, Portfolio, PaperRepository) +│ └── schema.py tabelle paper_trading_* (DB locale dedicato) +├── frontend/ NiceGUI dashboard (tab invariance, candle, equity, ticks) +├── strategies/ JSON freezate input al runner +│ (pythagoras_*.json) +└── prompts.json 7 stili di prompt LLM (candle-pattern, frattale, ratio, + pivot, kagi, renko, hybrid) +``` + +## Run paper-trading smoke + +```bash +uv run python scripts/run_pythagoras_smoke.py \ + --name pythagoras-smoke-001 \ + --initial-capital 1000 \ + --poll-seconds 300 +``` + +Il default `--strategies-dir` punta ai JSON shippati col package via +`importlib.resources.files("strategy_pythagoras") / "strategies"`. + +## Dashboard + +```bash +uv run python -m strategy_pythagoras.frontend.nicegui_app +``` + +In produzione: `https://swarm.tielogic.xyz/strategy_pythagoras_gui/` +(root_path configurato via `DASHBOARD_ROOT_PATH=/strategy_pythagoras_gui`). + +## DB schema + +Schema isolato dal core e dalle altre strategie. Due DB distinti: + +- `state/strategy_pythagoras.db` — GA + analisi invarianza + (env `STRATEGY_PYTHAGORAS_DB_PATH`) +- `state/strategy_pythagoras_paper.db` — paper-trading runs + (env `STRATEGY_PYTHAGORAS_PAPER_DB_PATH`) + +Tabelle paper-trading: + +- `paper_trading_runs` — metadata run (id, name, capital, status) +- `paper_trading_positions` — posizioni aperte (long/short) +- `paper_trading_trades` — trade realized (entry/exit, pnl, fees) +- `paper_trading_equity` — equity curve snapshot +- `paper_trading_ticks` — log signal/action per ogni bar + +DDL gestito da `strategy_pythagoras.backend.schema.init_schema()`. + +La dashboard legge **anche** il `runs.db` del core GA (env `GA_DB_PATH`) +per correlare paper performance con i genomi di provenienza e con i +risultati di fitness invariance. + +## References + +- Spec: `docs/superpowers/specs/2026-05-19-strategy-pythagoras-design.md` +- Plan: `docs/superpowers/plans/2026-05-19-strategy-pythagoras.md` +- Summary paper: `Pythagoras/Pythagoras_Trading_Prediction.summary.md` +- Summary frattali: `Pythagoras/Libro_frattali.summary.md` +- Pattern member: vedi `src/strategy_crypto/README.md` diff --git a/src/strategy_pythagoras/pyproject.toml b/src/strategy_pythagoras/pyproject.toml new file mode 100644 index 0000000..8ab71ce --- /dev/null +++ b/src/strategy_pythagoras/pyproject.toml @@ -0,0 +1,21 @@ +[project] +name = "strategy-pythagoras" +version = "0.1.0" +description = "Strategy Pythagoras: candle-pattern GA su framework Pythagoras-Malanga, paper-trading runner + NiceGUI dashboard" +authors = [{ name = "Adriano Dal Pastro", email = "adrianodalpastro@tielogic.com" }] +requires-python = ">=3.13" +dependencies = [ + "multi-swarm-core", + "nicegui>=3.11.1", + "plotly>=5.24", + "pandas>=2.2", + "pyarrow>=18.0", +] + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.hatch.build.targets.wheel.force-include] +"strategy_pythagoras/strategies" = "strategy_pythagoras/strategies" +"strategy_pythagoras/prompts.json" = "strategy_pythagoras/prompts.json" diff --git a/src/strategy_pythagoras/strategy_pythagoras/__init__.py b/src/strategy_pythagoras/strategy_pythagoras/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/strategy_pythagoras/strategy_pythagoras/backend/__init__.py b/src/strategy_pythagoras/strategy_pythagoras/backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/strategy_pythagoras/strategy_pythagoras/frontend/__init__.py b/src/strategy_pythagoras/strategy_pythagoras/frontend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/strategy_pythagoras/strategy_pythagoras/prompts.json b/src/strategy_pythagoras/strategy_pythagoras/prompts.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/src/strategy_pythagoras/strategy_pythagoras/prompts.json @@ -0,0 +1 @@ +{} diff --git a/src/strategy_pythagoras/strategy_pythagoras/strategies/.gitkeep b/src/strategy_pythagoras/strategy_pythagoras/strategies/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/strategy_pythagoras/tests/__init__.py b/src/strategy_pythagoras/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/uv.lock b/uv.lock index d2e48fa..ceb21f6 100644 --- a/uv.lock +++ b/uv.lock @@ -18,6 +18,7 @@ members = [ "multi-swarm-coevolutive", "multi-swarm-core", "strategy-crypto", + "strategy-pythagoras", ] [[package]] @@ -900,6 +901,7 @@ source = { virtual = "." } dependencies = [ { name = "multi-swarm-core" }, { name = "strategy-crypto" }, + { name = "strategy-pythagoras" }, ] [package.dev-dependencies] @@ -917,6 +919,7 @@ dev = [ requires-dist = [ { name = "multi-swarm-core", editable = "src/multi_swarm_core" }, { name = "strategy-crypto", editable = "src/strategy_crypto" }, + { name = "strategy-pythagoras", editable = "src/strategy_pythagoras" }, ] [package.metadata.requires-dev] @@ -1980,6 +1983,27 @@ requires-dist = [ { name = "pyarrow", specifier = ">=18.0" }, ] +[[package]] +name = "strategy-pythagoras" +version = "0.1.0" +source = { editable = "src/strategy_pythagoras" } +dependencies = [ + { name = "multi-swarm-core" }, + { name = "nicegui" }, + { name = "pandas" }, + { name = "plotly" }, + { name = "pyarrow" }, +] + +[package.metadata] +requires-dist = [ + { name = "multi-swarm-core", editable = "src/multi_swarm_core" }, + { name = "nicegui", specifier = ">=3.11.1" }, + { name = "pandas", specifier = ">=2.2" }, + { name = "plotly", specifier = ">=5.24" }, + { name = "pyarrow", specifier = ">=18.0" }, +] + [[package]] name = "tenacity" version = "9.1.4"