In this PR we are disabling the default security seeding (automatically getting the last price for a security when added to the algorithm) for a couple reasons, both when using large universes:
- In live trading, these history requests are sent to a history server, potentially causing timeouts
- In backtesting, depending on the algorithm this could also cause slowdowns up to 30%
This algorithm serves as an example for the SetSecurityInilializer for python feature
The date range for the C# version is changed to match existing data
Currently, calling SetBrokerageModel after AddSecurity, AddForex, etc. has no effect, the security initializer has already been initialized and its models have been set to their default implementations.
For example, Forex backtests using OandaBrokerageModel will report fees calculated with the default fee model (Oanda fees are spread-based, so they should always be reported as zero).
In this PR, SetBrokerageModel now calls SecurityInitializer.Initialize on all securities added before SetBrokerageModel is called.
Fees will be calculated using the correct fee models and the order of the calls in algorithm Initialize is now irrelevant.
FuncSecuritySeeder implements this new interface and is used in BrokerageModelSecurityInitializer to seed new securities with a price when they are created. FuncSecuritySeeder uses a new method, GetSingleBarHistory, in QCAlgorithm.History to get the last price from the history provider.
An ISecurityInitializer implementation will be run after calls to AddSecurity.
A custom implementation can be specified by calling SetSecurityInitializer(...).
The default implementation sets the fill/fee/slippage/settlement models based off the BrokerageModel.