stable/tests/optimize/conftest.py

55 lines
1.6 KiB
Python
Raw Normal View History

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
2021-06-08 19:20:35 +00:00
from freqtrade.enums import RunMode, SellType
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-08-26 05:18:26 +00:00
'hyperopt': 'HyperoptTestSepFile',
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(
{
'pair': ['ETH/BTC', 'ETH/BTC', 'ETH/BTC'],
'profit_ratio': [-0.1, 0.2, 0.3],
2020-10-28 13:36:19 +00:00
'profit_abs': [-0.2, 0.4, 0.6],
'trade_duration': [10, 30, 10],
'sell_reason': [SellType.STOP_LOSS, SellType.ROI, SellType.ROI],
'close_date':
[
datetime(2019, 1, 1, 9, 26, 3, 478039),
datetime(2019, 2, 1, 9, 26, 3, 478039),
datetime(2019, 3, 1, 9, 26, 3, 478039)
]
}
)