freqtrade / freqtrade

Free, open source crypto trading bot
https://www.freqtrade.io
GNU General Public License v3.0
31.74k stars 6.44k forks source link

Hyperopt Data Type Issue #10418

Closed Tim-Walnut closed 4 months ago

Tim-Walnut commented 4 months ago

Describe your environment

Your question

I'm working with Hyperopt on a strategy, the relevant codes are below. Basically, it buys when an indicator is above a threshold.

...
    ent_thresh = DecimalParameter(0.01, 0.30, decimals=2, default=0.05, space='buy')
...
    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            (
                    ...
                    dataframe['indicator1'] > self.ent_thresh

            ),
            'enter_long'] = 1
        ...

Then, I have the following error message. I'd appreciate any help identifying the issue. Thanks!

2024-07-10 08:50:09,642 - freqtrade - ERROR - Fatal exception!
joblib.externals.loky.process_executor._RemoteTraceback:
"""
Traceback (most recent call last):
  File "/home/ftuser/.local/lib/python3.12/site-packages/joblib/externals/loky/process_executor.py", line 463, in _process_worker
    r = call_item()
        ^^^^^^^^^^^
  File "/home/ftuser/.local/lib/python3.12/site-packages/joblib/externals/loky/process_executor.py", line 291, in __call__
    return self.fn(*self.args, **self.kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ftuser/.local/lib/python3.12/site-packages/joblib/parallel.py", line 589, in __call__
    return [func(*args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^
  File "/home/ftuser/.local/lib/python3.12/site-packages/joblib/externals/loky/cloudpickle_wrapper.py", line 32, in __call__
    return self._obj(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/freqtrade/freqtrade/optimize/hyperopt.py", line 360, in generate_optimizer
    bt_results = self.backtesting.backtest(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/freqtrade/freqtrade/optimize/backtesting.py", line 1222, in backtest
    data: Dict = self._get_ohlcv_as_lists(processed)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/freqtrade/freqtrade/optimize/backtesting.py", line 382, in _get_ohlcv_as_lists
    df_analyzed = self.strategy.ft_advise_signals(pair_data, {'pair': pair})
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/freqtrade/freqtrade/strategy/interface.py", line 1404, in ft_advise_signals
    dataframe = self.advise_entry(dataframe, metadata)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/freqtrade/freqtrade/strategy/interface.py", line 1438, in advise_entry
    df = self.populate_entry_trend(dataframe, metadata)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/freqtrade/user_data/strategies/DumbV2_hyper.py", line 85, in populate_entry_trend
    dataframe['indicator1'] > self.ent_thresh
  File "/home/ftuser/.local/lib/python3.12/site-packages/pandas/core/ops/common.py", line 76, in new_method
    return method(self, other)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/ftuser/.local/lib/python3.12/site-packages/pandas/core/arraylike.py", line 56, in __gt__
    return self._cmp_method(other, operator.gt)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ftuser/.local/lib/python3.12/site-packages/pandas/core/series.py", line 6110, in _cmp_method
    res_values = ops.comparison_op(lvalues, rvalues, op)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ftuser/.local/lib/python3.12/site-packages/pandas/core/ops/array_ops.py", line 347, in comparison_op
    res_values = _na_arithmetic_op(lvalues, rvalues, op, is_cmp=True)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ftuser/.local/lib/python3.12/site-packages/pandas/core/ops/array_ops.py", line 218, in _na_arithmetic_op
    result = func(left, right)
             ^^^^^^^^^^^^^^^^^
  File "/home/ftuser/.local/lib/python3.12/site-packages/pandas/core/computation/expressions.py", line 242, in evaluate
    return _evaluate(op, op_str, a, b)  # type: ignore[misc]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ftuser/.local/lib/python3.12/site-packages/pandas/core/computation/expressions.py", line 131, in _evaluate_numexpr
    result = _evaluate_standard(op, op_str, a, b)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ftuser/.local/lib/python3.12/site-packages/pandas/core/computation/expressions.py", line 73, in _evaluate_standard
    return op(a, b)
           ^^^^^^^^
TypeError: '>' not supported between instances of 'float' and 'DecimalParameter'
"""

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

Traceback (most recent call last):
  File "/freqtrade/freqtrade/main.py", line 42, in main
    return_code = args['func'](args)
                  ^^^^^^^^^^^^^^^^^^
  File "/freqtrade/freqtrade/commands/optimize_commands.py", line 107, in start_hyperopt
    hyperopt.start()
  File "/freqtrade/freqtrade/optimize/hyperopt.py", line 616, in start
    f_val = self.run_optimizer_parallel(parallel, asked)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/freqtrade/freqtrade/optimize/hyperopt.py", line 439, in run_optimizer_parallel
    return parallel(delayed(
           ^^^^^^^^^^^^^^^^^
  File "/home/ftuser/.local/lib/python3.12/site-packages/joblib/parallel.py", line 1952, in __call__
    return output if self.return_generator else list(output)
                                                ^^^^^^^^^^^^
  File "/home/ftuser/.local/lib/python3.12/site-packages/joblib/parallel.py", line 1595, in _get_outputs
    yield from self._retrieve()
  File "/home/ftuser/.local/lib/python3.12/site-packages/joblib/parallel.py", line 1699, in _retrieve
    self._raise_error_fast()
  File "/home/ftuser/.local/lib/python3.12/site-packages/joblib/parallel.py", line 1734, in _raise_error_fast
    error_job.get_result(self.timeout)
  File "/home/ftuser/.local/lib/python3.12/site-packages/joblib/parallel.py", line 736, in get_result
    return self._return_or_raise()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ftuser/.local/lib/python3.12/site-packages/joblib/parallel.py", line 754, in _return_or_raise
    raise self._result
TypeError: '>' not supported between instances of 'float' and 'DecimalParameter'
stash86 commented 4 months ago

Use self.ent_thresh.value