Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented a parameter for skipping errors during model training in the backtest process #10098

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions config_examples/config_freqai.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
],
"freqai": {
"enabled": true,
"warn_exceptions_on_backtest_only": false,
"purge_old_models": 2,
"train_period_days": 15,
"backtest_period_days": 7,
Expand Down
49 changes: 35 additions & 14 deletions freqtrade/freqai/freqai_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@

record_params(config, self.full_path)

self.new_feature_selector = self.config.get('freqai', {}) \
.get('warn_exceptions_on_backtest_only', False)

def __getstate__(self):
"""
Return an empty state to be pickled in hyperopt
Expand Down Expand Up @@ -257,7 +260,7 @@
if self.freqai_info.get('write_metrics_to_disk', False):
self.dd.save_metric_tracker_to_disk()

def start_backtesting(

Check failure on line 263 in freqtrade/freqai/freqai_interface.py

View workflow job for this annotation

GitHub Actions / build-windows (windows-latest, 3.11)

Ruff (C901)

freqtrade\freqai\freqai_interface.py:263:9: C901 `start_backtesting` is too complex (16 > 12)

Check failure on line 263 in freqtrade/freqai/freqai_interface.py

View workflow job for this annotation

GitHub Actions / build-linux (ubuntu-20.04, 3.11)

Ruff (C901)

freqtrade/freqai/freqai_interface.py:263:9: C901 `start_backtesting` is too complex (16 > 12)
self, dataframe: DataFrame, metadata: dict, dk: FreqaiDataKitchen, strategy: IStrategy
) -> FreqaiDataKitchen:
"""
Expand Down Expand Up @@ -354,25 +357,43 @@
logger.warning(
f"Training {pair} raised exception {msg.__class__.__name__}. "
f"Message: {msg}, skipping.", exc_info=True)

if self.new_feature_selector:
xsa-dev marked this conversation as resolved.
Show resolved Hide resolved
logger.warning(
"Train failed. Try to train on next pair." \
if self.new_feature_selector else
"Train failed. Raise error, fix data issue and try again."
)
self.tb_logger.close()
self.model = None

self.dd.pair_dict[pair]["trained_timestamp"] = int(
tr_train.stopts)
if self.plot_features and self.model is not None:
plot_feature_importance(self.model, pair, dk, self.plot_features)
if self.save_backtest_models and self.model is not None:
logger.info('Saving backtest model to disk.')
self.dd.save_data(self.model, pair, dk)
else:
logger.info('Saving metadata to disk.')
self.dd.save_metadata(dk)
hard_check_model_valid = True
if self.new_feature_selector:
hard_check_model_valid = bool(False if self.model is None else True)
if hard_check_model_valid:
logger.info(
"Model is trained. Saving model and metadata to disk."
)

if hard_check_model_valid:
self.dd.pair_dict[pair]["trained_timestamp"] = int(tr_train.stopts)
if self.plot_features and self.model is not None:
plot_feature_importance(self.model, pair, dk, self.plot_features)
if self.save_backtest_models and self.model is not None:
logger.info('Saving backtest model to disk.')
self.dd.save_data(self.model, pair, dk)
else:
logger.info('Saving metadata to disk.')
self.dd.save_metadata(dk)

else:
self.model = self.dd.load_data(pair, dk)

pred_df, do_preds = self.predict(dataframe_backtest, dk)
append_df = dk.get_predictions_to_append(pred_df, do_preds, dataframe_backtest)
dk.append_predictions(append_df)
dk.save_backtesting_prediction(append_df)
if hard_check_model_valid:
pred_df, do_preds = self.predict(dataframe_backtest, dk)
append_df = dk.get_predictions_to_append(pred_df, do_preds, dataframe_backtest)
dk.append_predictions(append_df)
xsa-dev marked this conversation as resolved.
Show resolved Hide resolved
dk.save_backtesting_prediction(append_df)

self.backtesting_fit_live_predictions(dk)
dk.fill_predictions(dataframe)
Expand Down