Overall Statistics
class TransdimensionalHorizontalAtmosphericScrubbers(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2005, 1, 1)  
        self.SetCash(100000)  
        
        
        self.UniverseSettings.Resolution = Resolution.Daily
        symbols = [Symbol.Create("MCD", SecurityType.Equity, Market.USA)]
        self.AddUniverseSelection(ManualUniverseSelectionModel(symbols))
        
        self.AddAlpha(UnemploymentRateAlpha(self))
        
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())
        self.AddRiskManagement(NullRiskManagementModel())
    

    def OnData(self, data):
       pass
   
# Algorithm framework model that produces insightsa
class UnemploymentRateAlpha:
    
    def __init__(self, algorithm):
        self.rate = algorithm.AddData(UNRATE, "UNRATE", Resolution.Daily, None, False, 1).Symbol 
        unemployment_history = algorithm.History([self.rate], timedelta(35))
        unemployment_numbers = unemployment_history.loc[self.rate].value.dropna() 
        self.lastRate = unemployment_numbers.values[0]

    def Update(self, algorithm, slice):
        insights = []
        
        if not slice.ContainsKey(self.rate):
            return []
        
        if slice[self.rate].Value < self.lastRate:
            insights.append( Insight.Price("MCD", timedelta(days=22), InsightDirection.Up) )
        
        self.lastRate = slice[self.rate].Value
        
        return insights

    def OnSecuritiesChanged(self, algorithm, changes):
        pass
    
class UNRATE(PythonData):
    
    def GetSource(self, config, date, isLiveMode):
        return SubscriptionDataSource('https://raw.githubusercontent.com/shilewenuw/FileHost/master/UNRATE.csv', SubscriptionTransportMedium.RemoteFile)

    def Reader(self, config, line, date, isLiveMode):
        if not (line.strip() and line[0].isdigit()): return None
        rate = UNRATE()
        rate.Symbol = config.Symbol 
        data = line.split(',')
        rate.Time = datetime.strptime(data[0], "%Y-%m-%d") + timedelta(days=31)
        rate.Value = data[1]
        return rate