-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fix/kelly #147
Fix/kelly #147
Conversation
@@ -72,6 +72,56 @@ def remove_fraction_wei(amount: int, fraction: float) -> int: | |||
raise ValueError(f"The given fraction {fraction!r} is not in the range [0, 1].") | |||
|
|||
|
|||
def perturb_y_if_x_equals_y(x: int, y: int) -> float: | |||
"""Introduce perturbation to the y value if x equals y.""" | |||
epsilon = (x + y) / 10000 |
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.
Still looking at best strategy...
@@ -216,45 +266,6 @@ def check_balance(self) -> WaitableConditionType: | |||
self.context.logger.info(f"The safe has {native} xDAI and {collateral}.") | |||
return True | |||
|
|||
def _calculate_kelly_bet_amount( |
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.
Antipattern to have this as an instance method. It's much harder to test this way
packages/valory/skills/decision_maker_abci/tests/test_behaviours.py
Outdated
Show resolved
Hide resolved
return 0 | ||
if x == y: | ||
# o/w kelly traders will never be the first to bet in a new market | ||
y = perturb_y_if_x_equals_y(x, y) |
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.
If x==y both denominator AND numerator are zero! So the previous implementation avoided division by zero but didn't solve the issue of 0 bet amount.
@@ -293,17 +294,18 @@ def get_bet_amount( | |||
) -> Generator[None, None, int]: | |||
"""Get the bet amount given a specified trading strategy.""" | |||
|
|||
if strategy == "bet_amount_per_conf_threshold": | |||
# Kelly Criterion does not trade for equally weighted pools. | |||
if ( |
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.
Rather than using some hack, let's just revert to this strategy when Kelly Criterion would suggest not to trade.
self.context.logger.info( | ||
"Used trading strategy: Bet amount per confidence threshold" | ||
) | ||
threshold = round(confidence, 1) | ||
bet_amount = self.params.bet_amount_per_threshold[threshold] | ||
return bet_amount | ||
|
||
if strategy != "kelly_criterion": |
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.
Should be checked once at construction, not here.
@@ -323,7 +325,10 @@ def get_bet_amount( | |||
|
|||
fee_fraction = 1 - self.wei_to_native(bet_fee) | |||
self.context.logger.info(f"Fee fraction: {fee_fraction}") | |||
kelly_bet_amount = self._calculate_kelly_bet_amount( | |||
if bankroll_adj == 0: | |||
error = "Cannot calculate Kelly bet amount with no bankroll." |
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.
extracted
fix: properly handle batch size reduction
fix: add missing local var
No description provided.