-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Expand file tree
/
Copy pathengine.py
More file actions
38 lines (27 loc) · 1.26 KB
/
Copy pathengine.py
File metadata and controls
38 lines (27 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from __future__ import annotations
from dataclasses import dataclass
from polymarket_bot.config.settings import RiskConfig, StrategyConfig
@dataclass
class TradeDecision:
should_trade: bool
side: str | None
size_fraction: float
expected_value: float
reason: str
class DecisionEngine:
def __init__(self, risk: RiskConfig, strategy: StrategyConfig):
self.risk = risk
self.strategy = strategy
def evaluate(self, prob_yes: float, yes_price: float, liquidity: float) -> TradeDecision:
if liquidity < self.risk.min_liquidity:
return TradeDecision(False, None, 0.0, 0.0, "liquidity_too_low")
if prob_yes < self.risk.min_probability:
return TradeDecision(False, None, 0.0, 0.0, "probability_below_threshold")
b = (1 - yes_price) / yes_price
q = 1 - prob_yes
kelly_f = max(0.0, (b * prob_yes - q) / b) if b > 0 else 0.0
size = min(kelly_f, self.strategy.kelly_fraction_cap, self.risk.max_risk_per_trade)
ev = prob_yes * (1 - yes_price) - (1 - prob_yes) * yes_price - self.strategy.fee_rate
if ev <= 0 or size <= 0:
return TradeDecision(False, None, 0.0, ev, "non_positive_ev_or_size")
return TradeDecision(True, "YES", size, ev, "ok")