nateemma / strategies

Custom trading strategies using the freqtrade framework
331 stars 94 forks source link

HyperOpt Crash #14

Open aloksaurabh opened 1 year ago

aloksaurabh commented 1 year ago

Happens on all Linux installs Tried with setup.sh and conda installs Happens on stable and current dev builds Back testing with any time-range works fine

(freqtrade-conda2) alok@kaliSSD:/media/alok/New_Volume/kali/freqtrade$ freqtrade hyperopt --config user_data/strategies/binance/config_binance_short.json --strategy-path user_data/strategies/binance --strategy DWT_short  --epochs 5 --hyperopt-loss ExpectancyHyperOptLoss --timerange 20220915-20221015
2023-03-01 16:40:44,531 - freqtrade - INFO - freqtrade 2023.3.dev-d1b2e38ae

-------trimmed ------------------------
2023-03-01 16:41:57,627 - freqtrade.optimize.hyperopt - INFO - Using estimator ET.
2023-03-01 16:41:57,659 - freqtrade.optimize.hyperopt - INFO - Effective number of parallel workers used: 16

2023-03-01 16:42:07,724 - freqtrade - ERROR - Fatal exception!
joblib.externals.loky.process_executor._RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/joblib/externals/loky/process_executor.py", line 428, in _process_worker
    r = call_item()
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/joblib/externals/loky/process_executor.py", line 275, in __call__
    return self.fn(*self.args, **self.kwargs)
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/joblib/_parallel_backends.py", line 620, in __call__
    return self.func(*args, **kwargs)
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/joblib/parallel.py", line 288, in __call__
    return [func(*args, **kwargs)
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/joblib/parallel.py", line 288, in <listcomp>
    return [func(*args, **kwargs)
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/joblib/externals/loky/cloudpickle_wrapper.py", line 33, in __call__
    return self._obj(*args, **kwargs)
  File "/media/alok/New_Volume/kali/freqtrade/freqtrade/optimize/hyperopt.py", line 373, in generate_optimizer
    return self._get_results_dict(bt_results, self.min_date, self.max_date,
  File "/media/alok/New_Volume/kali/freqtrade/freqtrade/optimize/hyperopt.py", line 401, in _get_results_dict
    loss = self.calculate_loss(results=backtesting_results['results'],
  File "/media/alok/New_Volume/kali/freqtrade/user_data/hyperopts/ExpectancyHyperOptLoss.py", line 65, in hyperopt_loss_function
    total_profit_pct = results["profit_abs"] / stake
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/pandas/core/ops/common.py", line 72, in new_method
    return method(self, other)
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/pandas/core/arraylike.py", line 126, in __truediv__
    return self._arith_method(other, operator.truediv)
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/pandas/core/series.py", line 6259, in _arith_method
    return base.IndexOpsMixin._arith_method(self, other, op)
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/pandas/core/base.py", line 1325, in _arith_method
    result = ops.arithmetic_op(lvalues, rvalues, op)
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/pandas/core/ops/array_ops.py", line 226, in arithmetic_op
    res_values = _na_arithmetic_op(left, right, op)  # type: ignore[arg-type]
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/pandas/core/ops/array_ops.py", line 165, in _na_arithmetic_op
    result = func(left, right)
TypeError: ufunc 'divide' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/media/alok/New_Volume/kali/freqtrade/freqtrade/main.py", line 42, in main
    return_code = args['func'](args)
  File "/media/alok/New_Volume/kali/freqtrade/freqtrade/commands/optimize_commands.py", line 107, in start_hyperopt
    hyperopt.start()
  File "/media/alok/New_Volume/kali/freqtrade/freqtrade/optimize/hyperopt.py", line 630, in start
    f_val = self.run_optimizer_parallel(parallel, asked)
  File "/media/alok/New_Volume/kali/freqtrade/freqtrade/optimize/hyperopt.py", line 440, in run_optimizer_parallel
    return parallel(delayed(
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/joblib/parallel.py", line 1098, in __call__
    self.retrieve()
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/joblib/parallel.py", line 975, in retrieve
    self._output.extend(job.get(timeout=self.timeout))
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/site-packages/joblib/_parallel_backends.py", line 567, in wrap_future_result
    return future.result(timeout=timeout)
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/concurrent/futures/_base.py", line 445, in result
    return self.__get_result()
  File "/home/alok/miniconda3/envs/freqtrade-conda2/lib/python3.10/concurrent/futures/_base.py", line 390, in __get_result
    raise self._exception
TypeError: ufunc 'divide' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

SampleStrategy HyperOpt also works fine

(freqtrade-conda2) alok@kaliSSD:/media/alok/New_Volume/kali/freqtrade$ freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --strategy SampleStrategy --config ./user_data/config_ds.json -e 10 --timerange 20210101-20210201
2023-03-01 16:42:33,561 - freqtrade - INFO - freqtrade 2023.3.dev-d1b2e38ae
2023-03-01 16:42:33,572 - freqtrade.configuration.load_config - INFO - Using config: ./user_data/config_ds.json ...
2023-03-01 16:42:33,572 - freqtrade.loggers - INFO - Verbosity set to 0
2

-------------trimmed--------------------

2023-03-01 16:44:03,952 - freqtrade.optimize.hyperopt - INFO - Number of parallel jobs set as: -1
2023-03-01 16:44:03,952 - freqtrade.optimize.hyperopt - INFO - Using estimator ET.
2023-03-01 16:44:03,962 - freqtrade.optimize.hyperopt - INFO - Effective number of parallel workers used: 16
+--------+---------+----------+--------------------------+--------------+-------------------------------+-----------------+-------------+-------------------------------+
|   Best |   Epoch |   Trades |    Win  Draw  Loss  Win% |   Avg profit |                        Profit |    Avg duration |   Objective |           Max Drawdown (Acct) |
|--------+---------+----------+--------------------------+--------------+-------------------------------+-----------------+-------------+-------------------------------|
| * Best |    1/10 |      166 |    107    53     6  64.5 |        1.05% |       185.488 USDT   (18.55%) | 0 days 03:46:00 |    -9.45209 |        45.303 USDT    (4.08%) |
| * Best |    3/10 |      739 |    320   406    13  43.3 |        0.66% |       624.189 USDT   (62.42%) | 0 days 09:58:00 |    -11.7834 |        91.865 USDT    (5.35%) |                                                                 
 [Epoch 10 of 10 (100%)] ||                                                                                                                                                                      | [Time:  0:00:00, Elapsed Time: 0:00:00]
2023-03-01 16:44:45,551 - freqtrade.optimize.hyperopt - INFO - 10 epochs saved to '/media/alok/New_Volume/kali/freqtrade/user_data/hyperopt_results/strategy_SampleStrategy_2023-03-01_16-42-55.fthypt'.
Add {
        "method": "AgeFilter",
        "min_days_listed": 30
},
 to your pairlists in config (Under StaticPairList)
2023-03-01 16:44:45,568 - NostalgiaForInfinityX - INFO - pandas_ta successfully imported
2023-03-01 16:44:45,579 - NostalgiaForInfinityX3 - INFO - pandas_ta successfully imported
2023-03-01 16:44:45,589 - freqtrade.optimize.hyperopt_tools - INFO - Dumping parameters to /media/alok/New_Volume/kali/freqtrade/user_data/strategies/sample_strategy.json

Best result:

*    3/10:    739 trades. 320/406/13 Wins/Draws/Losses. Avg profit   0.66%. Median profit   0.00%. Total profit 624.18882109 USDT (  62.42%). Avg duration 9:58:00 min. Objective: -11.78339
aloksaurabh commented 1 year ago

My conda environment details attached packages.txt . Could you please post yours as well or may be take a guess on what could be causing this crash?

aloksaurabh commented 1 year ago

i found the issue in file https://github.com/nateemma/strategies/blob/master/hyperopts/ExpectancyHyperOptLoss.py in line number 64 stake = backtest_stats['stake_amount'] You need to handle what if stake amount is 'unlimited'