Skip to content
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

modified the CustomAlgorithm._data_updated() #30

Open
temph2020 opened this issue Oct 4, 2024 · 1 comment
Open

modified the CustomAlgorithm._data_updated() #30

temph2020 opened this issue Oct 4, 2024 · 1 comment

Comments

@temph2020
Copy link

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]
@Heerozh
Copy link
Owner

Heerozh commented Oct 4, 2024

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.

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

No branches or pull requests

2 participants