-
Notifications
You must be signed in to change notification settings - Fork 130
Description
I’ve modified the CustomAlgorithm._data_updated() method to prevent recalculating the factors each time. Instead, it now extracts the required period’s factor data from the already obtained full-period factor data. The full-period factor data has already been calculated in SimulationEventManager.run_simulation_alg(). Does this approach seem reasonable, and are there any potential side effects?
Here are my modifications:
1 In SimulationEventManager.run_simulation_alg(), I store the full-period factor data in the algorithm’s factor_all attribute (which I added to the algorithm class) as follows:
data, _ = run_engine(start, end, delay_factor) # Obtain the full-period factor data starting from 'start'
alg.factor_all = data # I add this line
2 In CustomAlgorithm._data_updated(), instead of running run_engine each time to calculate the factors, I extract the required period’s factor data from factor_all. This improves performance.
def _data_updated(self, event_source=None):
# self._data, self._last_row = self.run_engine(None, None) # Original code
# The following is my code
start = self._current_dt - self._history_window
end = self._current_dt
# Extract records from self.factor_all for the period from 'start' to 'end'
self._data = self.factor_all.loc[start:end]
self._last_row = self._data.loc[end]