parent
3110d2dbb1
commit
aa79574c0c
@ -159,7 +159,8 @@ class Edge:
|
|||||||
available_capital = (total_capital + capital_in_trade) * self._capital_ratio
|
available_capital = (total_capital + capital_in_trade) * self._capital_ratio
|
||||||
allowed_capital_at_risk = available_capital * self._allowed_risk
|
allowed_capital_at_risk = available_capital * self._allowed_risk
|
||||||
max_position_size = abs(allowed_capital_at_risk / stoploss)
|
max_position_size = abs(allowed_capital_at_risk / stoploss)
|
||||||
position_size = min(max_position_size, free_capital)
|
# Position size must be below available capital.
|
||||||
|
position_size = min(min(max_position_size, free_capital), available_capital)
|
||||||
if pair in self._cached_pairs:
|
if pair in self._cached_pairs:
|
||||||
logger.info(
|
logger.info(
|
||||||
'winrate: %s, expectancy: %s, position size: %s, pair: %s,'
|
'winrate: %s, expectancy: %s, position size: %s, pair: %s,'
|
||||||
|
@ -209,7 +209,7 @@ def test_nonexisting_stoploss(mocker, edge_conf):
|
|||||||
assert edge.stoploss('N/O') == -0.1
|
assert edge.stoploss('N/O') == -0.1
|
||||||
|
|
||||||
|
|
||||||
def test_stake_amount(mocker, edge_conf):
|
def test_edge_stake_amount(mocker, edge_conf):
|
||||||
freqtrade = get_patched_freqtradebot(mocker, edge_conf)
|
freqtrade = get_patched_freqtradebot(mocker, edge_conf)
|
||||||
edge = Edge(edge_conf, freqtrade.exchange, freqtrade.strategy)
|
edge = Edge(edge_conf, freqtrade.exchange, freqtrade.strategy)
|
||||||
mocker.patch('freqtrade.edge.Edge._cached_pairs', mocker.PropertyMock(
|
mocker.patch('freqtrade.edge.Edge._cached_pairs', mocker.PropertyMock(
|
||||||
@ -217,20 +217,33 @@ def test_stake_amount(mocker, edge_conf):
|
|||||||
'E/F': PairInfo(-0.02, 0.66, 3.71, 0.50, 1.71, 10, 60),
|
'E/F': PairInfo(-0.02, 0.66, 3.71, 0.50, 1.71, 10, 60),
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
free = 100
|
assert edge._capital_ratio == 0.5
|
||||||
total = 100
|
assert edge.stake_amount('E/F', free_capital=100, total_capital=100,
|
||||||
in_trade = 25
|
capital_in_trade=25) == 31.25
|
||||||
assert edge.stake_amount('E/F', free, total, in_trade) == 31.25
|
|
||||||
|
|
||||||
free = 20
|
assert edge.stake_amount('E/F', free_capital=20, total_capital=100,
|
||||||
total = 100
|
capital_in_trade=25) == 20
|
||||||
in_trade = 25
|
|
||||||
assert edge.stake_amount('E/F', free, total, in_trade) == 20
|
|
||||||
|
|
||||||
free = 0
|
assert edge.stake_amount('E/F', free_capital=0, total_capital=100,
|
||||||
total = 100
|
capital_in_trade=25) == 0
|
||||||
in_trade = 25
|
|
||||||
assert edge.stake_amount('E/F', free, total, in_trade) == 0
|
# Test with increased allowed_risk
|
||||||
|
# Result should be no more than allowed capital
|
||||||
|
edge._allowed_risk = 0.4
|
||||||
|
edge._capital_ratio = 0.5
|
||||||
|
assert edge.stake_amount('E/F', free_capital=100, total_capital=100,
|
||||||
|
capital_in_trade=25) == 62.5
|
||||||
|
|
||||||
|
assert edge.stake_amount('E/F', free_capital=100, total_capital=100,
|
||||||
|
capital_in_trade=0) == 50
|
||||||
|
|
||||||
|
edge._capital_ratio = 1
|
||||||
|
# Full capital is available
|
||||||
|
assert edge.stake_amount('E/F', free_capital=100, total_capital=100,
|
||||||
|
capital_in_trade=0) == 100
|
||||||
|
# Full capital is available
|
||||||
|
assert edge.stake_amount('E/F', free_capital=0, total_capital=100,
|
||||||
|
capital_in_trade=0) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_nonexisting_stake_amount(mocker, edge_conf):
|
def test_nonexisting_stake_amount(mocker, edge_conf):
|
||||||
|
Loading…
Reference in New Issue
Block a user