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

class TiingoNLPDemonstration(QCAlgorithm):

    def Initialize(self):
        self.wordSentiment = {
            "bad": -0.5, "good": 0.5,
            "negative": -0.5, "great": 0.5,
            "growth": 0.5, "fail": -0.5, 
            "failed": -0.5, "success": 0.5, "nailed": 0.5,
            "beat": 0.5, "missed": -0.5,
        }
        
        self.SetStartDate(2019, 4, 1) 
        self.SetCash(100000)
        
        aapl = self.AddEquity("AAPL", Resolution.Hour).Symbol
        self.aaplCustom = self.AddData(TiingoNews, aapl).Symbol
        
    def OnData(self, data):
        if not data.ContainsKey(self.aaplCustom):
            return
        
        news = data[self.aaplCustom]
        
        descriptionWords = news.Description.lower().split(" ")
        intersection = set(self.wordSentiment.keys()).intersection(descriptionWords)
        sentimentSum = sum([self.wordSentiment[i] for i in intersection])
        
        self.SetHoldings(self.aaplCustom.Underlying, sentimentSum)