Heerozh / spectre

GPU-accelerated Factors analysis library and Backtester
GNU General Public License v3.0
647 stars 108 forks source link

modified the CustomAlgorithm._data_updated() #30

Open temph2020 opened 1 month ago

temph2020 commented 1 month ago

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 factorall 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]
Heerozh commented 1 month ago

fixed factor should add to DataLoader, there is no reason to add pre-calculated data during the calculation stage.

I guess you want to fine-tune the backtest parameters on last factor, but you should use various statistical tools to evaluate the factors, instead of backtest. we only perform backtesting before real trading.

this involves too much basic knowledge, and I am not going to answer any more of this.