Merge pull request #3277 from hroff-1902/edge-fix-fee

Fix fee usage in Edge
This commit is contained in:
Matthias 2020-05-10 10:58:57 +02:00 committed by GitHub
commit f246336943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 19 deletions

View File

@ -238,20 +238,9 @@ class Edge:
:param result Dataframe :param result Dataframe
:return: result Dataframe :return: result Dataframe
""" """
# We set stake amount to an arbitrary amount, as it doesn't change the calculation.
# stake and fees # All returned values are relative, they are defined as ratios.
# stake = 0.015
# 0.05% is 0.0005
# fee = 0.001
# we set stake amount to an arbitrary amount.
# as it doesn't change the calculation.
# all returned values are relative.
# they are defined as ratios.
stake = 0.015 stake = 0.015
fee = self.fee
open_fee = fee / 2
close_fee = fee / 2
result['trade_duration'] = result['close_time'] - result['open_time'] result['trade_duration'] = result['close_time'] - result['open_time']
@ -262,12 +251,12 @@ class Edge:
# Buy Price # Buy Price
result['buy_vol'] = stake / result['open_rate'] # How many target are we buying result['buy_vol'] = stake / result['open_rate'] # How many target are we buying
result['buy_fee'] = stake * open_fee result['buy_fee'] = stake * self.fee
result['buy_spend'] = stake + result['buy_fee'] # How much we're spending result['buy_spend'] = stake + result['buy_fee'] # How much we're spending
# Sell price # Sell price
result['sell_sum'] = result['buy_vol'] * result['close_rate'] result['sell_sum'] = result['buy_vol'] * result['close_rate']
result['sell_fee'] = result['sell_sum'] * close_fee result['sell_fee'] = result['sell_sum'] * self.fee
result['sell_take'] = result['sell_sum'] - result['sell_fee'] result['sell_take'] = result['sell_sum'] - result['sell_fee']
# profit_ratio # profit_ratio

View File

@ -335,12 +335,16 @@ def test_edge_init_error(mocker, edge_conf,):
get_patched_freqtradebot(mocker, edge_conf) get_patched_freqtradebot(mocker, edge_conf)
def test_process_expectancy(mocker, edge_conf): @pytest.mark.parametrize("fee,risk_reward_ratio,expectancy", [
(0.0005, 306.5384615384, 101.5128205128),
(0.001, 152.6923076923, 50.2307692308),
])
def test_process_expectancy(mocker, edge_conf, fee, risk_reward_ratio, expectancy):
edge_conf['edge']['min_trade_number'] = 2 edge_conf['edge']['min_trade_number'] = 2
freqtrade = get_patched_freqtradebot(mocker, edge_conf) freqtrade = get_patched_freqtradebot(mocker, edge_conf)
def get_fee(*args, **kwargs): def get_fee(*args, **kwargs):
return 0.001 return fee
freqtrade.exchange.get_fee = get_fee freqtrade.exchange.get_fee = get_fee
edge = Edge(edge_conf, freqtrade.exchange, freqtrade.strategy) edge = Edge(edge_conf, freqtrade.exchange, freqtrade.strategy)
@ -394,9 +398,9 @@ def test_process_expectancy(mocker, edge_conf):
assert 'TEST/BTC' in final assert 'TEST/BTC' in final
assert final['TEST/BTC'].stoploss == -0.9 assert final['TEST/BTC'].stoploss == -0.9
assert round(final['TEST/BTC'].winrate, 10) == 0.3333333333 assert round(final['TEST/BTC'].winrate, 10) == 0.3333333333
assert round(final['TEST/BTC'].risk_reward_ratio, 10) == 306.5384615384 assert round(final['TEST/BTC'].risk_reward_ratio, 10) == risk_reward_ratio
assert round(final['TEST/BTC'].required_risk_reward, 10) == 2.0 assert round(final['TEST/BTC'].required_risk_reward, 10) == 2.0
assert round(final['TEST/BTC'].expectancy, 10) == 101.5128205128 assert round(final['TEST/BTC'].expectancy, 10) == expectancy
# Pop last item so no trade is profitable # Pop last item so no trade is profitable
trades.pop() trades.pop()