Replies: 4 comments 4 replies
-
@JJTittles; I can assure you that the plotting function works just fine. Here is a chart that I just ran. I'm running the backtesting.py library from pycharm without any problems, as well as a range of many other bokeh plots. If you'd like help getting it working, you're going to need to do better than "your thing doesn't work, so I'm throwing my toys out of the cot". If you can describe what you've tried, what you're seeing and what errors are appearing, it might be possible for others to offer their free time to assist you. |
Beta Was this translation helpful? Give feedback.
-
Thanks Paul for replying, unfortunately some of my frustrations came
through in my e-mail. Below is the code I was running along with output
stats and warning/error message. It runs ok until it tries to plot the
results in graph form. I am running Bokeh (3.1.1) and python (3.11). I have
tried is other a versions of Bokeh (3.4.1,/3,2.1). with no success.. Which
one should should I be running with the library?
Thanks
Patrick
--------------------------------Program--------------------------------------------------------------------
from backtesting import Backtest, Strategy
from backtesting.lib import crossover
from backtesting.test import SMA, GOOG
class SmaCross(Strategy):
n1 = 10
n2 = 20
def init(self):
close = self.data.Close
self.sma1 = self.I(SMA, close, self.n1)
self.sma2 = self.I(SMA, close, self.n2)
def next(self):
if crossover(self.sma1, self.sma2):
self.buy()
elif crossover(self.sma2, self.sma1):
self.sell()
bt = Backtest(GOOG, SmaCross,cash=10000, commission=.002,
exclusive_orders=True)
stats = bt.run()
print(stats)
bt.plot()
…-------------------------------------------Stats
output------------------------------------------------------------------------
runfile('E:/2GB HD Backup/User Files/Python Program files
(.py)/Test_backtester_code.py', wdir='E:/2GB HD Backup/User Files/Python
Program files (.py)')
Start 2004-08-19 00:00:00
End 2013-03-01 00:00:00
Duration 3116 days 00:00:00
Exposure Time [%] 97.067039
Equity Final [$] 68221.96986
Equity Peak [$] 68991.21986
Return [%] 582.219699
Buy & Hold Return [%] 703.458242
Return (Ann.) [%] 25.266427
Volatility (Ann.) [%] 38.383008
Sharpe Ratio 0.658271
Sortino Ratio 1.288779
Calmar Ratio 0.763748
Max. Drawdown [%] -33.082172
Avg. Drawdown [%] -5.581506
Max. Drawdown Duration 688 days 00:00:00
Avg. Drawdown Duration 41 days 00:00:00
# Trades 94
Win Rate [%] 54.255319
Best Trade [%] 57.11931
Worst Trade [%] -16.629898
Avg. Trade [%] 2.074326
Max. Trade Duration 121 days 00:00:00
Avg. Trade Duration 33 days 00:00:00
Profit Factor 2.190805
Expectancy [%] 2.606294
SQN 1.990216
_strategy SmaCross
_equity_curve ...
_trades Size EntryB...
dtype: object
--------------------------------------------------------------error/warning
message
-----------------------------------------------------------------------------------------------------
BokehDeprecationWarning: Passing lists of formats for DatetimeTickFormatter
scales was deprecated in Bokeh 3.0. Configure a single string format for
each scale
C:\Users\User\anaconda3\Lib\site-packages\backtesting\_plotting.py:250:
UserWarning: DatetimeFormatter scales now only accept a single format.
Using the first provided: '%d %b'
formatter=DatetimeTickFormatter(days=['%d %b', '%a %d'],
BokehDeprecationWarning: Passing lists of formats for DatetimeTickFormatter
scales was deprecated in Bokeh 3.0. Configure a single string format for
each scale
C:\Users\User\anaconda3\Lib\site-packages\backtesting\_plotting.py:250:
UserWarning: DatetimeFormatter scales now only accept a single format.
Using the first provided: '%m/%Y'
formatter=DatetimeTickFormatter(days=['%d %b', '%a %d'],
On Fri, 21 Jun 2024 at 21:16, Paul Ryder ***@***.***> wrote:
@JJTittles <https://github.com/JJTittles>; I can assure you that the
plotting function works just fine. Here is a chart that I just ran.
Screenshot.2024-06-22.110916.png (view on web)
<https://github.com/kernc/backtesting.py/assets/5959696/ef22d39d-42ed-44c1-b54e-133b80dfa9d1>
I'm running the backtesting.py library from pycharm without any problems,
as well as a range of many other bokeh plots. If you'd like help getting it
working, you're going to need to do better than "your thing doesn't work,
so I'm throwing my toys out of the cot". If you can describe what you've
tried, what you're seeing and what errors are appearing, it might be
possible for others to offer their free time to assist you.
—
Reply to this email directly, view it on GitHub
<#1150 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APNLQRTMKRYS27RQVJJWTZTZITF6DAVCNFSM6AAAAABJQ7GJWCVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TQNBUGY3DA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hey @JJTittles; no worries. Writing code can be a lonely and frustrating road. I'm a complete noob, not a software eng, so I understand how you feel. Noting the above...your error looks like its coming from Bokeh itself. If you navigate through backtesting.py to _plotting.py in your IDE, on about line 250 you'll see something like:
Bokeh now doesn't like inputs to Go into this line of code, comment out the list input (so you can go back) and instead write: This should work for you. Let me know how you go. As a tip, I paid the $10/mth for GitHub CoPilot...for someone like me who is clueless with code, its saved a lot of time. Works directly from with pycharm, or whatever IDE you use. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the tip!
…On Fri, 28 Jun 2024 at 20:53, Paul Ryder ***@***.***> wrote:
Hey @JJTittles <https://github.com/JJTittles>; no worries. Writing code
can be a lonely and frustrating road. I'm a complete noob, not a software
eng, so I understand how you feel.
Noting the above...your error looks like its coming from Bokeh itself. If
you navigate through backtesting.py to _plotting.py in your IDE, on about
line 250 you'll see something like:
if is_datetime_index: fig_ohlc.xaxis.formatter = CustomJSTickFormatter(
args=dict(axis=fig_ohlc.xaxis[0], formatter=DatetimeTickFormatter(days=['%d
%b', '%a %d'] months=['%m/%Y', "%b'%y"]), source=source)
Bokeh now doesn't like inputs to DatetimeTickFormatter to be a list.
Go into this line of code, comment out the list input (so you can go back)
and instead write:
formatter=DatetimeTickFormatter(days='%a, %d %b', # ['%d %b', '%a %d]'
months='%m/%Y'), # ['%m/%Y', "%b'%y"]
This should work for you. Let me know how you go. As a tip, I paid the
$10/mth for GitHub CoPilot...for someone like me who is clueless with code,
its saved a lot of time. Works directly from with pycharm, or whatever IDE
you use.
—
Reply to this email directly, view it on GitHub
<#1150 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/APNLQRWFAXLVPQRAM6QNS63ZJYARJAVCNFSM6AAAAABJQ7GJWCVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TSMBZGY3TI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi, I have recently downloaded backtesting.py and was using the sample sma crossover strategy provided. I am using the spyder GUI. The code ran and stats generated but the bt.plot() generate a number of errors and did not generate a chart. Several sources have pointed to compatibility issues with the Bokeh graphics library. I have uninstalled and reinstalled both Bokeh 3.2.1 and 3.1.1 versions and neither seems to work.
While the stats are nice if I cant get the graphing to work it is not much use to me. and I will need to try another backtesting library.
Beta Was this translation helpful? Give feedback.
All reactions