|
|
|
@@ -30,6 +30,7 @@ def is_mac() -> bool:
|
|
|
|
|
@pytest.mark.parametrize('model', [
|
|
|
|
|
'LightGBMRegressor',
|
|
|
|
|
'XGBoostRegressor',
|
|
|
|
|
'XGBoostRFRegressor',
|
|
|
|
|
'CatboostRegressor',
|
|
|
|
|
'ReinforcementLearner',
|
|
|
|
|
'ReinforcementLearner_multiproc',
|
|
|
|
@@ -69,10 +70,17 @@ def test_extract_data_and_train_model_Standard(mocker, freqai_conf, model):
|
|
|
|
|
|
|
|
|
|
data_load_timerange = TimeRange.parse_timerange("20180125-20180130")
|
|
|
|
|
new_timerange = TimeRange.parse_timerange("20180127-20180130")
|
|
|
|
|
freqai.dk.set_paths('ADA/BTC', None)
|
|
|
|
|
|
|
|
|
|
freqai.train_timer("start", "ADA/BTC")
|
|
|
|
|
freqai.extract_data_and_train_model(
|
|
|
|
|
new_timerange, "ADA/BTC", strategy, freqai.dk, data_load_timerange)
|
|
|
|
|
freqai.train_timer("stop", "ADA/BTC")
|
|
|
|
|
freqai.dd.save_metric_tracker_to_disk()
|
|
|
|
|
freqai.dd.save_drawer_to_disk()
|
|
|
|
|
|
|
|
|
|
assert Path(freqai.dk.full_path / "metric_tracker.json").is_file()
|
|
|
|
|
assert Path(freqai.dk.full_path / "pair_dictionary.json").is_file()
|
|
|
|
|
assert Path(freqai.dk.data_path /
|
|
|
|
|
f"{freqai.dk.model_filename}_model.{model_save_ext}").is_file()
|
|
|
|
|
assert Path(freqai.dk.data_path / f"{freqai.dk.model_filename}_metadata.json").is_file()
|
|
|
|
@@ -107,6 +115,7 @@ def test_extract_data_and_train_model_MultiTargets(mocker, freqai_conf, model):
|
|
|
|
|
|
|
|
|
|
data_load_timerange = TimeRange.parse_timerange("20180110-20180130")
|
|
|
|
|
new_timerange = TimeRange.parse_timerange("20180120-20180130")
|
|
|
|
|
freqai.dk.set_paths('ADA/BTC', None)
|
|
|
|
|
|
|
|
|
|
freqai.extract_data_and_train_model(
|
|
|
|
|
new_timerange, "ADA/BTC", strategy, freqai.dk, data_load_timerange)
|
|
|
|
@@ -125,6 +134,7 @@ def test_extract_data_and_train_model_MultiTargets(mocker, freqai_conf, model):
|
|
|
|
|
'LightGBMClassifier',
|
|
|
|
|
'CatboostClassifier',
|
|
|
|
|
'XGBoostClassifier',
|
|
|
|
|
'XGBoostRFClassifier',
|
|
|
|
|
])
|
|
|
|
|
def test_extract_data_and_train_model_Classifiers(mocker, freqai_conf, model):
|
|
|
|
|
if is_arm() and model == 'CatboostClassifier':
|
|
|
|
@@ -148,6 +158,7 @@ def test_extract_data_and_train_model_Classifiers(mocker, freqai_conf, model):
|
|
|
|
|
|
|
|
|
|
data_load_timerange = TimeRange.parse_timerange("20180110-20180130")
|
|
|
|
|
new_timerange = TimeRange.parse_timerange("20180120-20180130")
|
|
|
|
|
freqai.dk.set_paths('ADA/BTC', None)
|
|
|
|
|
|
|
|
|
|
freqai.extract_data_and_train_model(new_timerange, "ADA/BTC",
|
|
|
|
|
strategy, freqai.dk, data_load_timerange)
|
|
|
|
@@ -172,7 +183,7 @@ def test_extract_data_and_train_model_Classifiers(mocker, freqai_conf, model):
|
|
|
|
|
("CatboostClassifier", 6, "freqai_test_classifier")
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_start_backtesting(mocker, freqai_conf, model, num_files, strat):
|
|
|
|
|
def test_start_backtesting(mocker, freqai_conf, model, num_files, strat, caplog):
|
|
|
|
|
freqai_conf.get("freqai", {}).update({"save_backtest_models": True})
|
|
|
|
|
freqai_conf['runmode'] = RunMode.BACKTEST
|
|
|
|
|
if is_arm() and "Catboost" in model:
|
|
|
|
@@ -205,6 +216,9 @@ def test_start_backtesting(mocker, freqai_conf, model, num_files, strat):
|
|
|
|
|
corr_df, base_df = freqai.dd.get_base_and_corr_dataframes(sub_timerange, "LTC/BTC", freqai.dk)
|
|
|
|
|
|
|
|
|
|
df = freqai.dk.use_strategy_to_populate_indicators(strategy, corr_df, base_df, "LTC/BTC")
|
|
|
|
|
for i in range(5):
|
|
|
|
|
df[f'%-constant_{i}'] = i
|
|
|
|
|
# df.loc[:, f'%-constant_{i}'] = i
|
|
|
|
|
|
|
|
|
|
metadata = {"pair": "LTC/BTC"}
|
|
|
|
|
freqai.start_backtesting(df, metadata, freqai.dk)
|
|
|
|
@@ -212,6 +226,14 @@ def test_start_backtesting(mocker, freqai_conf, model, num_files, strat):
|
|
|
|
|
|
|
|
|
|
assert len(model_folders) == num_files
|
|
|
|
|
Trade.use_db = True
|
|
|
|
|
assert log_has_re(
|
|
|
|
|
"Removed features ",
|
|
|
|
|
caplog,
|
|
|
|
|
)
|
|
|
|
|
assert log_has_re(
|
|
|
|
|
"Removed 5 features from prediction features, ",
|
|
|
|
|
caplog,
|
|
|
|
|
)
|
|
|
|
|
Backtesting.cleanup()
|
|
|
|
|
shutil.rmtree(Path(freqai.dk.full_path))
|
|
|
|
|
|
|
|
|
@@ -237,6 +259,7 @@ def test_start_backtesting_subdaily_backtest_period(mocker, freqai_conf):
|
|
|
|
|
metadata = {"pair": "LTC/BTC"}
|
|
|
|
|
freqai.start_backtesting(df, metadata, freqai.dk)
|
|
|
|
|
model_folders = [x for x in freqai.dd.full_path.iterdir() if x.is_dir()]
|
|
|
|
|
|
|
|
|
|
assert len(model_folders) == 9
|
|
|
|
|
|
|
|
|
|
shutil.rmtree(Path(freqai.dk.full_path))
|
|
|
|
@@ -281,6 +304,7 @@ def test_start_backtesting_from_existing_folder(mocker, freqai_conf, caplog):
|
|
|
|
|
corr_df, base_df = freqai.dd.get_base_and_corr_dataframes(sub_timerange, "LTC/BTC", freqai.dk)
|
|
|
|
|
|
|
|
|
|
df = freqai.dk.use_strategy_to_populate_indicators(strategy, corr_df, base_df, "LTC/BTC")
|
|
|
|
|
|
|
|
|
|
freqai.start_backtesting(df, metadata, freqai.dk)
|
|
|
|
|
|
|
|
|
|
assert log_has_re(
|
|
|
|
@@ -337,6 +361,7 @@ def test_follow_mode(mocker, freqai_conf):
|
|
|
|
|
freqai.dd.load_all_pair_histories(timerange, freqai.dk)
|
|
|
|
|
|
|
|
|
|
df = strategy.dp.get_pair_dataframe('ADA/BTC', '5m')
|
|
|
|
|
|
|
|
|
|
freqai.start_live(df, metadata, strategy, freqai.dk)
|
|
|
|
|
|
|
|
|
|
assert len(freqai.dk.return_dataframe.index) == 5702
|
|
|
|
|