Merge remote-tracking branch 'origin/develop' into feat/add-pytorch-model-support
This commit is contained in:
@@ -50,6 +50,7 @@ class HyperoptableStrategy(StrategyTestV3):
|
||||
return prot
|
||||
|
||||
bot_loop_started = False
|
||||
bot_started = False
|
||||
|
||||
def bot_loop_start(self):
|
||||
self.bot_loop_started = True
|
||||
@@ -58,6 +59,7 @@ class HyperoptableStrategy(StrategyTestV3):
|
||||
"""
|
||||
Parameters can also be defined here ...
|
||||
"""
|
||||
self.bot_started = True
|
||||
self.buy_rsi = IntParameter([0, 50], default=30, space='buy')
|
||||
|
||||
def informative_pairs(self):
|
||||
|
@@ -986,7 +986,8 @@ def test_auto_hyperopt_interface_loadparams(default_conf, mocker, caplog):
|
||||
}
|
||||
}
|
||||
}
|
||||
mocker.patch('freqtrade.strategy.hyper.json_load', return_value=expected_result)
|
||||
mocker.patch('freqtrade.strategy.hyper.HyperoptTools.load_params',
|
||||
return_value=expected_result)
|
||||
PairLocks.timeframe = default_conf['timeframe']
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
assert strategy.stoploss == -0.05
|
||||
@@ -1005,11 +1006,13 @@ def test_auto_hyperopt_interface_loadparams(default_conf, mocker, caplog):
|
||||
}
|
||||
}
|
||||
|
||||
mocker.patch('freqtrade.strategy.hyper.json_load', return_value=expected_result)
|
||||
mocker.patch('freqtrade.strategy.hyper.HyperoptTools.load_params',
|
||||
return_value=expected_result)
|
||||
with pytest.raises(OperationalException, match="Invalid parameter file provided."):
|
||||
StrategyResolver.load_strategy(default_conf)
|
||||
|
||||
mocker.patch('freqtrade.strategy.hyper.json_load', MagicMock(side_effect=ValueError()))
|
||||
mocker.patch('freqtrade.strategy.hyper.HyperoptTools.load_params',
|
||||
MagicMock(side_effect=ValueError()))
|
||||
|
||||
StrategyResolver.load_strategy(default_conf)
|
||||
assert log_has("Invalid parameter file format.", caplog)
|
||||
|
@@ -177,26 +177,30 @@ def test_stoploss_from_open(side, profitrange):
|
||||
("long", 0.1, 0.2, 1, 0.08333333),
|
||||
("long", 0.1, 0.5, 1, 0.266666666),
|
||||
("long", 0.1, 5, 1, 0.816666666), # 500% profit, set stoploss to 10% above open price
|
||||
("long", 0, 5, 10, 3.3333333), # 500% profit, set stoploss break even
|
||||
("long", 0.1, 5, 10, 3.26666666), # 500% profit, set stoploss to 10% above open price
|
||||
("long", -0.1, 5, 10, 3.3999999), # 500% profit, set stoploss to 10% belowopen price
|
||||
|
||||
("short", 0, 0.1, 1, 0.1111111),
|
||||
("short", -0.1, 0.1, 1, 0.2222222),
|
||||
("short", 0.1, 0.2, 1, 0.125),
|
||||
("short", 0.1, 1, 1, 1),
|
||||
("short", -0.01, 5, 10, 10.01999999), # 500% profit at 10x
|
||||
])
|
||||
def test_stoploss_from_open_leverage(side, rel_stop, curr_profit, leverage, expected):
|
||||
|
||||
stoploss = stoploss_from_open(rel_stop, curr_profit, side == 'short')
|
||||
stoploss = stoploss_from_open(rel_stop, curr_profit, side == 'short', leverage)
|
||||
assert pytest.approx(stoploss) == expected
|
||||
open_rate = 100
|
||||
if stoploss != 1:
|
||||
if side == 'long':
|
||||
current_rate = open_rate * (1 + curr_profit)
|
||||
stop = current_rate * (1 - stoploss)
|
||||
assert pytest.approx(stop) == open_rate * (1 + rel_stop)
|
||||
current_rate = open_rate * (1 + curr_profit / leverage)
|
||||
stop = current_rate * (1 - stoploss / leverage)
|
||||
assert pytest.approx(stop) == open_rate * (1 + rel_stop / leverage)
|
||||
else:
|
||||
current_rate = open_rate * (1 - curr_profit)
|
||||
stop = current_rate * (1 + stoploss)
|
||||
assert pytest.approx(stop) == open_rate * (1 - rel_stop)
|
||||
current_rate = open_rate * (1 - curr_profit / leverage)
|
||||
stop = current_rate * (1 + stoploss / leverage)
|
||||
assert pytest.approx(stop) == open_rate * (1 - rel_stop / leverage)
|
||||
|
||||
|
||||
def test_stoploss_from_absolute():
|
||||
|
@@ -69,7 +69,7 @@ def test_load_strategy(default_conf, dataframe_1m):
|
||||
def test_load_strategy_base64(dataframe_1m, caplog, default_conf):
|
||||
filepath = Path(__file__).parents[2] / 'freqtrade/templates/sample_strategy.py'
|
||||
encoded_string = urlsafe_b64encode(filepath.read_bytes()).decode("utf-8")
|
||||
default_conf.update({'strategy': 'SampleStrategy:{}'.format(encoded_string)})
|
||||
default_conf.update({'strategy': f'SampleStrategy:{encoded_string}'})
|
||||
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
assert 'rsi' in strategy.advise_indicators(dataframe_1m, {'pair': 'ETH/BTC'})
|
||||
|
Reference in New Issue
Block a user