Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions backtesting/_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ def _windos_safe_filename(filename):
return filename


def _remove_timezone(values):
if isinstance(values, pd.DatetimeIndex):
return values.tz_localize(None) if values.tz is not None else values
if isinstance(values, pd.Series) and isinstance(values.dtype, pd.DatetimeTZDtype):
return values.dt.tz_localize(None)
return values


def _bokeh_reset(filename=None):
curstate().reset()
if filename:
Expand Down Expand Up @@ -239,7 +247,7 @@ def plot(*, results: pd.Series,
resample, df, indicators, equity_data, trades)

df.index.name = None # Provides source name @index
df['datetime'] = df.index # Save original, maybe datetime index
df['datetime'] = _remove_timezone(df.index) # Save original, maybe datetime index
df = df.reset_index(drop=True)
equity_data = equity_data.reset_index(drop=True)
index = df.index
Expand Down Expand Up @@ -268,7 +276,7 @@ def plot(*, results: pd.Series,

trade_source = ColumnDataSource(dict(
index=trades['ExitBar'],
datetime=trades['ExitTime'],
datetime=_remove_timezone(trades['ExitTime']),
size=trades['Size'],
returns_positive=(trades['ReturnPct'] > 0).astype(int).astype(str),
))
Expand Down