Saltar al contenido principal

Recipe: add a strategy

The 5-minute happy path:

  1. Subclass IStrategy (or FrameworkAlgorithm) under alphaswarm/strategies/.
  2. Decorate with @register("MyName", kind="alpha") from alphaswarm/core/registry.py.
  3. Ship a YAML at configs/strategies/<my-name>.yaml using the class / module_path / kwargs factory pattern.
  4. Smoke-test:
docker exec alphaswarm-api python -m alphaswarm.cli.cli backtest \
--config configs/strategies/<my-name>.yaml \
--start 2024-01-01 --end 2024-06-30

If the smoke run lands a backtest_runs row with a non-NULL sharpe, you are done.

Pitfalls

  • Forgetting @register. YAML loaders fail silently; the run errors out as StrategyRegistryMissError.
  • Putting strategy logic in a route or task. Don't. Routes thin wrap Celery tasks; Celery tasks thin wrap pure functions under alphaswarm/strategies/. See AGENTS Don'ts.
  • Skipping risk overlays. Every strategy ships with a risk: block in YAML. Without it, the paper-metadata gate refuses to promote the strategy.

Deeper reads