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 alphaswarm-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. alphaswarm.core.registry.resolve can't find the alias and the run errors out with KeyError: Cannot resolve class reference: '<MyName>'.
  • 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 the paper-metadata gate. Promoting a bot/strategy to a paper session requires a valid model_urn + pipeline_urn pair resolvable in entity_aspects (model status Production or Staging) — see Concept: paper metadata gate. Risk limits for a bot live in BotSpec.risk_layer, not in the strategy YAML.

Deeper reads​