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
Probabilistic 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
-10.684
Tracking Error
0.136
Treynor Ratio
0
Total Fees
$0.00
using System;
using System.Collections.Concurrent;
using System.Linq;
using QuantConnect.Data.Market;
using QuantConnect.Data.UniverseSelection;
using QuantConnect.Indicators;

namespace QuantConnect.Algorithm.CSharp
{

    public class yunotwork : QCAlgorithm
    {
        private const decimal TargetPercent = 0.1m;
        private SecurityChanges _changes = SecurityChanges.None;
        // holds our coarse fundamental indicators by symbol
        private readonly ConcurrentDictionary<Symbol, SelectionData> _averages = new ConcurrentDictionary<Symbol, SelectionData>();

		List<Symbol> _invested = new List<Symbol>();

        // class used to improve readability of the coarse selection function
        private class SelectionData
        {
            public readonly ExponentialMovingAverage Fast;
            public readonly ExponentialMovingAverage Slow;

            public SelectionData()
            {
                Fast = new ExponentialMovingAverage(1);
                Slow = new ExponentialMovingAverage(5);
            }

            // computes an object score of how much large the fast is than the slow
            public decimal ScaledDelta
            {
                get { return (Fast - Slow)/((Fast + Slow)); }
            }

            // updates the EMA1 and EMA5 indicators, returning true when they're both ready
            public bool Update(DateTime time, decimal value)
            {
                return Fast.Update(time, value) && Slow.Update(time, value);
            }
        }

        public override void Initialize()
        {
            UniverseSettings.Resolution = Resolution.Minute; // doesn't matter, still gives wrong current price :(
            UniverseSettings.ExtendedMarketHours = false;
			//UniverseSettings.FillForward = true;
			UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw; //can only compare x.Price to History request with Raw data 

            SetStartDate(2020, 6, 2); // go to wait for EMA to warm up. normal warming up doesn't work :(
            SetEndDate(2020, 6, 4);
            SetCash(1000);
			
    		AddUniverse(NiceFilter, FineSelectionFunction);
			
        }
		
		IEnumerable<Symbol> NiceFilter(IEnumerable<CoarseFundamental> coarse) {
			var _symbols = coarse
 				 .Where(x => x.HasFundamentalData)
				 .Where(x => x.DollarVolume > 800000)
				 .Where(x => x.Price > 2)
                 .Where(x => 
                    {
                    	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; }
                	    
                	    if (x.Symbol.Value == "GNUS") {
                	    	Debug("=========");
                	    	Debug($"'Current price': {x.Price.ToString()}");
                	    	Debug($"'1dayago price': {close.ToString()}");
                	    	Debug("---------");
                	    }
                	    
                	    return (x.Price> (decimal)1.7 * close);
                    })
                    .Select(x => x.Symbol).Take(10);
			return _symbols;
		}
        
        IEnumerable<Symbol> FineSelectionFunction(IEnumerable<FineFundamental> fine) {
			var _symbols = fine
				 .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 (close == null) { return false; }

                	    var marketcap = averageShares * close;
                	    // MarketCap > 25m
                	    return (marketcap > 25000000);
                    })
                    .Select(x => x.Symbol).Take(5);
			return _symbols;
		}
    }
}