P1: Risk management (stop-loss/take-profit) not implemented #28

Closed
opened 2026-04-09 07:12:02 +02:00 by shoko · 0 comments
Owner

Problem

The database schema and frontend UI support risk_management configuration (stop_loss_percent, take_profit_percent), but neither engine implements the logic.

Evidence

Frontend Types:

export interface RiskManagement {
    stop_loss_percent?: number;
    take_profit_percent?: number;
}

But engines ignore it:

  • backtest/engine.py - No stop-loss/take-profit checks
  • simulate/engine.py - Same issue

Solution

Implement stop-loss and take-profit checks in both engines after a trade is executed.

Logic Flow

After Buy Execution:
1. Record entry price and position size
2. On each tick, check:
   - If current_price <= entry_price * (1 - stop_loss_percent/100) -> SELL (stop-loss)
   - If current_price >= entry_price * (1 + take_profit_percent/100) -> SELL (take-profit)
3. Record realized P&L

Acceptance Criteria

  • Backtest engine respects stop_loss_percent
  • Backtest engine respects take_profit_percent
  • Simulate engine respects stop_loss_percent
  • Simulate engine respects take_profit_percent
  • Results show exit reasons (stop-loss, take-profit, or end of period)
## Problem The database schema and frontend UI support `risk_management` configuration (stop_loss_percent, take_profit_percent), but neither engine implements the logic. ### Evidence **Frontend Types:** ```typescript export interface RiskManagement { stop_loss_percent?: number; take_profit_percent?: number; } ``` **But engines ignore it:** - `backtest/engine.py` - No stop-loss/take-profit checks - `simulate/engine.py` - Same issue ## Solution Implement stop-loss and take-profit checks in both engines after a trade is executed. ### Logic Flow ``` After Buy Execution: 1. Record entry price and position size 2. On each tick, check: - If current_price <= entry_price * (1 - stop_loss_percent/100) -> SELL (stop-loss) - If current_price >= entry_price * (1 + take_profit_percent/100) -> SELL (take-profit) 3. Record realized P&L ``` ## Acceptance Criteria - [ ] Backtest engine respects stop_loss_percent - [ ] Backtest engine respects take_profit_percent - [ ] Simulate engine respects stop_loss_percent - [ ] Simulate engine respects take_profit_percent - [ ] Results show exit reasons (stop-loss, take-profit, or end of period)
shoko added the enhancement label 2026-04-09 07:12:02 +02:00
shoko closed this issue 2026-04-09 11:39:50 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shoko/randebu#28