Skip to content
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_criterion formula for investment scenario #340

Open
gyusu opened this issue Mar 28, 2024 · 0 comments
Open

Fix kelly_criterion formula for investment scenario #340

gyusu opened this issue Mar 28, 2024 · 0 comments

Comments

@gyusu
Copy link

gyusu commented Mar 28, 2024

According to https://en.wikipedia.org/wiki/Kelly_criterion,
current code is for a gambling scenario where you lose all your money when you lose.

def kelly_criterion(returns, prepare_returns=True):
"""
Calculates the recommended maximum amount of capital that
should be allocated to the given strategy, based on the
Kelly Criterion (http://en.wikipedia.org/wiki/Kelly_criterion)
"""
if prepare_returns:
returns = _utils._prepare_returns(returns)
win_loss_ratio = payoff_ratio(returns)
win_prob = win_rate(returns)
lose_prob = 1 - win_prob
return ((win_loss_ratio * win_prob) - lose_prob) / win_loss_ratio

Need to change like below to calcuate it for investment scenario which allows partial losses.

def kelly_criterion(returns, prepare_returns=True):
    """
    Calculates the recommended maximum amount of capital that
    should be allocated to the given strategy, based on the
    Kelly Criterion (http://en.wikipedia.org/wiki/Kelly_criterion)
    """
    if prepare_returns:
        returns = _utils._prepare_returns(returns)

    win_avg = avg_win(returns)
    lose_avg = -avg_lose(returns)

    win_prob = win_rate(returns)
    lose_prob = 1 - win_prob

    return win_prob / lose_avg - lose_prob / win_avg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant