| Overall Statistics |
|
Total Orders 222 Average Win 0.47% Average Loss -0.61% Compounding Annual Return -10.220% Drawdown 7.000% Expectancy -0.060 Start Equity 100000 End Equity 95620.37 Net Profit -4.380% Sharpe Ratio -0.584 Sortino Ratio -0.518 Probabilistic Sharpe Ratio 10.679% Loss Rate 47% Win Rate 53% Profit-Loss Ratio 0.77 Alpha -0.141 Beta 0.323 Annual Standard Deviation 0.117 Annual Variance 0.014 Information Ratio -2.154 Tracking Error 0.136 Treynor Ratio -0.211 Total Fees $854.74 Estimated Strategy Capacity $12000000.00 Lowest Capacity Asset AAPL R735QTJ8XC9X Portfolio Turnover 145.65% |
from AlgorithmImports import *
from QuantConnect.DataSource 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) -> 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.benzinga_symbol = self.add_data(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 on_data(self, slice: Slice) -> None:
if slice.contains_key(self.benzinga_symbol):
# Assign a sentiment score to the news article
content_words = slice[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 (slice.contains_key(self.aapl) and slice[self.aapl] is not None and not slice[self.aapl].is_fill_forward):
return
# Buy or sell if the sentiment has changed from our current holdings
if self.current_holdings != self.target_holdings:
self.set_holdings(self.aapl, self.target_holdings)
self.current_holdings = self.target_holdings