Skip to content

ValueError: Invalid frequency: ME #1257

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

Open
xXgordonXx opened this issue Mar 27, 2025 · 1 comment
Open

ValueError: Invalid frequency: ME #1257

xXgordonXx opened this issue Mar 27, 2025 · 1 comment
Labels
wontfix This will not be worked on

Comments

@xXgordonXx
Copy link

Expected behavior

what i do:

  1. pip install backtesting
  2. run
    from backtesting import Backtest, Strategy
    from backtesting.lib import crossover

from backtesting.test import SMA, GOOG

class SmaCross(Strategy):
def init(self):
price = self.data.Close
self.ma1 = self.I(SMA, price, 10)
self.ma2 = self.I(SMA, price, 20)

def next(self):
    if crossover(self.ma1, self.ma2):
        self.buy()
    elif crossover(self.ma2, self.ma1):
        self.sell()

bt = Backtest(GOOG, SmaCross, commission=.002,
exclusive_orders=True)
stats = bt.run()
bt.plot()

  1. expected result: is ploting a sample graph

Code sample

from backtesting import Backtest, Strategy
from backtesting.lib import crossover

from backtesting.test import SMA, GOOG


class SmaCross(Strategy):
    def init(self):
        price = self.data.Close
        self.ma1 = self.I(SMA, price, 10)
        self.ma2 = self.I(SMA, price, 20)

    def next(self):
        if crossover(self.ma1, self.ma2):
            self.buy()
        elif crossover(self.ma2, self.ma1):
            self.sell()


bt = Backtest(GOOG, SmaCross, commission=.002,
              exclusive_orders=True)
stats = bt.run()
bt.plot()

Actual behavior

  1. error/ related report
    [ValueError: Invalid frequency: ME]

Image

reference: pandas-dev/pandas#57197

Additional info, steps to reproduce, full crash traceback, screenshots

  1. seems there is typo in _plot_superimposed_ohlc() function

    def _plot_superimposed_ohlc():
    """Superimposed, downsampled vbars"""
    time_resolution = pd.DatetimeIndex(df['datetime']).resolution
    resample_rule = (superimpose if isinstance(superimpose, str) else
    dict(day='ME',
    hour='D',
    minute='h',
    second='min',
    millisecond='s').get(time_resolution))

Software versions

  • Backtesting version: 0.?.?
  • bokeh.__version__:
  • OS:
@kernc
Copy link
Owner

kernc commented Mar 30, 2025

Please upgrade to pandas >= 2.2 or pass bt.plot(superimpose='M') or bt.plot(superimpose=False).

@kernc kernc added the wontfix This will not be worked on label Mar 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants