Hi all,

I've been trying to build an alpha model using an sklearn ML model, and I'm wondering about the best way to do so. In order to make the model itself accessible from the algorithm's Train() function, both the model and a related max training price dictionary are attributes of the algorithm object. When I try to access this dictionary from the alpha model as below, however, I get the error ‘QCAlgorithm object has no attribute “max_train_price”’:

# within the alpha model
def Update(self, algorithm, data):


        insights = []
        for security in algorithm.ActiveSecurities.Values:
            symbol = security.Symbol
          
            if data.ContainsKey(symbol) and data[symbol] is not None:
                
                # this is the issue: algorithm.max_train_price[symbol] throws an error
                if (data[symbol].Close < algorithm.max_train_price[symbol] 
                    and data[symbol].Close > algorithm.min_train_price[symbol]):
                    
                    # do other stuff

Am I structuring things wrong? It seems like any ML models and associated objects have to be a part of the algorithm object, since they need to be accessible by the Train() function, but it also seems like attributes of the algorithm aren't accessible from the alpha model (unless I messed something else up).

It's worth mentioning that I do define max_train_price in the algorithm's Initialize() function, before I add the alpha model, so it's not that my algorithm object doesn't actually have that attribute.

I appreciate any feedback! Let me know if this is too vague or if there's anything I can clarify.

Author