I am learning to use the “Algorithm Framework” where I found an example of creating symbols to create a manual universe selection model from the documentation.
Now I am trying to create a custom data source using a pre-saved CSV file, and below is the main algorithm initialise method:
def Initialize(self):
self.SetStartDate(2018, 7, 1)
self.SetEndDate(2019, 3, 31)
self.SetCash(100000)
self.UniverseSettings.Resolution = Resolution.Daily
self.UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw
# -------------------- to use Custom Data class ----------------------
self.symbols: List[Symbol] = []
symbol_str: List[str] = ["GLD", "GDX"]
for sym in symbol_str:
# Manual universes doesn't work with custom data
# See https://github.com/QuantConnect/Lean/blob/master/Algorithm/Selection/ManualUniverseSelectionModel.py
self.symbols.append(self.AddData(MyCustomDataClass, ticker=sym, resolution=self.UniverseSettings.Resolution).Symbol)
# TODO Set Benchmark
# self.SetBenchmark(self.symbol)
self.AddUniverseSelection(ManualUniverseSelectionModel(self.symbols))
It turns out that in the Alpha Model, in OnSecuritiesChanged, the changes.AddedSecurities is an empty list.
However, if I use the “classic style” algorithm using self.AddData method, I can see the added securities.
Here are my two questions:
- Does ManualUniverseSelectionModel support custom data symbols?
2. If not, how can I write a custom ManualUniverseSelectionModel to achieve the same result as using self.AddData(CustomDataClass, <name>, resolution). (And is it even worth it)?
Alexandre Catarino
Hi Bella Yousefi ,
The OnSecuritesChanged method does not receive events of addition or removal of custom data.
I don't think you should write a custom selection model for custom data. Generally, custom data is used to create insights, so we can add them directly to the Alpha Model:
However, if the custom data is market data as it seems in your case, it's not worth creating a Selection Model.
Best regards,
Alex
Bella Yousefi
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!