Skip to content

Commit

Permalink
Pass fees to Kelly (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Oct 17, 2024
1 parent 5ed2712 commit cc21ebf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 43 deletions.
63 changes: 23 additions & 40 deletions prediction_market_agent_tooling/deploy/betting_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions tests_integration/markets/omen/test_kelly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit cc21ebf

Please sign in to comment.