Overall Statistics
Total Trades
374
Average Win
1.07%
Average Loss
-0.97%
Compounding Annual Return
33.085%
Drawdown
38.500%
Expectancy
0.222
Net Profit
319.790%
Sharpe Ratio
1.143
Probabilistic Sharpe Ratio
49.416%
Loss Rate
42%
Win Rate
58%
Profit-Loss Ratio
1.10
Alpha
0.147
Beta
1.323
Annual Standard Deviation
0.275
Annual Variance
0.076
Information Ratio
1.137
Tracking Error
0.165
Treynor Ratio
0.238
Total Fees
$4033.24
//Copyright HardingSoftware.com 2020.
//Granted to the public domain.
//Use at your own risk.

namespace QuantConnect.Algorithm.CSharp
{
    public class SimpleVolume : QCAlgorithm
    {
		int TotalHighDollarVolumeStocks = 10;
		List<Symbol> StocksToHold;
		DateTime lastMonth;
		
        public override void Initialize()
        {
            SetStartDate(2015, 11, 19);
            SetCash(1000000);
			AddUniverse(CoarseSelectionFunction);
        }
        
        public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
        {
            StocksToHold = coarse
						.Where(x => x.HasFundamentalData)
						.OrderByDescending(x => x.DollarVolume)
						.Take(TotalHighDollarVolumeStocks)
            			.Select(x => x.Symbol)
            			.ToList();
            			
        	return StocksToHold;
        }
        
        public override void OnData(Slice data)
        {
			if (lastMonth.Month == data.Time.Month)
			{
				return;
			}
			lastMonth = data.Time;
			
			foreach (var stock in Portfolio.Values)
			{
				if (stock.Invested)
				{
					if (StocksToHold.Exists(x => x == stock.Symbol) == false)
					{
						Liquidate(stock.Symbol);
					}
				}
			}
			
			decimal positionSize = 1m / TotalHighDollarVolumeStocks;
			foreach (Symbol symbol in StocksToHold)
			{
				if (Portfolio[symbol].Invested == false && data.ContainsKey(symbol))
				{
					SetHoldings(symbol, positionSize);
				}
			}
        }
    }
}