-
Notifications
You must be signed in to change notification settings - Fork 2
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
Refactor DeployableTraderAgent to 1. predict a probability for a market then 2. place a bet based on its BettingStrategy
#352
Merged
gabrielfior
merged 37 commits into
main
from
338-change-default-betting-strategy-from-amount-==-tiny_bet-direction-==-yes-if-p_yes-05-to-use-kelly-bet
Aug 27, 2024
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
7f6c0a7
Refactored tiny_bet_amount to strategy
gabrielfior 626c42d
Updating deps
gabrielfior ed21ffd
Refactoring betting strategies
gabrielfior faf35e2
Added default strategies
gabrielfior a4fc8c9
Refactoring betting strategies
gabrielfior d51301e
Merge remote-tracking branch 'refs/remotes/origin/main' into 338-chan…
gabrielfior bcbe375
Added lock
gabrielfior 7bbb0c5
Bump version
gabrielfior 74da0d1
Delete run_all.sh
gabrielfior 01ba8f2
Fixing tests
gabrielfior d6f4b14
Updated GNOSIS_RPC
gabrielfior 1ae480a
Added exception message pattern to be retried
gabrielfior 4515bdd
Refactored exception message
gabrielfior f073fb8
Added ape as dependency again
gabrielfior 14c9250
Implementing PR comments (1)
gabrielfior 0c8bf96
Update prediction_market_agent_tooling/deploy/agent.py
gabrielfior 9e85c79
Update prediction_market_agent_tooling/deploy/betting_strategy.py
gabrielfior 4432d3b
Update prediction_market_agent_tooling/deploy/betting_strategy.py
gabrielfior 683b95f
Refactored get_tiny_bet_amount
gabrielfior c013ee2
Refactored Answer into ProbabilisticAnswer, since direction removed
gabrielfior 080ec6e
Updated lock
gabrielfior cc25098
Merge remote-tracking branch 'refs/remotes/origin/main' into 338-chan…
gabrielfior 99d1eee
Small changes after merge
gabrielfior 0fcd66d
Added calculator for directions in betting strategies
gabrielfior fc97df9
Removed Answer
gabrielfior 8dce9ce
Added comment to calculator classes | renaming for clarity
gabrielfior 82bd7b9
Removed unnecessary share calculations, replacing that with clever math
gabrielfior 913be0c
Merge remote-tracking branch 'refs/remotes/origin/main' into 338-chan…
gabrielfior a033c5e
Updated lock file
gabrielfior 932cfa2
Update prediction_market_agent_tooling/deploy/betting_strategy.py
gabrielfior 6e66394
Update prediction_market_agent_tooling/deploy/betting_strategy.py
gabrielfior 742db1d
Implemented PR changes
gabrielfior c2cf786
Merge remote-tracking branch 'origin/338-change-default-betting-strat…
gabrielfior 0b886fb
Update prediction_market_agent_tooling/deploy/betting_strategy.py
gabrielfior 45f9545
Fixing CI
gabrielfior 0e9386a
Added configurable bet_amount
gabrielfior 9eb4140
Implemented PR changes
gabrielfior File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this change from a
YES
enum to a boolean required?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was discussed in another thread (can't remember which one from the 80 comments) - if you have specific concerns, happy to open a new PR to discuss having "YES" or True.