Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9c93ad2

Browse filesBrowse files
committed
REF: lib.FractionalBacktest: Precompute patched data once instead of before each run
1 parent 270fec6 commit 9c93ad2
Copy full SHA for 9c93ad2

1 file changed

+6-4Lines changed: 6 additions & 4 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎backtesting/lib.py‎

Copy file name to clipboardExpand all lines: backtesting/lib.py
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,15 +534,17 @@ def __init__(self,
534534
category=DeprecationWarning, stacklevel=2)
535535
fractional_unit = 1 / kwargs.pop('satoshi')
536536
self._fractional_unit = fractional_unit
537+
self.__data: pd.DataFrame = data.copy(deep=False) # Shallow copy
538+
for col in ('Open', 'High', 'Low', 'Close',):
539+
self.__data[col] = self.__data[col] * self._fractional_unit
540+
for col in ('Volume',):
541+
self.__data[col] = self.__data[col] / self._fractional_unit
537542
with warnings.catch_warnings(record=True):
538543
warnings.filterwarnings(action='ignore', message='frac')
539544
super().__init__(data, *args, **kwargs)
540545

541546
def run(self, **kwargs) -> pd.Series:
542-
data = self._data.copy()
543-
data[['Open', 'High', 'Low', 'Close']] *= self._fractional_unit
544-
data['Volume'] /= self._fractional_unit
545-
with patch(self, '_data', data):
547+
with patch(self, '_data', self.__data):
546548
result = super().run(**kwargs)
547549

548550
trades: pd.DataFrame = result['_trades']

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.