Overall Statistics |
Total Trades 33 Average Win 1.49% Average Loss -0.44% Compounding Annual Return 36.569% Drawdown 4.000% Expectancy 0.373 Net Profit 2.584% Sharpe Ratio 2.049 Loss Rate 69% Win Rate 31% Profit-Loss Ratio 3.39 Alpha 0.31 Beta -0.039 Annual Standard Deviation 0.155 Annual Variance 0.024 Information Ratio 2.239 Tracking Error 0.227 Treynor Ratio -8.075 Total Fees $42.71 |
using System; using System.Collections.Generic; using System.Linq; using QuantConnect.Data.Market; using QuantConnect.Data.UniverseSelection; using System.Globalization; using System.Text; using System.Threading.Tasks; using QuantConnect.Data; using QuantConnect.Data.Consolidators; namespace QuantConnect.Algorithm.CSharp { // In this algorithm we show how you can easily define a // universe using our coarse selection data. This data includes // a few properties, including the daily DollarVolume, the daily Volume // and also the daily closing price via the Value property. public class CoarseFundamentalTop5Algorithm : QCAlgorithm { // initialize our security changes to nothing SecurityChanges _changes = SecurityChanges.None; TradeBar open; // we'll set the close at the end of each day TradeBar close; public override void Initialize() { // this sets the resolution for securities added via universe selection UniverseSettings.Resolution = Resolution.Minute; SetStartDate(2015, 1, 1); SetEndDate(2015, 2, 1); SetCash(5000); // this add universe method accepts a single parameter that is a function that // accepts an IEnumerable<CoarseFundamental> and returns IEnumerable<Symbol> AddUniverse(CoarseSelectionFunction); } // sort the data by daily dollar volume and take the top 5 symbols public static IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse) { // sort descending by daily dollar volume var sortedByDollarVolume = coarse.OrderBy(x => x.Price); // take the top 5 entries from our sorted collection //var top5 = sortedByDollarVolume.Take(1); // we need to return only the symbols //return top5.Select(x => x.Symbol); return (from stock in coarse orderby stock.Price descending where stock.Price < 5 select stock.Symbol).Take(1); } //Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol. public void OnData(TradeBars data) { // 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 25% allocation in each security in our universe (total of 150% invested) foreach (var security in _changes.AddedSecurities) { SetHoldings(security.Symbol, 0.25m); Log("BUY >> " + security.Symbol + " " + security.Price); } // reset our changes _changes = SecurityChanges.None; } // this event fires whenever we have changes to our universe public override void OnSecuritiesChanged(SecurityChanges changes) { _changes = changes; } } }