src.trading.money_manager

πŸ¦‰ AthenaAI is an AI-powered ensemble machine-learning trading bot for PocketOption, built on BinaryOptionsToolsV2 β†’ Get it on GitLab
πŸ’¬ Need help? Join the Chipa Discord Β· ⚑ Go no-code with ChipaEditor

Source: src/trading/money_manager.py. MoneyManager owns two things: the daily P&L stop and the stake size for each trade.

class MoneyManager

__init__(self, cfg: BotConfig)

ParameterTypeMeaning
cfgBotConfigReads base_stake, max_stake, kelly_fraction, max_daily_loss

Initialises daily_pnl = 0.0 and day_start to today’s UTC date.

reset_if_new_day(self) -> None

If the current UTC date differs from day_start, logs New day β€” resetting daily P&L tracker and zeroes daily_pnl. Called automatically by can_trade().

can_trade(self) -> bool

Calls reset_if_new_day(), then returns daily_pnl > -cfg.max_daily_loss. With the default max_daily_loss = 300.0, trading stops for the rest of the UTC day once the day’s losses reach $300. Note the state is in-memory only β€” restarting the bot resets the daily P&L.

compute_stake(self, confidence: float, win_rate: float, payout: float = 0.85) -> float

ParameterTypeDefaultMeaning
confidencefloatβ€”Ensemble confidence for this trade (fraction)
win_ratefloatβ€”Session win rate from PerformanceTracker.win_rate (0.5 with no history)
payoutfloat0.85Broker payout fraction (b in Kelly). The bot passes 0.85

Returns the stake in $, rounded to 2 decimals, always within [base_stake, max_stake].

Algorithm:

  1. If payout <= 0 β†’ base_stake.
  2. Kelly edge: edge = win_rate * payout βˆ’ (1 βˆ’ win_rate). If edge <= 0 (no statistical edge) β†’ base_stake.
  3. kelly = edge / payout; fraction = kelly * cfg.kelly_fraction (half-Kelly by default).
  4. stake = base_stake + fraction * (max_stake βˆ’ base_stake) β€” Kelly interpolates between the floor and the ceiling rather than sizing off a bankroll.
  5. Confidence scaling (v6, gentler than the old formula that crushed stakes to $1–3): stake *= max(0.5, (confidence βˆ’ 0.45) * 2.0) β€” 60% conf β†’ 0.50Γ—, 65% β†’ 0.65Γ—, 70% β†’ 0.80Γ—, 75% β†’ 0.95Γ—.
  6. Clamp to [base_stake, max_stake] and round.

No side effects. Because of step 2, a bot with win rate ≀ breakeven always bets exactly base_stake.

record(self, pnl: float) -> None

Adds pnl ($, signed) to daily_pnl. Called by _result_checker() in src/bot.py for every resolved trade.

Usage example

from src.config import BotConfig
from src.trading.money_manager import MoneyManager

mm = MoneyManager(BotConfig())
stake = mm.compute_stake(confidence=0.68, win_rate=0.58, payout=0.85)  # e.g. 41.19
mm.record(-stake)          # a loss
print(mm.can_trade())      # True until daily_pnl <= -300.0

Risk note

This class is the only thing standing between the model and your balance. max_daily_loss resets on UTC day boundaries and on process restart. Binary options trading can lose money; past performance does not guarantee future results. See the risk management guide.

See also

πŸ’¬ Unsure how this interacts with the rest of the configuration? Ask in the Chipa Discord β€” or prototype strategies no-code with ChipaEditor.