When developing a trading algorithm, it may be the case where we have trained/built a particular model for a financial instrument and want to apply it on other financial sectors/markets. For such case, re-using a pre-trained model for strategy backtests could largely reduce the time in repeated model calibration process. However, if we handle it inproperly, it is likely for us to fall into the trap of "Look Ahead Bias"!
What is "Look Ahead Bias"?
Look-ahead bias refers to making trade decisions based on data/information that would only be available in the future.
For backtesting, it is crucial that we only use information that would have been available at the time of the trade. For example, using a yearly earnings figure that would be released a quarter later will potentially bias the results in favor of the desired outcome. The accuracy of this strategy performance is also doubtful.
Here are some considerations for identifying a potential look-ahead bias.
- When was the data released?
- At what time the data observable and available to us?
Load/Dump model on ALGOGENE Web IDE
As an event streaming backtest enginee, ALGOGENE primarily eliminated the look-ahead bias where data feed into our strategy script according to chronological order, as if replaying a recorder. On the other hand, ALGOGENE provides feasibility to save and re-use customized models for backtesting on the Web IDE. Such feasibility, however, might expose us to potential look-ahead bias that we might inappropriately introduce. Thus, the questions above would be a guide to justify whether our re-used model is logically sound good.
Now, let's see how to load/dump a model on ALGOGENE IDE. Upon account registration on the platform, each user has automatically been assigned with a partition on ALGOGENE's cloud environment. All we need to do is simply to save the model to our assigned cloud directory (i.e. self.evt.path_lib), and then retrieve it for other backtest process. In the following example, it is presented how to implement programmatically, but it may not be logically sound good in terms of strategy backtesting.
Suppose we want to find out the mathematical relationship between 3 financial instruments, defined as Y = f(X1, X2). We based on 'keras' (https://www.tensorflow.org/guide/keras/save_and_serialize) library to derive the fitted model using the past 100 daily observations. In the first example below, we create 'model_1' directory and dump the results there. In the second example, 'model_1' is retrieved for another backtest.
Save a model refers to line #51
Load a model refers to line #24