-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
338 change default betting strategy from amount == tiny bet direction…
… == yes if p yes 05 to use kelly bet (#352) * Refactored tiny_bet_amount to strategy * Updating deps * Refactoring betting strategies * Added default strategies * Refactoring betting strategies * Added lock * Bump version * Delete run_all.sh * Fixing tests * Updated GNOSIS_RPC * Added exception message pattern to be retried * Refactored exception message * Added ape as dependency again * Implementing PR comments (1) * Update prediction_market_agent_tooling/deploy/agent.py Co-authored-by: Peter Jung <peter@jung.ninja> * Update prediction_market_agent_tooling/deploy/betting_strategy.py Co-authored-by: Peter Jung <peter@jung.ninja> * Update prediction_market_agent_tooling/deploy/betting_strategy.py Co-authored-by: Peter Jung <peter@jung.ninja> * Refactored get_tiny_bet_amount * Refactored Answer into ProbabilisticAnswer, since direction removed * Updated lock * Small changes after merge * Added calculator for directions in betting strategies * Removed Answer * Added comment to calculator classes | renaming for clarity * Removed unnecessary share calculations, replacing that with clever math * Updated lock file * Update prediction_market_agent_tooling/deploy/betting_strategy.py Co-authored-by: Evan Griffiths <56087052+evangriffiths@users.noreply.github.com> * Update prediction_market_agent_tooling/deploy/betting_strategy.py Co-authored-by: Evan Griffiths <56087052+evangriffiths@users.noreply.github.com> * Implemented PR changes * Update prediction_market_agent_tooling/deploy/betting_strategy.py Co-authored-by: Evan Griffiths <56087052+evangriffiths@users.noreply.github.com> * Fixing CI * Added configurable bet_amount * Implemented PR changes --------- Co-authored-by: Peter Jung <peter@jung.ninja> Co-authored-by: Evan Griffiths <56087052+evangriffiths@users.noreply.github.com>
- Loading branch information
1 parent
34fd87f
commit 5a57423
Showing
12 changed files
with
438 additions
and
358 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
prediction_market_agent_tooling/deploy/betting_strategy.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from prediction_market_agent_tooling.markets.agent_market import AgentMarket | ||
from prediction_market_agent_tooling.markets.data_models import ( | ||
ProbabilisticAnswer, | ||
TokenAmountAndDirection, | ||
) | ||
from prediction_market_agent_tooling.tools.betting_strategies.kelly_criterion import ( | ||
get_kelly_bet, | ||
) | ||
|
||
|
||
class BettingStrategy(ABC): | ||
@abstractmethod | ||
def calculate_bet_amount_and_direction( | ||
self, answer: ProbabilisticAnswer, market: AgentMarket | ||
) -> TokenAmountAndDirection: | ||
pass | ||
|
||
|
||
class MaxAccuracyBettingStrategy(BettingStrategy): | ||
def __init__(self, bet_amount: float | None = None): | ||
self.bet_amount = bet_amount | ||
|
||
@staticmethod | ||
def calculate_direction(market_p_yes: float, estimate_p_yes: float) -> bool: | ||
# If estimate_p_yes >= market.current_p_yes, then bet TRUE, else bet FALSE. | ||
# This is equivalent to saying EXPECTED_VALUE = (estimate_p_yes * num_tokens_obtained_by_betting_yes) - | ||
# ((1 - estimate_p_yes) * num_tokens_obtained_by_betting_no) >= 0 | ||
return estimate_p_yes >= market_p_yes | ||
|
||
def calculate_bet_amount_and_direction( | ||
self, answer: ProbabilisticAnswer, market: AgentMarket | ||
) -> TokenAmountAndDirection: | ||
bet_amount = ( | ||
market.get_tiny_bet_amount().amount | ||
if self.bet_amount is None | ||
else self.bet_amount | ||
) | ||
direction = self.calculate_direction(market.current_p_yes, answer.p_yes) | ||
return TokenAmountAndDirection( | ||
amount=bet_amount, | ||
currency=market.currency, | ||
direction=direction, | ||
) | ||
|
||
|
||
class KellyBettingStrategy(BettingStrategy): | ||
def __init__(self, max_bet_amount: float = 10): | ||
self.max_bet_amount = max_bet_amount | ||
|
||
def calculate_bet_amount_and_direction( | ||
self, answer: ProbabilisticAnswer, market: AgentMarket | ||
) -> TokenAmountAndDirection: | ||
kelly_bet = get_kelly_bet( | ||
self.max_bet_amount, market.current_p_yes, answer.p_yes, answer.confidence | ||
) | ||
return TokenAmountAndDirection( | ||
amount=kelly_bet.size, | ||
currency=market.currency, | ||
direction=kelly_bet.direction, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.