From 657d27a9d2f3c5b72593e1135333fd5f9180fd0e Mon Sep 17 00:00:00 2001 From: Peter Jung Date: Thu, 24 Oct 2024 10:25:55 +0200 Subject: [PATCH] Fix betting benchmark (#526) --- .../match_bets_with_langfuse_traces.py | 20 +++++++++++-------- .../deploy/betting_strategy.py | 6 +++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/examples/monitor/match_bets_with_langfuse_traces.py b/examples/monitor/match_bets_with_langfuse_traces.py index 11f09244..b048777f 100644 --- a/examples/monitor/match_bets_with_langfuse_traces.py +++ b/examples/monitor/match_bets_with_langfuse_traces.py @@ -8,6 +8,7 @@ from prediction_market_agent_tooling.config import APIKeys from prediction_market_agent_tooling.deploy.betting_strategy import ( BettingStrategy, + GuaranteedLossError, KellyBettingStrategy, MaxAccuracyBettingStrategy, MaxAccuracyWithKellyScaledBetsStrategy, @@ -50,14 +51,17 @@ def get_outcome_for_trace( market = trace.market answer = trace.answer - trades = strategy.calculate_trades( - existing_position=None, - answer=ProbabilisticAnswer( - p_yes=answer.p_yes, - confidence=answer.confidence, - ), - market=market, - ) + try: + trades = strategy.calculate_trades( + existing_position=None, + answer=ProbabilisticAnswer( + p_yes=answer.p_yes, + confidence=answer.confidence, + ), + market=market, + ) + except GuaranteedLossError: + return None # For example, when our predicted p_yes is 95%, but market is already trading at 99%, and we don't have anything to sell, Kelly will yield no trades. if not trades: return None diff --git a/prediction_market_agent_tooling/deploy/betting_strategy.py b/prediction_market_agent_tooling/deploy/betting_strategy.py index f4761b37..f1ec7f1e 100644 --- a/prediction_market_agent_tooling/deploy/betting_strategy.py +++ b/prediction_market_agent_tooling/deploy/betting_strategy.py @@ -24,6 +24,10 @@ from prediction_market_agent_tooling.tools.utils import check_not_none +class GuaranteedLossError(RuntimeError): + pass + + class BettingStrategy(ABC): @abstractmethod def calculate_trades( @@ -63,7 +67,7 @@ def assert_buy_trade_wont_be_guaranteed_loss( ) if outcome_tokens_to_get.amount < trade.amount.amount: - raise RuntimeError( + raise GuaranteedLossError( f"Trade {trade=} would result in guaranteed loss by getting only {outcome_tokens_to_get=}." )