Overall Statistics |
Total Orders 222 Average Win 0.47% Average Loss -0.61% Compounding Annual Return -10.220% Drawdown 7.000% Expectancy -0.060 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% |
#region imports using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.Drawing; using QuantConnect; using System.Text.RegularExpressions; using QuantConnect.Algorithm.Framework; using QuantConnect.Algorithm.Framework.Selection; using QuantConnect.Algorithm.Framework.Alphas; using QuantConnect.Algorithm.Framework.Portfolio; using QuantConnect.Algorithm.Framework.Execution; using QuantConnect.Algorithm.Framework.Risk; using QuantConnect.Algorithm.Selection; using QuantConnect.Parameters; using QuantConnect.Benchmarks; using QuantConnect.Brokerages; using QuantConnect.Util; using QuantConnect.Interfaces; using QuantConnect.Algorithm; using QuantConnect.Indicators; using QuantConnect.Data; using QuantConnect.Data.Consolidators; using QuantConnect.Data.Custom; using QuantConnect.DataSource; using QuantConnect.Data.Fundamental; using QuantConnect.Data.Market; using QuantConnect.Data.UniverseSelection; using QuantConnect.Notifications; using QuantConnect.Orders; using QuantConnect.Orders.Fees; using QuantConnect.Orders.Fills; using QuantConnect.Orders.Slippage; using QuantConnect.Scheduling; using QuantConnect.Securities; using QuantConnect.Securities.Equity; using QuantConnect.Securities.Future; using QuantConnect.Securities.Option; using QuantConnect.Securities.Forex; using QuantConnect.Securities.Crypto; using QuantConnect.Securities.Interfaces; using QuantConnect.Storage; using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm; using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm; #endregion using QuantConnect.DataSource; namespace QuantConnect.Algorithm.CSharp.AltData { public class BenzingaNewsDataAlgorithm : QCAlgorithm { private Symbol _aapl; private Symbol _benzingaSymbol; private int _currentHoldings = 0; private int _targetHoldings = 0; private Dictionary<string, int> _wordScores = new Dictionary<string, int>(){ {"good", 1}, {"great", 1}, {"best", 1}, {"growth", 1}, {"bad", -1}, {"terrible", -1}, {"worst", -1}, {"loss", -1} }; public override void Initialize() { SetStartDate(2021, 1, 1); SetEndDate(2021, 6, 1); SetCash(100000); // Requesting data _aapl = AddEquity("AAPL", Resolution.Minute).Symbol; _benzingaSymbol = AddData<BenzingaNews>(_aapl).Symbol; // Historical data var history = History<BenzingaNews>(_benzingaSymbol, 14, Resolution.Daily); Debug($"We got {history.Count()} items from our history request"); } public override void OnData(Slice slice) { if (slice.ContainsKey(_benzingaSymbol)) { // Assign a sentiment score to the news article var contentWords = slice[_benzingaSymbol].Contents.ToLower(); var score = 0; foreach (KeyValuePair<string, int> entry in _wordScores) { score += (Regex.Matches(contentWords, entry.Key).Count * entry.Value); } _targetHoldings = Convert.ToInt32(score > 0); } // Ensure we have AAPL data in the current Slice if (!(slice.ContainsKey(_aapl) && slice[_aapl] != null && !slice[_aapl].IsFillForward)) { return; } // Buy or sell if the sentiment has changed from our current holdings if (_currentHoldings != _targetHoldings) { SetHoldings(_aapl, _targetHoldings); _currentHoldings = _targetHoldings; } } } }