Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
using System.Collections.Concurrent;

namespace QuantConnect.Algorithm.CSharp
{
    public class MomentumInvest : QCAlgorithm
    {
    	
    	SortedDictionary<Symbol, SelectionData> stateData = new SortedDictionary<Symbol, SelectionData>();

        private decimal largeCompMarketCap = 10000000000;
        private decimal largeCompVolume = 100000000;
    	private int currentMonth = -1;

		private class SelectionData
		{
		    // stock selection data
		    public Symbol symbol;
		    
		    public SelectionData(Symbol _symbol)
		    {
		    	symbol = _symbol;
		    }
		}

        public override void Initialize()
        {
            //SetStartDate(2000, 8, 1);
            SetStartDate(2019, 08, 5);
            SetEndDate(2019,08,10);
            SetCash(100000);
			//SetWarmup(momPeriod);
			//SetBenchmark("SPY");
			UniverseSettings.Resolution = Resolution.Daily;
			SetSecurityInitializer(x => x.SetDataNormalizationMode(DataNormalizationMode.Raw));
			
			AddUniverse(CoarseFilterFunction, FineSelectionFunction);
        }
        
	    public IEnumerable<Symbol> CoarseFilterFunction(IEnumerable<CoarseFundamental> coarse)
	    {
	    	if(currentMonth != Time.Month)
	    	{
	    		//new month --> new stock selection
	    		currentMonth = Time.Month;
	    		var stocks = new List<Symbol>(); 

		    	var e = coarse.GetEnumerator();
		    	while(e.MoveNext())
		    	{
		    		var c = e.Current;
		    		if(c.Price > 10 && c.HasFundamentalData && c.DollarVolume > largeCompVolume*10)
		    		{
		    			stocks.Add(c.Symbol);
		    		}
		    	}
		    	
		    	return stocks;
	    	}
	    	else
	    	{
	    		// same month --> no changes
	    		return Universe.Unchanged;
	    	}
	    }	
	    
	    public IEnumerable<Symbol> FineSelectionFunction(IEnumerable<FineFundamental> fine)
	    {
			var stocks = new List<Symbol>();
	    	var e = fine.GetEnumerator();
	    	
	    	while(e.MoveNext())
	    	{
	    		var f = e.Current;

	    		if(f.ValuationRatios.PERatio *
                   f.EarningReports.BasicEPS.TwelveMonths *
                   f.EarningReports.BasicAverageShares.ThreeMonths > largeCompMarketCap*10)
	    		{
	    			stocks.Add(f.Symbol);
	    		}
	    	}
	    	
	    	return stocks; 
	    }
	   
	    public override void OnSecuritiesChanged(SecurityChanges changes)
		{
			
			if(changes.AddedSecurities.Count > 0)
			{
			    for(int i=0; i < changes.AddedSecurities.Count; i++) 
			    {
			    	// add new security to SortedDictionary
			    	var addedSymbol = changes.AddedSecurities[i].Symbol;
			    	SelectionData data = new SelectionData(addedSymbol);
			    	
			    	try
			    	{
			    		stateData.Add(addedSymbol, data);
			    	}
			    	catch (ArgumentException e)
			    	{}
			    	
			    }
			}
			
			if(changes.RemovedSecurities.Count > 0)
			{
			    for(int i=0; i < changes.RemovedSecurities.Count; i++) 
			    {
			    	// remove security
			    	stateData.Remove(changes.RemovedSecurities[i].Symbol);
			    }
			}
		}
        
        public override void OnData(Slice data)
        {
        	
        	foreach(var key in data.Keys)
        	{
        		Debug(key.Value);
        	}

        	foreach(var selectionData in stateData.Values)
        	{
        		Debug(selectionData.symbol.Value);
        		Debug(data.ContainsKey(selectionData.symbol.Value).ToString());
        		
        	}
        }
    }
}