Skip to content

Conversation

@ChadThackray
Copy link

@ChadThackray ChadThackray commented Nov 6, 2025

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.run

Tests all pass

nillvitor and others added 5 commits November 6, 2025 18:07
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
Copy link
Owner

@kernc kernc left a 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):
Copy link
Owner

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).

Comment on lines +873 to +875
open_price = data.current_value("Open")
high_price = data.current_value("High")
low_price = data.current_value("Low")
Copy link
Owner

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
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants