prediction-market-agent-tooling 0.44.0__py3-none-any.whl → 0.45.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py +61 -104
- {prediction_market_agent_tooling-0.44.0.dist-info → prediction_market_agent_tooling-0.45.0.dist-info}/METADATA +1 -1
- {prediction_market_agent_tooling-0.44.0.dist-info → prediction_market_agent_tooling-0.45.0.dist-info}/RECORD +6 -6
- {prediction_market_agent_tooling-0.44.0.dist-info → prediction_market_agent_tooling-0.45.0.dist-info}/LICENSE +0 -0
- {prediction_market_agent_tooling-0.44.0.dist-info → prediction_market_agent_tooling-0.45.0.dist-info}/WHEEL +0 -0
- {prediction_market_agent_tooling-0.44.0.dist-info → prediction_market_agent_tooling-0.45.0.dist-info}/entry_points.txt +0 -0
@@ -1,110 +1,67 @@
|
|
1
|
-
|
1
|
+
from enum import Enum
|
2
2
|
|
3
|
-
from
|
4
|
-
from prediction_market_agent_tooling.markets.omen.data_models import OmenMarket
|
5
|
-
from prediction_market_agent_tooling.tools.utils import check_not_none
|
6
|
-
from prediction_market_agent_tooling.tools.web3_utils import (
|
7
|
-
ONE_XDAI,
|
8
|
-
wei_to_xdai,
|
9
|
-
xdai_to_wei,
|
10
|
-
)
|
3
|
+
from pydantic import BaseModel
|
11
4
|
|
12
|
-
OutcomeIndex = t.Literal[0, 1]
|
13
5
|
|
6
|
+
class BetDirection(str, Enum):
|
7
|
+
YES = "Yes"
|
8
|
+
NO = "No"
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
10
|
+
|
11
|
+
class KellyBet(BaseModel):
|
12
|
+
direction: BetDirection
|
13
|
+
size: float
|
14
|
+
|
15
|
+
|
16
|
+
def check_is_valid_probability(probability: float) -> None:
|
17
|
+
if not 0 <= probability <= 1:
|
18
|
+
raise ValueError("Probability must be between 0 and 1")
|
19
|
+
|
20
|
+
|
21
|
+
def get_kelly_bet(
|
22
|
+
max_bet: float,
|
23
|
+
market_p_yes: float,
|
24
|
+
estimated_p_yes: float,
|
25
|
+
confidence: float,
|
26
|
+
) -> KellyBet:
|
18
27
|
"""
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
```
|
36
|
-
|
37
|
-
x: Number of tokens in the selected outcome pool
|
38
|
-
y: Number of tokens in the other outcome pool
|
39
|
-
p: Probability of winning
|
40
|
-
c: Confidence
|
41
|
-
b: Bankroll
|
42
|
-
f: Fee fraction
|
28
|
+
Calculate the optimal bet amount using the Kelly Criterion for a binary outcome market.
|
29
|
+
|
30
|
+
From https://en.wikipedia.org/wiki/Kelly_criterion:
|
31
|
+
|
32
|
+
f* = p - q / b
|
33
|
+
|
34
|
+
where:
|
35
|
+
- f* is the fraction of the current bankroll to wager
|
36
|
+
- p is the probability of a win
|
37
|
+
- q = 1-p is the probability of a loss
|
38
|
+
- b is the proportion of the bet gained with a win
|
39
|
+
|
40
|
+
Note: this calculation does not factor in that the bet changes the market
|
41
|
+
odds. This means the calculation is only accurate if the bet size is small
|
42
|
+
compared to the market volume. See discussion here for more detail:
|
43
|
+
https://github.com/gnosis/prediction-market-agent-tooling/pull/330#discussion_r1698269328
|
43
44
|
"""
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
-4 * b * x * y**2 * p * c
|
68
|
-
- 4 * b * x**2 * y * p * c
|
69
|
-
+ 4 * b * x * y**2
|
70
|
-
)
|
71
|
-
)
|
72
|
-
)
|
73
|
-
** (1 / 2)
|
74
|
-
)
|
75
|
-
denominator = 2 * (x**2 * f - y**2 * f)
|
76
|
-
if denominator == 0:
|
77
|
-
return 0
|
78
|
-
kelly_bet_amount = numerator / denominator
|
79
|
-
return int(kelly_bet_amount)
|
80
|
-
|
81
|
-
|
82
|
-
def get_kelly_criterion_bet(
|
83
|
-
market: OmenMarket,
|
84
|
-
estimated_p_yes: Probability,
|
85
|
-
max_bet: xDai,
|
86
|
-
) -> t.Tuple[xDai, OutcomeIndex]:
|
87
|
-
if len(market.outcomeTokenAmounts) != 2:
|
88
|
-
raise ValueError("Only binary markets are supported.")
|
89
|
-
|
90
|
-
current_p_yes = check_not_none(
|
91
|
-
market.outcomeTokenProbabilities, "No probabilities, is marked closed?"
|
92
|
-
)[0]
|
93
|
-
outcome_index: OutcomeIndex = 0 if estimated_p_yes > current_p_yes else 1
|
94
|
-
estimated_p_win = estimated_p_yes if outcome_index == 0 else 1 - estimated_p_yes
|
95
|
-
|
96
|
-
kelly_bet_wei = wei_type(
|
97
|
-
_get_kelly_criterion_bet(
|
98
|
-
x=market.outcomeTokenAmounts[outcome_index],
|
99
|
-
y=market.outcomeTokenAmounts[1 - outcome_index],
|
100
|
-
p=estimated_p_win,
|
101
|
-
c=1, # confidence
|
102
|
-
b=xdai_to_wei(max_bet), # bankroll, or max bet, in Wei
|
103
|
-
f=(
|
104
|
-
xdai_to_wei(ONE_XDAI)
|
105
|
-
- check_not_none(market.fee, "No fee for the market.")
|
106
|
-
)
|
107
|
-
/ xdai_to_wei(ONE_XDAI), # fee fraction
|
108
|
-
)
|
109
|
-
)
|
110
|
-
return wei_to_xdai(kelly_bet_wei), outcome_index
|
45
|
+
check_is_valid_probability(market_p_yes)
|
46
|
+
check_is_valid_probability(estimated_p_yes)
|
47
|
+
check_is_valid_probability(confidence)
|
48
|
+
|
49
|
+
if estimated_p_yes > market_p_yes:
|
50
|
+
bet_direction = BetDirection.YES
|
51
|
+
market_prob = market_p_yes
|
52
|
+
else:
|
53
|
+
bet_direction = BetDirection.NO
|
54
|
+
market_prob = 1 - market_p_yes
|
55
|
+
|
56
|
+
# Handle the case where market_prob is 0
|
57
|
+
if market_prob == 0:
|
58
|
+
market_prob = 1e-10
|
59
|
+
|
60
|
+
edge = abs(estimated_p_yes - market_p_yes) * confidence
|
61
|
+
odds = (1 / market_prob) - 1
|
62
|
+
kelly_fraction = edge / odds
|
63
|
+
|
64
|
+
# Ensure bet size is non-negative does not exceed the wallet balance
|
65
|
+
bet_size = min(kelly_fraction * max_bet, max_bet)
|
66
|
+
|
67
|
+
return KellyBet(direction=bet_direction, size=bet_size)
|
@@ -56,7 +56,7 @@ prediction_market_agent_tooling/monitor/monitor_app.py,sha256=THyZ67baByakoOm3hI
|
|
56
56
|
prediction_market_agent_tooling/monitor/monitor_settings.py,sha256=Xiozs3AsufuJ04JOe1vjUri-IAMWHjjmc2ugGGiHNH4,947
|
57
57
|
prediction_market_agent_tooling/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
58
58
|
prediction_market_agent_tooling/tools/balances.py,sha256=nR8_dSfbm3yTOOmMAwhGlurftEiNo1w1WIVzbskjdmM,837
|
59
|
-
prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py,sha256=
|
59
|
+
prediction_market_agent_tooling/tools/betting_strategies/kelly_criterion.py,sha256=d3QEg1Bia8D7SPHGr-SgP0OHSLIzm_hf4sN4iz06qiM,1951
|
60
60
|
prediction_market_agent_tooling/tools/betting_strategies/market_moving.py,sha256=wtrHVQRuA0uDx06z0OxQLYbswuOpHQ1UyCWwLCrD_oM,4400
|
61
61
|
prediction_market_agent_tooling/tools/betting_strategies/minimum_bet_to_win.py,sha256=-FUSuQQgjcWSSnoFxnlAyTeilY6raJABJVM2QKkFqAY,438
|
62
62
|
prediction_market_agent_tooling/tools/betting_strategies/stretch_bet_between.py,sha256=THMXwFlskvzbjnX_OiYtDSzI8XVFyULWfP2525_9UGc,429
|
@@ -75,8 +75,8 @@ prediction_market_agent_tooling/tools/singleton.py,sha256=CiIELUiI-OeS7U7eeHEt0r
|
|
75
75
|
prediction_market_agent_tooling/tools/streamlit_user_login.py,sha256=NXEqfjT9Lc9QtliwSGRASIz1opjQ7Btme43H4qJbzgE,3010
|
76
76
|
prediction_market_agent_tooling/tools/utils.py,sha256=JE9YWtPPhnTgLiOyGAZDNG5K8nCwUY9IZEuAlm9UcxA,6611
|
77
77
|
prediction_market_agent_tooling/tools/web3_utils.py,sha256=nKRHmdLnWSKd3wpo-cysXGvhhrJ2Yf69sN2FFQfSt6s,10578
|
78
|
-
prediction_market_agent_tooling-0.
|
79
|
-
prediction_market_agent_tooling-0.
|
80
|
-
prediction_market_agent_tooling-0.
|
81
|
-
prediction_market_agent_tooling-0.
|
82
|
-
prediction_market_agent_tooling-0.
|
78
|
+
prediction_market_agent_tooling-0.45.0.dist-info/LICENSE,sha256=6or154nLLU6bELzjh0mCreFjt0m2v72zLi3yHE0QbeE,7650
|
79
|
+
prediction_market_agent_tooling-0.45.0.dist-info/METADATA,sha256=3KvBa071FaBwX1gQtAtG5rg9LMVEhIfSkZC5VrzYRcc,7634
|
80
|
+
prediction_market_agent_tooling-0.45.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
81
|
+
prediction_market_agent_tooling-0.45.0.dist-info/entry_points.txt,sha256=m8PukHbeH5g0IAAmOf_1Ahm-sGAMdhSSRQmwtpmi2s8,81
|
82
|
+
prediction_market_agent_tooling-0.45.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|