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
namespace QuantConnect
{
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
    	private bool _rebalenceFlag = true;
    	private bool _firstMonthTradeFlag = true;
    	private bool _reSelectUniverse = true;
    	private IEnumerable<Symbol> _symbols = Enumerable.Empty<Symbol>();
    	
        public override void Initialize()
        {
            SetStartDate(2013, 10, 07);  //Set Start Date
            SetEndDate(2013, 10, 11);    //Set End Date
            SetCash(100000);             //Set Strategy Cash

            AddUniverse(CoarseSelectionFunction, FineSelectionFunction);
        }

        public override void OnData(Slice data)
        {
            Log(string.Join(",", data.Keys));
        }
        
        public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
        {
        	if (_rebalenceFlag || _firstMonthTradeFlag)
        	{
                // drop stocks which have no fundamental data or have too low prices
                // order by dollar volumena and take the top 200
                _symbols = coarse
                	.Where(x => x.HasFundamentalData)
                	.Where(x => x.Price > 5)
                	.OrderByDescending(x => x.DollarVolume)
                	.Select(x => x.Symbol)
                	.Take(200);
        	}
        	return _symbols;
        }
        
        public IEnumerable<Symbol> FineSelectionFunction(IEnumerable<FineFundamental> fine)
        {
            if (_reSelectUniverse)
            {
            	_symbols = fine
            	    .Where(x => x.SecurityReference.SecurityType == "ST00000001")
                    .Where(x => x.SecurityReference.IsPrimaryShare)
                    .Where(x => x.ValuationRatios.EVToEBITDA > 0)
                    .Where(x => x.EarningReports.BasicAverageShares.ThreeMonths > 0)
                    .Where(x => 
                    {
                	    var averageShares = x.EarningReports.BasicAverageShares.ThreeMonths;
                	    var history = History(x.Symbol, 1, Resolution.Daily);
                	    var close = history.FirstOrDefault()?.Close;
                	    
                	    // If history is empty, close will be null
                	    // In this case, we will not consider the security
                	    if (close == null)
                	    {
                	    	return false;
                	    }
                	    
                	    return averageShares * close > 2 * 1000 * 1000 * 1000;
                    })
               	    .OrderByDescending(x => x.ValuationRatios.EVToEBITDA)
                    .Select(x => x.Symbol);
            }
            return _symbols;
        }        
    }
}