QuantConnect / Documentation

QuantConnect Wiki Style Documentation Behind QuantConnect
https://www.quantconnect.com/docs/v2/
Apache License 2.0
173 stars 139 forks source link

Custom Security Data #1481

Closed AlexCatarino closed 1 year ago

AlexCatarino commented 1 year ago

Expected Behavior

Security > Key Concepts introduces the concept of custom data.

You can add properties (C# terminology) / attributes (Python terminology) to the Security object. For example, you can add an exponential moving average (link to indicator docs):

equity = self.AddEquity("SPY")
equity.ema = self.EMA("SPY", 10, Resolution.Daily)

This feature is helpful because you can find the Security object with the Securities object

spy_ema = self.Securities["SPY"].Current.Value

In Universe > Key Concepts, we should change the order to

In Security Custom Properties, we can use the existing text and code snippet:

If you need to save data or create objects for each security in the universe, add custom members to the respective Security objects. This technique is useful if you want to track stop loss levels or add indicators for each asset in the universe.

def OnSecuritiesChanged(self, changes: SecurityChanges) -> None:
    for security in changes.AddedSecurities:
        # Create an indicator
        security.indicator = self.SMA(security.Symbol, 10)

        # Warm up the indicator
        self.WarmUpIndicator(security.Symbol, security.indicator)

    for security in changes.RemovedSecurities:
        self.DeregisterIndicator(security.indicator)

Also, we need to review all Symbol Data pattern and note that we should use it when there is no Security object yet. For example in Example 2.

Actual Behavior

This information is not highlighted.

Checklist