Open btk-42 opened 4 months ago
Install the latest version from GitHub to incorporate recent fixes: pip install git+https://github.com/kernc/backtesting.py.git
The PyPI version (0.3.3) may not include the necessary fix
The solution is : In the file named _plotting.py
if is_datetime_index:
fig_ohlc.xaxis.formatter = CustomJSTickFormatter(
args=dict(axis=fig_ohlc.xaxis[0],
formatter=DatetimeTickFormatter(
days="%d %b %Y", # Example format for days
months="%b %Y", # Example format for months
hours="%H:%M", # Example format for hours
minutes="%H:%M", # Example format for minutes
seconds="%H:%M:%S" # Example format for seconds
),
source=source)
Best regards
Install the latest version from GitHub to incorporate recent fixes: pip install git+https://github.com/kernc/backtesting.py.git
The PyPI version (0.3.3) may not include the necessary fix
This helped me a lot, i was pulling out my hair yesterday trying to get this to work i tried everything under the sun, thank you so much, when will PyPi be updated to reflect the new changes?
I experienced the same issue and came across this thread.
THe solution here works perfectly (https://github.com/kernc/backtesting.py/issues/1158#issuecomment-2232993016)
When will we have the update in PyPI please?
Thank you!!
if is_datetime_index: fig_ohlc.xaxis.formatter = CustomJSTickFormatter( args=dict(axis=fig_ohlc.xaxis[0], formatter=DatetimeTickFormatter( days="%d %b %Y", # Example format for days months="%b %Y", # Example format for months hours="%H:%M", # Example format for hours minutes="%H:%M", # Example format for minutes seconds="%H:%M:%S" # Example format for seconds ),
installing from git returning same error
Not sure if this is still relevant but I had the same error until I made some adjustments to the initial data frame.
Initially, df = yf.Ticker("SPY").history(start='2010-01-01', end='2021-01-01').tz_localize(None) df.drop('Dividends', axis=1, inplace=True) df.drop('Stock Splits', axis=1, inplace=True) df.drop('Capital Gains', axis=1, inplace=True) df=df[df.High!=df.Low]
returned "ValueError: failed to validate DatetimeTickFormatter(id='p1996', ...).days: expected a value of type str, got ['%d %b', '%a %d'] of type list" for bt.plot()
But once I reset the index:
df = yf.Ticker("SPY").history(start='2010-01-01', end='2021-01-01').tz_localize(None)
df=df[df.High!=df.Low] df.drop('Dividends', axis=1, inplace=True) df.drop('Stock Splits', axis=1, inplace=True) df.drop('Capital Gains', axis=1, inplace=True) df.reset_index(inplace=True)
bt.plot() returns the figures
Expected Behavior
bt.plot() doesn't show up and returns error.
Actual Behavior
error:
Steps to Reproduce
code:
Additional info
Installing bokeh==3.4.2 fix the issue but makes everything lag and some other errors appears