freqtrade_origin/tests/optimize/conftest.py

71 lines
2.0 KiB
Python
Raw Permalink 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
2022-03-25 07:36:03 +00:00
from freqtrade.enums import ExitType, RunMode
2022-09-26 08:11:00 +00:00
from freqtrade.optimize.backtesting import Backtesting
2020-10-28 13:36:19 +00:00
from freqtrade.optimize.hyperopt import Hyperopt
from tests.conftest import patch_exchange
2024-05-12 13:29:14 +00:00
@pytest.fixture(scope="function")
2020-10-28 13:36:19 +00:00
def hyperopt_conf(default_conf):
hyperconf = deepcopy(default_conf)
2024-05-12 13:29:14 +00:00
hyperconf.update(
{
"datadir": Path(default_conf["datadir"]),
"runmode": RunMode.HYPEROPT,
"strategy": "HyperoptableStrategy",
"hyperopt_loss": "ShortTradeDurHyperOptLoss",
"hyperopt_path": str(Path(__file__).parent / "hyperopts"),
"epochs": 1,
"timerange": None,
"spaces": ["default"],
"hyperopt_jobs": 1,
"hyperopt_min_trades": 1,
}
)
2020-10-28 13:36:19 +00:00
return hyperconf
2022-09-26 08:11:00 +00:00
@pytest.fixture(autouse=True)
2024-02-22 18:02:04 +00:00
def backtesting_cleanup():
2022-09-26 08:11:00 +00:00
yield None
Backtesting.cleanup()
2024-05-12 13:29:14 +00:00
@pytest.fixture(scope="function")
2020-10-28 13:36:19 +00:00
def hyperopt(hyperopt_conf, mocker):
patch_exchange(mocker)
return Hyperopt(hyperopt_conf)
2024-05-12 13:29:14 +00:00
@pytest.fixture(scope="function")
2020-10-28 13:36:19 +00:00
def hyperopt_results():
return pd.DataFrame(
{
2024-05-12 13:29:14 +00:00
"pair": ["ETH/USDT", "ETH/USDT", "ETH/USDT", "ETH/USDT"],
"profit_ratio": [-0.1, 0.2, -0.12, 0.3],
"profit_abs": [-0.2, 0.4, -0.21, 0.6],
"trade_duration": [10, 30, 10, 10],
"amount": [0.1, 0.1, 0.1, 0.1],
"exit_reason": [ExitType.STOP_LOSS, ExitType.ROI, ExitType.STOP_LOSS, ExitType.ROI],
"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),
],
2024-05-12 13:29:14 +00:00
"close_date": [
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),
],
2020-10-28 13:36:19 +00:00
}
)