| Overall Statistics |
|
Total Orders 127 Average Win 0.91% Average Loss -0.90% Compounding Annual Return -2.626% Drawdown 11.800% Expectancy 0.019 Start Equity 100000 End Equity 98898.47 Net Profit -1.102% Sharpe Ratio 0.02 Sortino Ratio 0.026 Probabilistic Sharpe Ratio 22.738% Loss Rate 49% Win Rate 51% Profit-Loss Ratio 1.01 Alpha -0.229 Beta 1.035 Annual Standard Deviation 0.227 Annual Variance 0.051 Information Ratio -1.156 Tracking Error 0.191 Treynor Ratio 0.004 Total Fees $1006.92 Estimated Strategy Capacity $21000000.00 Lowest Capacity Asset AAPL R735QTJ8XC9X Portfolio Turnover 165.92% |
from AlgorithmImports import *
from QuantConnect.DataSource import *
class TiingoNewsDataAlgorithm(QCAlgorithm):
current_holdings = 0
target_holdings = 0
word_scores = {'good': 1, 'great': 1, 'best': 1, 'growth': 1,
'bad': -1, 'terrible': -1, 'worst': -1, 'loss': -1}
def initialize(self) -> None:
self.set_start_date(2021, 1, 1)
self.set_end_date(2021, 6, 1)
self.set_cash(100000)
# Requesting data
self.aapl = self.add_equity("AAPL", Resolution.MINUTE).symbol
self.tiingo_symbol = self.add_data(TiingoNews, self.aapl).symbol
# Historical data
history = self.history(self.tiingo_symbol, 14, Resolution.DAILY)
self.debug(f"We got {len(history)} items from our history request")
def on_data(self, slice: Slice) -> None:
if slice.contains_key(self.tiingo_symbol):
# Assign a sentiment score to the news article
title_words = slice[self.tiingo_symbol].description.lower()
score = 0
for word, word_score in self.word_scores.items():
if word in title_words:
score += word_score
if score > 0:
self.target_holdings = 1
elif score < 0:
self.target_holdings = -1
# Buy or short sell if the sentiment has changed from our current holdings
if slice.contains_key(self.aapl) and self.current_holdings != self.target_holdings:
self.set_holdings(self.aapl, self.target_holdings)
self.current_holdings = self.target_holdings