Overall Statistics
Total Trades
28
Average Win
0.32%
Average Loss
-0.18%
Compounding Annual Return
1939.462%
Drawdown
1.500%
Expectancy
1.471
Net Profit
5.082%
Sharpe Ratio
11.365
Loss Rate
12%
Win Rate
88%
Profit-Loss Ratio
1.82
Alpha
1.285
Beta
59.411
Annual Standard Deviation
0.185
Annual Variance
0.034
Information Ratio
11.297
Tracking Error
0.185
Treynor Ratio
0.035
Total Fees
$45.30
// https://www.quantconnect.com/forum/discussion/918/feature-coarse-universe-selection

using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data.Market;
using QuantConnect.Data.UniverseSelection;

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;

		//Coarse region "Variables"
		private const decimal minPrice = 50;
		private const decimal maxPrice = 100;
		private const int numberOfSymbolsCoarse  = 15;
		
		private const decimal minVolume = 50000;
		private const decimal tpPercent = 1.01m;

        public override void Initialize()
        {
        	// this sets the resolution for securities added via universe selection
            UniverseSettings.Resolution = Resolution.Minute;

            SetStartDate(2018, 5, 6);
            SetEndDate(2018, 5, 12);
            SetCash(100000);

            // this add universe method accepts a single parameter that is a function that
            // accepts an IEnumerable<CoarseFundamental> and returns IEnumerable<Symbol>
            AddUniverse(coarse =>
            {
            	return (from stock in coarse
            			where stock.Price > minPrice
                        where stock.Price < maxPrice
              			where stock.Volume > minVolume
            			orderby stock.DollarVolume descending  
            			select stock.Symbol).Take(numberOfSymbolsCoarse);
            });

        }

        // 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.OrderByDescending(x => x.DollarVolume);
            // take the top 5 entries from our sorted collection
            var top5 = sortedByDollarVolume.Take(5);
            // we need to return only the symbols
            return top5.Select(x => x.Symbol);
        }

        //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);
            }
            
            // reset our changes
            _changes = SecurityChanges.None;
        }

        // this event fires whenever we have changes to our universe
        public override void OnSecuritiesChanged(SecurityChanges changes)
        {
            _changes = changes;
        }
    }
}