Skip to content

Commit

Permalink
Fix betting benchmark (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Oct 24, 2024
1 parent a5bba8c commit 657d27a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
20 changes: 12 additions & 8 deletions examples/monitor/match_bets_with_langfuse_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion prediction_market_agent_tooling/deploy/betting_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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=}."
)

Expand Down

0 comments on commit 657d27a

Please sign in to comment.