添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
善良的手电筒  ·  TypeError: cannot do ...·  3 天前    · 
玩篮球的韭菜  ·  boxGrob function - ...·  3 周前    · 
儒雅的豆芽  ·  FPGA ERROR DRC INBB-3 ...·  3 周前    · 
逃课的充电器  ·  PyQT Tutorial·  1 月前    · 
魁梧的羊肉串  ·  Running a Pytorch ...·  1 月前    · 
憨厚的烈酒  ·  Django其实不是MVC - @Lenciel·  4 月前    · 
正直的铁链  ·  2.0 - Triggers | ...·  1 年前    · 

TypeError: cannot do positional indexing on RangeIndex with these indexers [nan] of type float - Backtesting #9831

Closed

Description

Describe your environment

  • Operating system: Ubuntu 23.10
  • Python Version: 3.11.2
  • CCXT version: ccxt==4.2.25
  • Freqtrade Version: freqtrade 2024.1
  • Describe the problem:

    Trying to run a backtest with this command

     freqtrade backtesting  -c config.json --timerange 20170101-20240206 --strategy Test  --freqaimodel XG
    BoostRegressor --timeframe 8h
    

    Explain the problem you have encountered

    2024-02-18 18:56:05,122 - freqtrade.optimize.backtesting - INFO - Backtesting with data from 2019-09-16 00:00:00 up to 2024-02-06 00:00:00 (1604 days).
    /home/the-box/Github/freqtrade/freqtrade/data/metrics.py:147: FutureWarning: The behavior of Series.idxmin with all-NA values, or any-NA and skipna=False, is deprecated. In a future version this will raise ValueError
      else max_drawdown_df['drawdown'].idxmin()
    2024-02-18 18:56:08,230 - freqtrade - ERROR - Fatal exception!
    Traceback (most recent call last):
      File "/home/the-box/Github/freqtrade/freqtrade/main.py", line 42, in main
        return_code = args['func'](args)
                      ^^^^^^^^^^^^^^^^^^
      File "/home/the-box/Github/freqtrade/freqtrade/commands/optimize_commands.py", line 58, in start_backtesting
        backtesting.start()
      File "/home/the-box/Github/freqtrade/freqtrade/optimize/backtesting.py", line 1397, in start
        results = generate_backtest_stats(
                  ^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/the-box/Github/freqtrade/freqtrade/optimize/optimize_reports/optimize_reports.py", line 559, in generate_backtest_stats
        strat_stats = generate_strategy_stats(pairlist, strategy, content,
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/the-box/Github/freqtrade/freqtrade/optimize/optimize_reports/optimize_reports.py", line 438, in generate_strategy_stats
        'calmar': calculate_calmar(results, min_date, max_date, start_balance),
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/the-box/Github/freqtrade/freqtrade/data/metrics.py", line 300, in calculate_calmar
        _, _, _, _, _, max_drawdown = calculate_max_drawdown(
                                      ^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/the-box/Github/freqtrade/freqtrade/data/metrics.py", line 150, in calculate_max_drawdown
        high_date = profit_results.loc[max_drawdown_df.iloc[:idxmin]['high_value'].idxmax(), date_col]
                                       ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
      File "/home/the-box/Github/freqtrade/.venv/lib/python3.11/site-packages/pandas/core/indexing.py", line 1153, in __getitem__
        return self._getitem_axis(maybe_callable, axis=axis)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/the-box/Github/freqtrade/.venv/lib/python3.11/site-packages/pandas/core/indexing.py", line 1691, in _getitem_axis
        return self._get_slice_axis(key, axis=axis)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/the-box/Github/freqtrade/.venv/lib/python3.11/site-packages/pandas/core/indexing.py", line 1726, in _get_slice_axis
        labels._validate_positional_slice(slice_obj)
      File "/home/the-box/Github/freqtrade/.venv/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 4197, in _validate_positional_slice
        self._validate_indexer("positional", key.stop, "iloc")
      File "/home/the-box/Github/freqtrade/.venv/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 6637, in _validate_indexer
        self._raise_invalid_indexer(form, key)
      File "/home/the-box/Github/freqtrade/.venv/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 4306, in _raise_invalid_indexer
        raise TypeError(msg)
    TypeError: cannot do positional indexing on RangeIndex with these indexers [nan] of type float
    

    Steps to reproduce:

    Run the commands above with my strategy
    The weird thing is that this happens when I run on 8h, running on 12h and 1d works perfectly fine.

    Observed Results:

  • What happened?
    The error above
  • What did you expect to happen?
    Backtest to complete normally
  • I also ran the freqtrade lookahead-analysis to see if I was doing something weird, but it passed the test

    I make my indicators, I don't think I'm doing anything wrong with this (below snippet).
    I use it to calculate an average based on a rolling period of previous candles, so for each new candle, look back to start_at_bar and compute something

                for _index, (_, _) in enumerate(dataframe.iterrows()):
                    for i in range(start_at_bar + 1):
                        y = dataframe['ohlc4'].shift(i).iloc[_index]
                        # Do some arithmetic, no more .shift() nor .iloc[i]

    Update: I tried running it on dry mode to see if the logs showed something

    2024-02-18 20:03:14,199 - freqtrade.strategy.interface - WARNING - Unable to analyze candle (OHLCV) data for pair BTC/USDT:USDT: Dataframe returned from strategy has mismatching last close price.

    I'm not sure if this is the reason

        heikinashi = qtpylib.heikinashi(dataframe)
        dataframe["open"] = heikinashi["open"]
        dataframe["close"] = heikinashi["close"]
        dataframe["high"] = heikinashi["high"]
        dataframe["low"] = heikinashi["low"]

    Is this allowed?

    Reverting to the normal candles (removing the snippet above) causes the same error to appear on backtesting on 1d

    However, this happens if I run the historical data, if I run the last few months, the backtest is successful .

    Maybe something with this?

    FutureWarning: The behavior of Series.idxmin with all-NA values, or any-NA and skipna=False, is deprecated. In a future version this will raise ValueError
      else max_drawdown_df['drawdown'].idxmin()
    2024-02-18 20:19:19,329 - freqtrade - ERROR - Fatal exception!
    
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Assignees

    No one assigned

    Labels

    Backtest Issues related backtesting. Bug Confirmed Bugs / problematic behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions