Overall Statistics |
Total Trades 222 Average Win 0.47% Average Loss -0.61% Compounding Annual Return -10.200% Drawdown 7.000% Expectancy -0.060 Net Profit -4.371% Sharpe Ratio -0.562 Probabilistic Sharpe Ratio 10.697% Loss Rate 47% Win Rate 53% Profit-Loss Ratio 0.77 Alpha -0.139 Beta 0.323 Annual Standard Deviation 0.117 Annual Variance 0.014 Information Ratio -2.153 Tracking Error 0.136 Treynor Ratio -0.203 Total Fees $845.24 Estimated Strategy Capacity $12000000.00 Lowest Capacity Asset AAPL R735QTJ8XC9X |
from AlgorithmImports import * class BenzingaNewsDataAlgorithm(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): self.SetStartDate(2021, 1, 1) self.SetEndDate(2021, 6, 1) self.SetCash(100000) # Requesting data self.aapl = self.AddEquity("AAPL", Resolution.Minute).Symbol self.benzinga_symbol = self.AddData(BenzingaNews, self.aapl).Symbol # Historical data history = self.History(self.benzinga_symbol, 14, Resolution.Daily) self.Debug(f"We got {len(history)} items from our history request") def OnData(self, data): if data.ContainsKey(self.benzinga_symbol): # Assign a sentiment score to the news article content_words = data[self.benzinga_symbol].Contents.lower() score = 0 for word, word_score in self.word_scores.items(): score += (content_words.count(word) * word_score) self.target_holdings = int(score > 0) # Ensure we have AAPL data in the current Slice if not (data.ContainsKey(self.aapl) and data[self.aapl] is not None and not data[self.aapl].IsFillForward): return # Buy or sell if the sentiment has changed from our current holdings if self.current_holdings != self.target_holdings: self.SetHoldings(self.aapl, self.target_holdings) self.current_holdings = self.target_holdings