Skip to content

ExecutionEngine: PositionEffect Loop and Order Execution #111

Description

@Muratich

Depends on: #110
Design doc: docs/strategy_composable_engine_design.md (§1.4–1.5, Engine changes)

Engine runtime for the composable action system.
Does NOT implement @register_action handlers — Philip owns those in #110.

Scope:

  • Add Portfolio.effects: list[PositionEffect] (internal SL/TP/trailing state)
  • Expose API so buy action handler (Predicates, Rules, Action registry #110) can attach effects when
    stop_loss_pct / take_profit_pct are set on a buy
  • Each bar, before strategy:
    1. Check PositionEffects → if triggered, close position
    2. strategy.on_candle() → Signal
    3. OrderExecutor.execute(signal) → update portfolio / trade log
  • Legacy Python strategies unchanged (no effects, same bar loop)
  • After one composable backtest: call calculate_metrics_from_trade_log()
    from src/analytics/ (same path as legacy)
  • For each combo: run backtest → calculate_metrics_from_trade_log() → collect (params, MetricsReport); skip empty/failed runs (just do not repeat same calculations)

Out of scope:

Definition of Done:

  • Bar loop order: effects → strategy → executor
  • Unit tests: SL effect closes position, TP effect closes position
  • Legacy strategies still backtest with no changes
  • One composable backtest → trade log + MetricsReport
  • Philip confirms portfolio.effects API works with buy handler

Metadata

Metadata

Assignees

Labels

Type

Fields

No fields configured for Task.

Projects

Status
In progress

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions