From cc21ebf4c5c594bdf40bc1ba39a14c5335b2aa48 Mon Sep 17 00:00:00 2001 From: Peter Jung Date: Thu, 17 Oct 2024 14:50:38 +0200 Subject: [PATCH] Pass fees to Kelly (#507) --- .../deploy/betting_strategy.py | 63 +++++++------------ .../betting_strategies/kelly_criterion.py | 2 +- tests_integration/markets/omen/test_kelly.py | 4 +- 3 files changed, 26 insertions(+), 43 deletions(-) diff --git a/prediction_market_agent_tooling/deploy/betting_strategy.py b/prediction_market_agent_tooling/deploy/betting_strategy.py index 35a9711d..07b04220 100644 --- a/prediction_market_agent_tooling/deploy/betting_strategy.py +++ b/prediction_market_agent_tooling/deploy/betting_strategy.py @@ -19,7 +19,6 @@ ) from prediction_market_agent_tooling.tools.betting_strategies.kelly_criterion import ( get_kelly_bet_full, - get_kelly_bet_simplified, ) from prediction_market_agent_tooling.tools.betting_strategies.utils import SimpleBet from prediction_market_agent_tooling.tools.utils import check_not_none @@ -153,25 +152,17 @@ def calculate_trades( market: AgentMarket, ) -> list[Trade]: outcome_token_pool = check_not_none(market.outcome_token_pool) - kelly_bet = ( - get_kelly_bet_full( - yes_outcome_pool_size=outcome_token_pool[ - market.get_outcome_str_from_bool(True) - ], - no_outcome_pool_size=outcome_token_pool[ - market.get_outcome_str_from_bool(False) - ], - estimated_p_yes=answer.p_yes, - max_bet=self.max_bet_amount, - confidence=answer.confidence, - ) - if market.has_token_pool() - else get_kelly_bet_simplified( - self.max_bet_amount, - market.current_p_yes, - answer.p_yes, - answer.confidence, - ) + kelly_bet = get_kelly_bet_full( + yes_outcome_pool_size=outcome_token_pool[ + market.get_outcome_str_from_bool(True) + ], + no_outcome_pool_size=outcome_token_pool[ + market.get_outcome_str_from_bool(False) + ], + estimated_p_yes=answer.p_yes, + max_bet=self.max_bet_amount, + confidence=answer.confidence, + fees=market.fees, ) kelly_bet_size = kelly_bet.size @@ -230,7 +221,7 @@ def calculate_price_impact_deviation_from_target_price_impact( bet_amount, yes_outcome_pool_size, no_outcome_pool_size, - MarketFees.get_zero_fees(), # TODO: Use market.fees + market.fees, ) # We return abs for the algorithm to converge to 0 instead of the min (and possibly negative) value. @@ -289,25 +280,17 @@ def calculate_trades( estimated_p_yes = float(answer.p_yes > 0.5) confidence = 1.0 - kelly_bet = ( - get_kelly_bet_full( - yes_outcome_pool_size=outcome_token_pool[ - market.get_outcome_str_from_bool(True) - ], - no_outcome_pool_size=outcome_token_pool[ - market.get_outcome_str_from_bool(False) - ], - estimated_p_yes=estimated_p_yes, - max_bet=adjusted_bet_amount, - confidence=confidence, - ) - if market.has_token_pool() - else get_kelly_bet_simplified( - adjusted_bet_amount, - market.current_p_yes, - estimated_p_yes, - confidence, - ) + kelly_bet = get_kelly_bet_full( + yes_outcome_pool_size=outcome_token_pool[ + market.get_outcome_str_from_bool(True) + ], + no_outcome_pool_size=outcome_token_pool[ + market.get_outcome_str_from_bool(False) + ], + estimated_p_yes=estimated_p_yes, + max_bet=adjusted_bet_amount, + confidence=confidence, + fees=market.fees, ) amounts = { diff --git a/prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py b/prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py index 134cb2a0..c7ff990d 100644 --- a/prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py +++ b/prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py @@ -62,7 +62,7 @@ def get_kelly_bet_full( estimated_p_yes: float, confidence: float, max_bet: float, - fees: MarketFees = MarketFees.get_zero_fees(), # TODO: Remove default value. + fees: MarketFees, ) -> SimpleBet: """ Calculate the optimal bet amount using the Kelly Criterion for a binary outcome market. diff --git a/tests_integration/markets/omen/test_kelly.py b/tests_integration/markets/omen/test_kelly.py index 015a1d06..5b3f7717 100644 --- a/tests_integration/markets/omen/test_kelly.py +++ b/tests_integration/markets/omen/test_kelly.py @@ -91,7 +91,7 @@ def assert_price_impact_converges( estimated_p_yes=p_yes, max_bet=max_bet_amount, confidence=confidence, - # fees=omen_agent_market.fees, TODO: Uncomment + fees=omen_agent_market.fees, ) kelly = KellyBettingStrategy( @@ -106,7 +106,7 @@ def assert_price_impact_converges( bet_amount=max_price_impact_bet_amount, yes=yes_outcome_pool_size, no=no_outcome_pool_size, - fees=MarketFees.get_zero_fees(), # TODO: Use fees=omen_agent_market.fees + fees=omen_agent_market.fees, ) # assert convergence