Overall Statistics |
Total Trades 22 Average Win 0.42% Average Loss -0.25% Compounding Annual Return -15.691% Drawdown 5.900% Expectancy -0.326 Net Profit -1.393% Sharpe Ratio -0.703 Loss Rate 75% Win Rate 25% Profit-Loss Ratio 1.70 Alpha -0.221 Beta 1.273 Annual Standard Deviation 0.173 Annual Variance 0.03 Information Ratio -2.124 Tracking Error 0.094 Treynor Ratio -0.095 Total Fees $22.34 |
using System.Collections.Generic; using System.Linq; using QuantConnect.Data.Fundamental; using QuantConnect.Data.Market; using QuantConnect.Data.UniverseSelection; namespace QuantConnect.Algorithm.CSharp { public class CoarseFineFundamentalComboAlgorithm : QCAlgorithm { private const int NumberOfSymbolsCoarse = 20; private const int NumberOfSymbolsFine = 10; private SecurityChanges _changes = SecurityChanges.None; public override void Initialize() { UniverseSettings.Resolution = Resolution.Daily; SetStartDate(2014, 04, 01); SetEndDate(2014, 04, 30); SetCash(50000); // this add universe method accepts two parameters: // - coarse selection function: accepts an IEnumerable<CoarseFundamental> and returns an IEnumerable<Symbol> // - fine selection function: accepts an IEnumerable<FineFundamental> and returns an IEnumerable<Symbol> AddUniverse(CoarseSelectionFunction, FineSelectionFunction); } public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse) { var sortedByDollarVolume = coarse .Where(x => x.HasFundamentalData) .OrderByDescending(x => x.DollarVolume); var top5 = sortedByDollarVolume.Take(NumberOfSymbolsCoarse); return top5.Select(x => x.Symbol); } public IEnumerable<Symbol> FineSelectionFunction(IEnumerable<FineFundamental> fine) { var candidates = fine.Where(x => Time > x.EarningReports.FileDate.AddDays(7) && // Within 7 days x.EarningReports.FileDate != new DateTime()) // Invalid FileDate .Take(NumberOfSymbolsFine); foreach(var candidate in candidates) { Log(Time +" > " + candidate.Symbol + "Earning Report File Data: " + candidate.EarningReports.FileDate); } return candidates.Select(x => x.Symbol); } public void OnData(TradeBars data) { if (_changes == SecurityChanges.None) return; foreach (var security in _changes.RemovedSecurities) { if (security.Invested) { Liquidate(security.Symbol); Debug("Liquidated Stock: " + security.Symbol.Value); } } foreach (var security in _changes.AddedSecurities) { SetHoldings(security.Symbol, 0.1m); Debug("Purchased Stock: " + security.Symbol.Value); } _changes = SecurityChanges.None; } // this event fires whenever we have changes to our universe public override void OnSecuritiesChanged(SecurityChanges changes) { _changes = changes; if (changes.AddedSecurities.Count > 0) { Debug("Securities added: " + string.Join(",", changes.AddedSecurities.Select(x => x.Symbol.Value))); } if (changes.RemovedSecurities.Count > 0) { Debug("Securities removed: " + string.Join(",", changes.RemovedSecurities.Select(x => x.Symbol.Value))); } } } }