kernc / backtesting.py

:mag_right: :chart_with_upwards_trend: :snake: :moneybag: Backtest trading strategies in Python.
https://kernc.github.io/backtesting.py/
GNU Affero General Public License v3.0
5.3k stars 1.04k forks source link

Backtest plotting results in empty graph #840

Open trueToastedCode opened 1 year ago

trueToastedCode commented 1 year ago

Expected Behavior

Graph should not be empty

Actual Behavior

There are also tons of warnings in the console...

/Users/lennard/opt/miniconda3/envs/torch/lib/python3.9/site-packages/backtesting/_plotting.py:122: UserWarning:

Data contains too many candlesticks to plot; downsampling to '1H'. See `Backtest.plot(resample=...)`

/Users/lennard/opt/miniconda3/envs/torch/lib/python3.9/site-packages/backtesting/_plotting.py:148: FutureWarning:

Passing method to Int64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead.

BokehDeprecationWarning: Passing lists of formats for DatetimeTickFormatter scales was deprecated in Bokeh 3.0. Configure a single string format for each scale
/Users/lennard/opt/miniconda3/envs/torch/lib/python3.9/site-packages/bokeh/models/formatters.py:399: UserWarning:

DatetimeFormatter scales now only accept a single format. Using the first prodvided: '%d %b' 

BokehDeprecationWarning: Passing lists of formats for DatetimeTickFormatter scales was deprecated in Bokeh 3.0. Configure a single string format for each scale
/Users/lennard/opt/miniconda3/envs/torch/lib/python3.9/site-packages/bokeh/models/formatters.py:399: UserWarning:

DatetimeFormatter scales now only accept a single format. Using the first prodvided: '%m/%Y' 

Steps to Reproduce

... doesn't matter ...

bt = Backtest(dfpl, MyStrategy, cash=100, margin=1/10, commission=.0)

# backtesting.set_bokeh_output(notebook=False) - doesn't matter

bt.plot(show_legend=False)

Additional info

Bildschirm­foto 2022-12-13 um 17 49 54

yes there are stats if I run the strategy:

Start                     2020-01-01 22:00:00
End                       2020-12-31 21:55:00
Duration                    364 days 23:55:00
Exposure Time [%]                    4.700638
Equity Final [$]                   139.304018
Equity Peak [$]                    139.533855
Return [%]                          39.304018
Buy & Hold Return [%]                8.932887
Return (Ann.) [%]                   30.478123
Volatility (Ann.) [%]               17.919015
Sharpe Ratio                         1.700882
Sortino Ratio                        3.531841
Calmar Ratio                         4.042517
Max. Drawdown [%]                   -7.539393
Avg. Drawdown [%]                   -0.858869
Max. Drawdown Duration       55 days 19:15:00
Avg. Drawdown Duration        3 days 12:49:00
# Trades                                  748
Win Rate [%]                        49.465241
Best Trade [%]                       0.222753
Worst Trade [%]                     -0.230765
Avg. Trade [%]                        0.00461
Max. Trade Duration           2 days 00:45:00
Avg. Trade Duration           0 days 00:27:00
Profit Factor                        1.269556
Expectancy [%]                       0.004625
SQN                                  2.384091
_strategy                          MyStrategy
_equity_curve                             ...
_trades                        Size  Entry...
dtype: object
micascheid commented 1 year ago

This issue falls in line with #803

Currently having to use python 3.8 with bokeh 2.4.3

trueToastedCode commented 1 year ago

Workaround pip uninstall -y bokeh && pip install bokeh==2.4.3

micascheid commented 1 year ago

Workaround pip uninstall -y bokeh && pip install bokeh==2.4.3

And thats working with python 3.9?

trueToastedCode commented 1 year ago

Workaround pip uninstall -y bokeh && pip install bokeh==2.4.3

And thats working with python 3.9?

Yes.

micascheid commented 1 year ago

Workaround pip uninstall -y bokeh && pip install bokeh==2.4.3

And thats working with python 3.9?

Y

Just ran it with python 3.11. And got that working. Sticking with bokeh 2.4.3 for now.

kiann00 commented 1 year ago

Workaround pip uninstall -y bokeh && pip install bokeh==2.4.3

And thats working with python 3.9?

Yes.

hmmm, I am also using python 3.9, and somehow this working around doesn't work

trueToastedCode commented 1 year ago

Workaround pip uninstall -y bokeh && pip install bokeh==2.4.3

And thats working with python 3.9?

Yes.

hmmm, I am also using python 3.9, and somehow this working around doesn't work

I also needed to restart my Jupyter notebook… otherwise idk why it would not work for u

krairy commented 1 year ago

Downgrading BokehJS from v3.0.3 to v2.4.3 worked for me too (Windows, Python 3.10, Jupyter server 6.4.12, IPython 8.4.0). Thanks so much!

stonematt commented 1 year ago

I'm getting: Javascript Error: unable to decode an object of type 'Row'

stonematt commented 1 year ago

I take it back! something must have been cached. I ended up shutting down and actually restarting my machine and it worked! ugh.

PlantBasedCrypto commented 1 year ago

I'm running backtesting.py on vscode. I can see the chart displayed however I cannot see the stats. Any recommendation?