Fix kelly_criterion formula for investment scenario
gyusu opened this issue · 1 comments
gyusu commented
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.
quantstats/quantstats/stats.py
Lines 870 to 882 in fa0a91a
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
grzesir commented
Check out https://github.com/Lumiwealth/quantstats_lumi, which is being updated regularly. We are a fork of this library that is being maintained by Lumiwealth