Overall Statistics
from QuantConnect.Data.Custom.TradingEconomics import *

class VerticalResistanceShield(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2014, 1, 1)  # Set Start Date
        self.SetEndDate(2019, 8, 22)
        self.SetCash(100000)  # Set Strategy Cash
        
        self.interestRateSymbol = self.AddData(TradingEconomicsCalendar, TradingEconomics.Calendar.UnitedStates.InterestRate, Resolution.Daily, TimeZones.Utc).Symbol

        self.UniverseSettings.Resolution = Resolution.Daily;
        self.AddUniverseSelection(FineFundamentalUniverseSelectionModel(self.CoarseSelector, self.FineSelector))

        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        self.SetExecution(ImmediateExecutionModel())
        self.SetRiskManagement(MaximumSectorExposureRiskManagementModel())
        
    def CoarseSelector(self, coarse):
        return [i.Symbol for i in coarse if i.DollarVolume > 100000000 and i.DollarVolume < 1000000000]
    
    def FineSelector(self, fine):
        return [i.Symbol for i in fine]

    def OnData(self, data):
        insights = []
        
        if not data.ContainsKey(self.interestRateSymbol):
            return
        
        announcement = data[self.interestRateSymbol]
        
        if announcement.Event != "Fed Interest Rate Decision":
            self.Debug(f"Event is: {announcement.Event}")
            return
        
        interestRateActual = self.ParseTEData(announcement.Actual)
        interestRatePrevious = self.ParseTEData(announcement.Previous)
        
        interestRateDecreased = interestRateActual <= interestRatePrevious
        # Interest rate increases are generally seen as a sign of slowing economic growth after QE
        insightDirection = InsightDirection.Up if interestRateDecreased else InsightDirection.Down
        
        for kvp in self.ActiveSecurities:
            symbol = kvp.Key
            insights.append(Insight(symbol, timedelta(days=10), InsightType.Price, insightDirection))
                
        self.EmitInsights(insights)
    
    def ParseTEData(self, dataStr):
        inBillions = "B" in dataStr

        if inBillions:
            data = float(dataStr.replace("%", "").replace("B", "").replace("$", ""))
            data = forecast * 1000000000
        elif "M" in dataStr:
            data = float(dataStr.replace("%", "").replace("M", "").replace("$", ""))
            data = forecast * 1000000
        else:
            data = float(dataStr.replace("%", "").replace("$", ""))
            
        return data