MCPcopy Create free account
hub / github.com/kernc/backtesting.py / _group_trades

Function _group_trades

backtesting/_plotting.py:169–176  ·  view source on GitHub ↗
(column)

Source from the content-addressed store, hash-verified

167 return ((df['Size'].abs() * df['ReturnPct']) / df['Size'].abs().sum()).sum()
168
169 def _group_trades(column):
170 def f(s, new_index=pd.Index(df.index.astype(np.int64)), bars=trades[column]):
171 if s.size:
172 # Via int64 because on pandas recently broken datetime
173 mean_time = int(bars.loc[s.index].astype(np.int64).mean())
174 new_bar_idx = new_index.get_indexer([mean_time], method='nearest')[0]
175 return new_bar_idx
176 return f
177
178 if len(trades): # Avoid pandas "resampling on Int64 index" error
179 trades = trades.assign(count=1).resample(freq, on='ExitTime', label='right').agg(dict(

Callers 1

_maybe_resample_dataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected