2020-10-28 13:36:19 +00:00
|
|
|
from copy import deepcopy
|
|
|
|
from datetime import datetime
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import pandas as pd
|
|
|
|
import pytest
|
|
|
|
|
2022-03-25 07:36:03 +00:00
|
|
|
from freqtrade.enums import ExitType, RunMode
|
2020-10-28 13:36:19 +00:00
|
|
|
from freqtrade.optimize.hyperopt import Hyperopt
|
|
|
|
from tests.conftest import patch_exchange
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
|
|
def hyperopt_conf(default_conf):
|
|
|
|
hyperconf = deepcopy(default_conf)
|
|
|
|
hyperconf.update({
|
2021-03-29 17:27:19 +00:00
|
|
|
'datadir': Path(default_conf['datadir']),
|
2021-04-24 05:18:35 +00:00
|
|
|
'runmode': RunMode.HYPEROPT,
|
2021-09-11 15:11:02 +00:00
|
|
|
'strategy': 'HyperoptableStrategy',
|
2020-10-28 13:36:19 +00:00
|
|
|
'hyperopt_loss': 'ShortTradeDurHyperOptLoss',
|
|
|
|
'hyperopt_path': str(Path(__file__).parent / 'hyperopts'),
|
|
|
|
'epochs': 1,
|
|
|
|
'timerange': None,
|
|
|
|
'spaces': ['default'],
|
|
|
|
'hyperopt_jobs': 1,
|
2021-03-29 17:27:19 +00:00
|
|
|
'hyperopt_min_trades': 1,
|
2020-10-28 13:36:19 +00:00
|
|
|
})
|
|
|
|
return hyperconf
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
|
|
def hyperopt(hyperopt_conf, mocker):
|
|
|
|
|
|
|
|
patch_exchange(mocker)
|
|
|
|
return Hyperopt(hyperopt_conf)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
|
|
def hyperopt_results():
|
|
|
|
return pd.DataFrame(
|
|
|
|
{
|
2021-10-02 13:23:48 +00:00
|
|
|
'pair': ['ETH/USDT', 'ETH/USDT', 'ETH/USDT', 'ETH/USDT'],
|
2021-10-02 12:30:24 +00:00
|
|
|
'profit_ratio': [-0.1, 0.2, -0.1, 0.3],
|
|
|
|
'profit_abs': [-0.2, 0.4, -0.2, 0.6],
|
|
|
|
'trade_duration': [10, 30, 10, 10],
|
2021-10-02 13:23:48 +00:00
|
|
|
'amount': [0.1, 0.1, 0.1, 0.1],
|
2022-03-25 05:55:37 +00:00
|
|
|
'sell_reason': [ExitType.STOP_LOSS, ExitType.ROI, ExitType.STOP_LOSS, ExitType.ROI],
|
2021-10-02 13:23:48 +00:00
|
|
|
'open_date':
|
|
|
|
[
|
|
|
|
datetime(2019, 1, 1, 9, 15, 0),
|
2021-10-02 13:36:51 +00:00
|
|
|
datetime(2019, 1, 2, 8, 55, 0),
|
|
|
|
datetime(2019, 1, 3, 9, 15, 0),
|
|
|
|
datetime(2019, 1, 4, 9, 15, 0),
|
2021-10-02 13:23:48 +00:00
|
|
|
],
|
2020-10-28 13:36:19 +00:00
|
|
|
'close_date':
|
|
|
|
[
|
2021-10-02 13:23:48 +00:00
|
|
|
datetime(2019, 1, 1, 9, 25, 0),
|
2021-10-02 13:36:51 +00:00
|
|
|
datetime(2019, 1, 2, 9, 25, 0),
|
|
|
|
datetime(2019, 1, 3, 9, 25, 0),
|
|
|
|
datetime(2019, 1, 4, 9, 25, 0),
|
2021-10-02 13:23:48 +00:00
|
|
|
],
|
2020-10-28 13:36:19 +00:00
|
|
|
}
|
|
|
|
)
|