Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass fees to Kelly #507

Merged
merged 8 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to opinions here 😄

A few lines above, outcome_token_pool = check_not_none(market.outcome_token_pool) is used, which means that get_kelly_bet_simplified was never going to be used.

Also get_kelly_bet_simplified doesn't accept fees which goes against this PR, but then if someones is going to create markets with huge fees, this other PR should solve that #488

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, no objections your honour!

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
Loading