added tests for position sizing
This commit is contained in:
parent
abd88767f8
commit
12471e012e
@ -164,7 +164,7 @@ class Edge():
|
|||||||
if pair not in self._cached_pairs:
|
if pair not in self._cached_pairs:
|
||||||
logger.warning("cannot find %s in calculated pairs, "
|
logger.warning("cannot find %s in calculated pairs, "
|
||||||
"stake_amount of strategy is used instead.", pair)
|
"stake_amount of strategy is used instead.", pair)
|
||||||
return self.strategy.stake_amount
|
return self.config['stake_amount']
|
||||||
|
|
||||||
stoploss = self._cached_pairs[pair].stoploss
|
stoploss = self._cached_pairs[pair].stoploss
|
||||||
available_capital = total_capital * self._capital_percentage
|
available_capital = total_capital * self._capital_percentage
|
||||||
|
@ -5,6 +5,7 @@ import pytest
|
|||||||
import logging
|
import logging
|
||||||
from freqtrade.tests.conftest import get_patched_freqtradebot
|
from freqtrade.tests.conftest import get_patched_freqtradebot
|
||||||
from freqtrade.edge import Edge, PairInfo
|
from freqtrade.edge import Edge, PairInfo
|
||||||
|
from freqtrade import constants
|
||||||
from pandas import DataFrame, to_datetime
|
from pandas import DataFrame, to_datetime
|
||||||
from freqtrade.strategy.interface import SellType
|
from freqtrade.strategy.interface import SellType
|
||||||
from freqtrade.tests.optimize import (BTrade, BTContainer, _build_backtest_dataframe,
|
from freqtrade.tests.optimize import (BTrade, BTContainer, _build_backtest_dataframe,
|
||||||
@ -152,9 +153,9 @@ def test_stoploss(mocker, edge_conf):
|
|||||||
assert edge.stoploss('E/F') == -0.01
|
assert edge.stoploss('E/F') == -0.01
|
||||||
|
|
||||||
|
|
||||||
def test_nonexisting_stoploss(mocker, default_conf):
|
def test_nonexisting_stoploss(mocker, edge_conf):
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
freqtrade = get_patched_freqtradebot(mocker, edge_conf)
|
||||||
edge = Edge(default_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(
|
||||||
return_value={
|
return_value={
|
||||||
'E/F': PairInfo(-0.01, 0.66, 3.71, 0.50, 1.71, 10, 60),
|
'E/F': PairInfo(-0.01, 0.66, 3.71, 0.50, 1.71, 10, 60),
|
||||||
@ -164,6 +165,39 @@ def test_nonexisting_stoploss(mocker, default_conf):
|
|||||||
assert edge.stoploss('N/O') == -0.1
|
assert edge.stoploss('N/O') == -0.1
|
||||||
|
|
||||||
|
|
||||||
|
def test_stake_amount(mocker, edge_conf):
|
||||||
|
freqtrade = get_patched_freqtradebot(mocker, edge_conf)
|
||||||
|
edge = Edge(edge_conf, freqtrade.exchange, freqtrade.strategy)
|
||||||
|
mocker.patch('freqtrade.edge.Edge._cached_pairs', mocker.PropertyMock(
|
||||||
|
return_value={
|
||||||
|
'E/F': PairInfo(-0.02, 0.66, 3.71, 0.50, 1.71, 10, 60),
|
||||||
|
}
|
||||||
|
))
|
||||||
|
free = 100
|
||||||
|
total = 100
|
||||||
|
assert edge.stake_amount('E/F', free, total) == 25
|
||||||
|
|
||||||
|
free = 20
|
||||||
|
total = 100
|
||||||
|
assert edge.stake_amount('E/F', free, total) == 20
|
||||||
|
|
||||||
|
free = 0
|
||||||
|
total = 100
|
||||||
|
assert edge.stake_amount('E/F', free, total) == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_nonexisting_stake_amount(mocker, edge_conf):
|
||||||
|
freqtrade = get_patched_freqtradebot(mocker, edge_conf)
|
||||||
|
edge = Edge(edge_conf, freqtrade.exchange, freqtrade.strategy)
|
||||||
|
mocker.patch('freqtrade.edge.Edge._cached_pairs', mocker.PropertyMock(
|
||||||
|
return_value={
|
||||||
|
'E/F': PairInfo(-0.01, 0.66, 3.71, 0.50, 1.71, 10, 60),
|
||||||
|
}
|
||||||
|
))
|
||||||
|
|
||||||
|
assert edge.stake_amount('N/O', 1, 2) == constants.UNLIMITED_STAKE_AMOUNT
|
||||||
|
|
||||||
|
|
||||||
def _validate_ohlc(buy_ohlc_sell_matrice):
|
def _validate_ohlc(buy_ohlc_sell_matrice):
|
||||||
for index, ohlc in enumerate(buy_ohlc_sell_matrice):
|
for index, ohlc in enumerate(buy_ohlc_sell_matrice):
|
||||||
# if not high < open < low or not high < close < low
|
# if not high < open < low or not high < close < low
|
||||||
|
Loading…
Reference in New Issue
Block a user