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)
| Parameter | Type | Meaning |
|---|---|---|
cfg | BotConfig | Reads 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
| Parameter | Type | Default | Meaning |
|---|---|---|---|
confidence | float | β | Ensemble confidence for this trade (fraction) |
win_rate | float | β | Session win rate from PerformanceTracker.win_rate (0.5 with no history) |
payout | float | 0.85 | Broker 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:
- If
payout <= 0βbase_stake. - Kelly edge:
edge = win_rate * payout β (1 β win_rate). Ifedge <= 0(no statistical edge) βbase_stake. kelly = edge / payout;fraction = kelly * cfg.kelly_fraction(half-Kelly by default).stake = base_stake + fraction * (max_stake β base_stake)β Kelly interpolates between the floor and the ceiling rather than sizing off a bankroll.- 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Γ. - 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.0Risk 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.