Stale cached data when optimising using Optuna

23 views Asked by At

I am running a backtest using Optuna ( trial Once only ), however I got some repetitive results. While if I just run this backtest itself, the result is fine. Has anyone got similar issue before ( it's the same strategy and input ) ?

Error result with Optuna:

2023-12-23 14:03:30,812 - Logger_Config - INFO - Date:2023-05-30 20:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0
2023-12-23 14:03:30,812 - Logger_Config - INFO - Date:2023-05-30 21:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0
2023-12-23 14:03:30,812 - Logger_Config - INFO - Date:2023-05-30 22:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0
2023-12-23 14:03:30,812 - Logger_Config - INFO - Date:2023-05-30 23:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:42.085882826206515    signal:0.0
2023-12-23 14:03:30,812 - Logger_Config - INFO - Date:2023-05-31 00:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:42.085882826206515    signal:0.0
2023-12-23 14:03:30,813 - Logger_Config - INFO - Date:2023-05-31 01:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:42.085882826206515    signal:0.0
2023-12-23 14:03:30,813 - Logger_Config - INFO - Date:2023-05-31 02:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:42.085882826206515    signal:0.0
2023-12-23 14:03:30,813 - Logger_Config - INFO - Date:2023-05-31 03:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:42.085882826206515    signal:0.0
2023-12-23 14:03:30,813 - Logger_Config - INFO - Date:2023-05-31 04:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:42.085882826206515    signal:0.0
2023-12-23 14:03:30,813 - Logger_Config - INFO - Date:2023-05-31 05:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:42.085882826206515    signal:0.0
2023-12-23 14:03:30,813 - Logger_Config - INFO - Date:2023-05-31 06:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:42.085882826206515    signal:0.0
2023-12-23 14:03:30,813 - Logger_Config - INFO - Date:2023-05-31 07:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0
2023-12-23 14:03:30,813 - Logger_Config - INFO - Date:2023-05-31 08:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0
2023-12-23 14:03:30,813 - Logger_Config - INFO - Date:2023-05-31 09:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0

Correct result just run the backtest:

2023-12-23 13:46:40,633 - Logger_Config - INFO - Date:2023-05-30 20:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0
2023-12-23 13:46:40,634 - Logger_Config - INFO - Date:2023-05-30 21:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0
2023-12-23 13:46:40,636 - Logger_Config - INFO - Date:2023-05-30 22:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0
2023-12-23 13:46:40,637 - Logger_Config - INFO - Date:2023-05-30 23:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0
2023-12-23 13:46:40,638 - Logger_Config - INFO - Date:2023-05-31 00:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0
2023-12-23 13:46:40,640 - Logger_Config - INFO - Date:2023-05-31 01:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0
2023-12-23 13:46:40,641 - Logger_Config - INFO - Date:2023-05-31 02:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0
2023-12-23 13:46:40,642 - Logger_Config - INFO - Date:2023-05-31 03:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:nan   signal:0.0
2023-12-23 13:46:40,644 - Logger_Config - INFO - Date:2023-05-31 04:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:41.41863934147713     signal:0.0
2023-12-23 13:46:40,645 - Logger_Config - INFO - Date:2023-05-31 05:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:36.72299108355483     signal:0.0
2023-12-23 13:46:40,646 - Logger_Config - INFO - Date:2023-05-31 06:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:34.41181843363085     signal:0.0
2023-12-23 13:46:40,647 - Logger_Config - INFO - Date:2023-05-31 07:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:32.66706040026315     signal:0.0
2023-12-23 13:46:40,649 - Logger_Config - INFO - Date:2023-05-31 08:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:31.109184036595103    signal:0.0
2023-12-23 13:46:40,650 - Logger_Config - INFO - Date:2023-05-31 09:00:00    QQE_MOD_Composite Indicator:    qqe_mod_hist1:nan   qqe_mod_hist2:29.873302267658804    signal:0.0

I used the following basic setup, thus should expect both sides return same results.


pfast = 29  # period for the fast moving average
pslow = 87  # period for the slow moving average
psignal = 30  # period for the signal moving average

cerebro.addstrategy(BacktraderCompositeStrategy,
                        logger=logger,
                        pfast=pfast,
                        pslow=pslow,
                        psignal=psignal,
                        ...
                   )


# Create the Optuna study and specify direction as 'minimize'
study = optuna.create_study(direction='minimize')

# Optimize the study, the objective function is passed in as the first argument
study.optimize(objective, n_trials=1)
0

There are 0 answers