Hi Community.
QuantConnect's Quant Team has been discussing algorithm design patterns to help members develop their algorithms. We use the SymbolData pattern to hold information (state, indicators, custom methods, etc) from a Symbol/Security in a multi-security algorithm (manual or dynamic universe). It follows the QCAlgorithm.Securities and QCAlgorithm.Portfolio pattern: dictionaries of a user-defined type keyed QuantConnect.Symbol. It's normally used in Alpha Models (e.g. RsiAlphaModel.cs, RsiAlphaModel.py), but it could be used in non-Framework algorithms too.
Create the SymbolData class with the desired variables (state, indicators, etc)
2. The SymbolData class should have at least two methods: Update(Slice), Dispose()
a. Update will receive a Slice object to update the class variable
b. Dispose will unsubscribe consolidators
3. The SymbolData class constructor should receive the following arguments: QCAlgorithm, Security
a. QCAlgorithm to access its methods, e.g. SubscriptionManager, EMA, RSI, etcb. Security to access the Symbol, Mapped (for futures), SymbolProperties, etc...
4. In the main/algorithm class, create a Dictionary of SymbolData keyed by Symbol: SymbolDataBySymbol
a. Let's key the dict by Symbol, not Security, to follow the QCAlgorithm.Securities and QCAlgorithm.Portfolio pattern.
5. Populate the dictionary in Initialize or OnSecuritiesChanged when a new Security is added to the universe
6. In OnData, iterate the dictionary and pass the Slice object to the SymbolData.Update(Slice) method
7. We may want to keep the trading methods, since we may want to use SetHoldings(List<PortfolioTarget>).
a. If we have multiple securities:
- Manage Alpha Signaling/Entry Exit in Symbol Data
b. If multiple trades per security
- Manage a Trade Collection in Symbol Data too.
We believe we can make it easier by adding some “sugar” in QuantConnect/Lean. For example, attaching the custom properties to the Security object to eliminate the user-defined class dictionary. We have opened a GitHub issue for the feature: On Security Cache Concept #6809
Please let us know your opinion.
Best regards,
Alex
Alexandre Catarino
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!