Overall Statistics |
Total Orders 118 Average Win 0.99% Average Loss -0.81% Compounding Annual Return 45.365% Drawdown 10.600% Expectancy 0.237 Start Equity 100000 End Equity 124520.40 Net Profit 24.520% Sharpe Ratio 1.542 Sortino Ratio 1.881 Probabilistic Sharpe Ratio 71.216% Loss Rate 44% Win Rate 56% Profit-Loss Ratio 1.23 Alpha 0.372 Beta -0.7 Annual Standard Deviation 0.171 Annual Variance 0.029 Information Ratio 0.486 Tracking Error 0.227 Treynor Ratio -0.378 Total Fees $682.94 Estimated Strategy Capacity $7200000.00 Lowest Capacity Asset AAPL R735QTJ8XC9X Portfolio Turnover 109.33% |
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(2024, 4, 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