-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Speed Enhancements #1330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Speed Enhancements #1330
Conversation
The Gemini backtesting framework appears to be deprecated. This moves it to the list of obsolete projects.
…ather than generating the full slice first. ~12% speed improvement
…changing positions at all. ~13% time saving
kernc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the late review. Some comments left ...
| arr = self.__cache[key] = cast(_Array, self.__arrays[key][:self.__len]) | ||
| return arr | ||
|
|
||
| def current_value(self, key: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit would be accepted, but as a private (underscored) method, for internal use only (below).
| open_price = data.current_value("Open") | ||
| high_price = data.current_value("High") | ||
| low_price = data.current_value("Low") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And without these name changes. 🙏
| def pl(self) -> float: | ||
| """Profit (positive) or loss (negative) of the current position in cash units.""" | ||
| return sum(trade.pl for trade in self.__broker.trades) | ||
| return self.__broker.unrealized_pl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memoization via functools.lru_cache or cached_property strongly preferred!
I've included here some speed enhancements from my video:
https://youtu.be/LSo4ghiAPvk
Running the SMA strategy from the README on my machine this PR gives a roughly 40% reduction in total runtime for
bt.runTests all pass