-
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.
Option to change deployed agent's bet strategy
- Loading branch information
Showing
8 changed files
with
134 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from math import ceil | ||
|
||
from prediction_market_agent_tooling.markets.agent_market import AgentMarket | ||
from prediction_market_agent_tooling.markets.data_models import Currency | ||
|
||
|
||
def minimum_bet_to_win( | ||
answer: bool, amount_to_win: float, market: AgentMarket | ||
) -> float: | ||
""" | ||
Estimates the minimum bet amount to win the given amount based on the current market price. | ||
""" | ||
share_price = market.p_yes if answer else market.p_no | ||
bet_amount = amount_to_win / (1 / share_price - 1) | ||
return bet_amount | ||
|
||
|
||
def minimum_bet_to_win_manifold( | ||
answer: bool, amount_to_win: float, market: AgentMarket | ||
) -> int: | ||
if market.currency != Currency.Mana: | ||
raise ValueError(f"Manifold bets are made in Mana. Got {market.currency}.") | ||
# Manifold lowest bet is 1 Mana, so we need to ceil the result. | ||
return ceil(minimum_bet_to_win(answer, amount_to_win, market)) |
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
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,70 @@ | ||
import pytest | ||
from web3 import Web3 | ||
|
||
from prediction_market_agent_tooling.gtypes import Probability | ||
from prediction_market_agent_tooling.markets.bets import ( | ||
minimum_bet_to_win, | ||
minimum_bet_to_win_manifold, | ||
) | ||
from prediction_market_agent_tooling.markets.manifold.manifold import ( | ||
ManifoldAgentMarket, | ||
) | ||
from prediction_market_agent_tooling.markets.omen.omen import OmenAgentMarket | ||
from prediction_market_agent_tooling.tools.web3_utils import WXDAI_CONTRACT_ADDRESS | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"outcome, market_p_yes, amount_to_win", | ||
[ | ||
(True, 0.68, 1), | ||
(False, 0.68, 1), | ||
(True, 0.7, 10), | ||
], | ||
) | ||
def test_minimum_bet_to_win( | ||
outcome: bool, market_p_yes: Probability, amount_to_win: float | ||
) -> None: | ||
min_bet = minimum_bet_to_win( | ||
outcome, | ||
amount_to_win, | ||
OmenAgentMarket( | ||
id="id", | ||
question="question", | ||
outcomes=["Yes", "No"], | ||
p_yes=market_p_yes, | ||
collateral_token_contract_address_checksummed=WXDAI_CONTRACT_ADDRESS, | ||
market_maker_contract_address_checksummed=Web3.to_checksum_address( | ||
"0xf3318C420e5e30C12786C4001D600e9EE1A7eBb1" | ||
), | ||
), | ||
) | ||
assert ( | ||
min_bet / (market_p_yes if outcome else 1 - market_p_yes) | ||
>= min_bet + amount_to_win | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"outcome, market_p_yes, amount_to_win, expected_min_bet", | ||
[ | ||
(True, 0.68, 1, 3), | ||
(False, 0.68, 1, 1), | ||
], | ||
) | ||
def test_minimum_bet_to_win_manifold( | ||
outcome: bool, | ||
market_p_yes: Probability, | ||
amount_to_win: float, | ||
expected_min_bet: int, | ||
) -> None: | ||
min_bet = minimum_bet_to_win_manifold( | ||
outcome, | ||
amount_to_win, | ||
ManifoldAgentMarket( | ||
id="id", | ||
question="question", | ||
outcomes=["Yes", "No"], | ||
p_yes=market_p_yes, | ||
), | ||
) | ||
assert min_bet == expected_min_bet, f"Expected {expected_min_bet}, got {min_bet}." |