Overall Statistics
Total Orders
319
Average Win
1.15%
Average Loss
-1.19%
Compounding Annual Return
-9.937%
Drawdown
38.500%
Expectancy
-0.035
Start Equity
100000
End Equity
83981.84
Net Profit
-16.018%
Sharpe Ratio
-0.459
Sortino Ratio
-0.593
Probabilistic Sharpe Ratio
3.047%
Loss Rate
51%
Win Rate
49%
Profit-Loss Ratio
0.97
Alpha
-0.059
Beta
-0.715
Annual Standard Deviation
0.22
Annual Variance
0.049
Information Ratio
-0.512
Tracking Error
0.313
Treynor Ratio
0.141
Total Fees
$1572.83
Estimated Strategy Capacity
$12000000.00
Lowest Capacity Asset
AAPL R735QTJ8XC9X
Portfolio Turnover
104.35%
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(2023, 9, 1)
        self.set_end_date(2025, 5, 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