Skip to content
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

After modification in Backtesting.py: TypeError: strategy must be a Strategy sub-type #1034

Open
abderrahim-plb opened this issue Aug 2, 2023 · 1 comment
Labels
question Not a bug, but a FAQ entry

Comments

@abderrahim-plb
Copy link

abderrahim-plb commented Aug 2, 2023

Expected Behavior

Hello, I forked the repository, after that i followed the instructions and install it. I tried a first example of an sma strategy, i backtest it using :

bt = Backtest(df,SmaCross,cash=1000,commission=0.0005,margin=0.84,exclusive_orders=True)
output=bt.run()
bt.plot()

If i modify the file backtesting.py even with a simple comment, i am getting the error :

TypeError                                 Traceback (most recent call last)
Cell In[22], line 1
----> 1 bt = Backtest(df,SmaCross,cash=1000,commission=0.0005,margin=0.84,exclusive_orders=True)
      2 output=bt.run()
      3 bt.plot()

File ~/backtesting.py/backtesting/backtesting.py:1082, in Backtest.__init__(self, data, strategy, cash, commission, margin, trade_on_close, hedging, exclusive_orders)
   1035 """
   1036 Initialize a backtest. Requires data and a strategy to test.
   1037 
   (...)
   1078 [FIFO]: https://www.investopedia.com/terms/n/nfa-compliance-rule-2-43b.asp
   1079 """
   1081 if not (isinstance(strategy, type) and issubclass(strategy, Strategy)):
-> 1082     raise TypeError('`strategy` must be a Strategy sub-type')
   1083 if not isinstance(data, pd.DataFrame):
   1084     raise TypeError("`data` must be a pandas.DataFrame with columns")

TypeError: `strategy` must be a Strategy sub-type

I should restart the kernel, then everything works fine, but this isn't practical at all.

Actual Behavior

Can't modify in backtesting file, should restart the kernel.

Additional info

  • Backtesting version: 0.3.4.dev30+g0ce24d8
  • bokeh.__version__: '2.4.3 '
  • OS: MAC OS M1
@kernc
Copy link
Owner

kernc commented Aug 25, 2023

My idea was to simply change the line:

if not (isinstance(strategy, type) and issubclass(strategy, Strategy)):

to if False: or some such for the duration of development.

Let me know of any other ideas.

@kernc kernc added the question Not a bug, but a FAQ entry label Feb 2, 2025
@kernc kernc changed the title After any modification in Backtesting.py strategy Type error After modification in Backtesting.py: TypeError: strategy must be a Strategy sub-type Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Not a bug, but a FAQ entry
Projects
None yet
Development

No branches or pull requests

2 participants