Hi guys. I've been trying to implement an algorithm, but I've been getting this run time exception. I'm really new to QC and would really appreciate some help.

The error it was giving me was: Runtime Error: Object reference not set to an instance of an object.

class FrameworkAlgorithm(QCAlgorithm):

   def Initialize(self):
       self.SetStartDate(2019, 12, 30)
       self.SetEndDate(2020, 12, 30)
       self.SetCash(10000) 
       
       
       #1. Set the Universe Selection Model
       CustomUniverseSelectionModel = LiquidValueUniverseSelectionModel(self)
       
       self.AddUniverseSelection(
         FineFundamentalUniverseSelectionModel(CustomUniverseSelectionModel.SelectCoarse, CustomUniverseSelectionModel.SelectFine)
       )
       self.UniverseSettings.Resolution = Resolution.Hour
       
       self.AddUniverseSelection(NullUniverseSelectionModel())
       
       #2. Set the Alpha Model
       self.SetAlpha(LongShortEYAlphaModel())

       #3. Set the NullPortfolioConstructionModel()
       self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())

       #4. Set the NullRiskManagementModel()
       self.SetRiskManagement(NullRiskManagementModel())

       #5. Set the NullExecutionModel()
       self.SetExecution(ImmediateExecutionModel())

class LongShortEYAlphaModel(AlphaModel):
   
   def __init__(self):
       self.lastMonth = -1
   
   def Update(self, algorithm, data):
       insights = []
       
       if (self.lastMonth == algorithm.Time.month):
           return
       self.lastMonth = algorithm.Time.month
       
       for security in algorithm.ActiveSecurities.Values:
           direction = 1 if security.Fundamentals.ValuationRatios.EarningYield > 0 else -1 
           insights.append(Insight.Price(security.Symbol, timedelta(28), direction))
           
       return Insight.Group(insights)


class LiquidValueUniverseSelectionModel():
   
   def __init__(self, algorithm):
       self.algorithm = algorithm
       self.lastMonth = -1

   def SelectCoarse(self, coarse):
       #1. If it isn't time to update data, return the previous symbols 
       if self.lastMonth == self.algorithm.Time.month:
           return Universe.Unchanged
       #2. Update self.lastMonth with current month to make sure only process once per month
       self.lastMonth = self.algorithm.Time.month
       
       #3. Sort symbols by dollar volume and if they have fundamental data, in descending order
       sortedByDollarVolume = sorted([x for x in coarse if x.HasFundamentalData],
           key=lambda x: x.DollarVolume, reverse=True)

       
       #4. Return the top 100 Symbols by Dollar Volume 
       return [x.Symbol for x in sortedByDollarVolume[:100]]
   
   def SelectFine(self, fine):
       sortedByYields = sorted(fine, key=lambda f: f.ValuationRatios.EarningYield, reverse=True)
       
       self.universe = sortedByYields[:10] + sortedByYields[-10:]
       
       

       return [f.Symbol for f in self.universe]
   

 

 

 

Author