backtesting.py
backtesting.py copied to clipboard
Backtest plotting results in empty graph
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

- Backtesting version: 0.3.3
-
bokeh.__version__
: 3.0.2 - Using Jupyter Notebook
- OS: MacOS Ventura 13.0 (Apple Silicon)
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
This issue falls in line with #803
Currently having to use python 3.8 with bokeh 2.4.3
Workaround
pip uninstall -y bokeh && pip install bokeh==2.4.3
Workaround
pip uninstall -y bokeh && pip install bokeh==2.4.3
And thats working with python 3.9?
Workaround
pip uninstall -y bokeh && pip install bokeh==2.4.3
And thats working with python 3.9?
Yes.
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.
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
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
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!
I'm getting: Javascript Error: unable to decode an object of type 'Row'
I take it back! something must have been cached. I ended up shutting down and actually restarting my machine and it worked! ugh.
I'm running backtesting.py on vscode. I can see the chart displayed however I cannot see the stats. Any recommendation?