Overall Statistics |
Total Orders 449 Average Win 1.26% Average Loss -0.64% Compounding Annual Return 209.076% Drawdown 30.600% Expectancy 0.556 Net Profit 75.511% Sharpe Ratio 2.383 Sortino Ratio 3.527 Probabilistic Sharpe Ratio 64.189% Loss Rate 47% Win Rate 53% Profit-Loss Ratio 1.95 Alpha 2.143 Beta -1.261 Annual Standard Deviation 0.776 Annual Variance 0.602 Information Ratio 2.01 Tracking Error 0.804 Treynor Ratio -1.467 Total Fees $723.37 Estimated Strategy Capacity $40000000.00 Lowest Capacity Asset MEDS XC03HZ3KX3L1 Portfolio Turnover 24.51% |
#region imports using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.Drawing; using QuantConnect; 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 { public class MorningStarDataAlgorithm : QCAlgorithm { private int _universeSize = 10; private SecurityChanges _changes = SecurityChanges.None; public override void Initialize() { SetStartDate(2021, 1, 1); SetEndDate(2021, 7, 1); SetCash(100000); // Requesting data UniverseSettings.Resolution = Resolution.Daily; AddUniverse(FundamentalSelectionFunction); } public IEnumerable<Symbol> FundamentalSelectionFunction(IEnumerable<Fundamental> fundamental) { return fundamental .Where(x => x.HasFundamentalData && x.Price > 1 && !Double.IsNaN(x.ValuationRatios.PERatio)) .OrderByDescending(x => x.DollarVolume) .Take(100) .OrderByDescending(x => x.ValuationRatios.PERatio) .Take(_universeSize) .Select(x => x.Symbol); } public override void OnData(Slice slice) { // if we have no changes, do nothing if (_changes == SecurityChanges.None) return; // liquidate removed securities foreach (var security in _changes.RemovedSecurities) { if (security.Invested) { Liquidate(security.Symbol); } } // we want 1/N allocation in each security in our universe foreach (var security in _changes.AddedSecurities) { SetHoldings(security.Symbol, 1m / _universeSize); } _changes = SecurityChanges.None; } public override void OnSecuritiesChanged(SecurityChanges changes) { _changes = changes; foreach (var security in changes.AddedSecurities) { // Historical data var history = History(security.Symbol, 7, Resolution.Daily); Debug($"We got {history.Count()} from our history request for {security.Symbol}"); } } } }