Overall Statistics |
Total Trades 10 Average Win 1.43% Average Loss 0% Compounding Annual Return 11.870% Drawdown 4.800% Expectancy 0 Net Profit 12.525% Sharpe Ratio 1.55 Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.071 Beta 0.26 Annual Standard Deviation 0.061 Annual Variance 0.004 Information Ratio 0.041 Tracking Error 0.101 Treynor Ratio 0.362 Total Fees $11.53 |
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 int month = -1; private const int NumberOfSymbolsCoarse = 5; // initialize our changes to nothing private SecurityChanges _changes = SecurityChanges.None; public override void Initialize() { UniverseSettings.Resolution = Resolution.Daily; SetStartDate(2016, 01, 01); AddUniverse(CoarseSelectionFunction); } public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse) { if( Time.Month % 3 != 0 || Time.Month == month) { return Universe.Unchanged; } month = Time.Month; var sortedByDollarVolume = coarse .Where(x => x.HasFundamentalData) .OrderByDescending(x => x.DollarVolume); // take the top entries from our sorted collection var top5 = sortedByDollarVolume.Take(NumberOfSymbolsCoarse); // we need to return only the symbol objects return top5.Select(x => x.Symbol); } public void OnData(TradeBars data) { // if we have no changes, do nothing 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; } public override void OnSecuritiesChanged(SecurityChanges changes) { _changes = changes; } } }