Overall Statistics |
Total Trades 59 Average Win 1.79% Average Loss -1.32% Compounding Annual Return 19.082% Drawdown 6.300% Expectancy 0.542 Net Profit 20.674% Sharpe Ratio 1.509 Probabilistic Sharpe Ratio 73.148% Loss Rate 34% Win Rate 66% Profit-Loss Ratio 1.35 Alpha 0.002 Beta 0.647 Annual Standard Deviation 0.082 Annual Variance 0.007 Information Ratio -1.076 Tracking Error 0.061 Treynor Ratio 0.192 Total Fees $1131.10 |
from QuantConnect.Data.Custom.Tiingo import * from datetime import datetime, timedelta import numpy as np class TiingoNS(QCAlgorithm): def Initialize(self): self.SetStartDate(2019, 1, 1) #self.SetEndDate(2015, 11, 1) symbols = [ Symbol.Create("SPY",SecurityType.Equity, Market.USA),#on ] self.SetUniverseSelection(ManualUniverseSelectionModel(symbols)) self.SetAlpha(NewsSentimentAlphaModel()) self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel()) self.SetExecution(ImmediateExecutionModel()) self.SetRiskManagement(NullRiskManagementModel()) self.SetBrokerageModel(BrokerageName.AlphaStreams) self.SetCash(1000000) class NewsData(): def __init__(self, symbol): self.Symbol = symbol self.Window = RollingWindow[float](100) class NewsSentimentAlphaModel(AlphaModel): def __init__(self): self.newsData = {} self.wordScores = { "over":1, #1 } self.overnightInsights = [] def Update(self, algorithm, data): insights = [] news = data.Get(TiingoNews) for article in news.Values: words = article.Description.lower().split(" ") score = sum([self.wordScores[word] for word in words if word in self.wordScores]) symbol = article.Symbol.Underlying self.newsData[symbol].Window.Add(score) sentiment = sum(self.newsData[symbol].Window) if sentiment > 3: insight = Insight.Price(symbol, timedelta(1), InsightDirection.Up) if algorithm.IsMarketOpen("SPY"): insights.append(insight) if len(self.overnightInsights) != 0: insights.extend(self.overnightInsights) self.overnightInsights = [] else: self.overnightInsights.append(insight) return insights def OnSecuritiesChanged(self, algorithm, changes): for security in changes.AddedSecurities: symbol = security.Symbol newsAsset = algorithm.AddData(TiingoNews, symbol) self.newsData[symbol] = NewsData(newsAsset.Symbol) for security in changes.RemovedSecurities: newsData = self.newsData.pop(security.Symbol, None) if newsData is not None: algorithm.RemoveSecurity(newsData.Symbol)