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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using System.Diagnostics;
using QuantConnect.Data.UniverseSelection;

namespace QuantConnect.Algorithm.CSharp
{
    class Quantithmar : QCAlgorithm
    {
        //private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
        private int _universeSize = 500, _trackerCount = 5;
        private List<QuantConnect.Securities.Security> _dailyTrackers = new List<QuantConnect.Securities.Security>();

        /// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
        /// </summary>
        public override void Initialize()
        {
            SetStartDate(2017, 08, 01);
            SetCash(100000);

            Schedule.On(DateRules.EveryDay(), TimeRules.At(9, 31), SelectStocks);
            //SetRunMode(RunMode.Parallel);

            UniverseSettings.Resolution = Resolution.Daily;
            AddUniverse(Universe.DollarVolume.Top(_universeSize));
            Debug(Time.ToString());
        }

        private void SelectStocks()
        {
            Dictionary<QuantConnect.Securities.Security, decimal> changes = new Dictionary<QuantConnect.Securities.Security, decimal>();
            IEnumerable<Slice> slices = History(TimeSpan.FromDays(1), Resolution.Daily);
            foreach (var s in Securities)
            {
                var symbol = s.Value.Symbol;
                if (slices.Count() > 0 && s.Value.Price > 0)
                {
                    IEnumerable<decimal> closingPrices = slices.Get(symbol, Field.Close);
                    var previous = closingPrices.FirstOrDefault();
                	var change = previous == 0 ? 0 : (s.Value.Price - previous) / previous;
                	changes.Add(s.Value, change);
                }
                //Securities.Remove(symbol);
                //RemoveSecurity(symbol);
                //SubscriptionManager.Subscriptions.RemoveWhere(x => x.Symbol == symbol);
            }
            if (changes.Count > 0)
            {
                _dailyTrackers = changes.OrderByDescending(x => x.Value).Take(_trackerCount).Select(x => x.Key).ToList();
                Debug(Time.ToShortDateString() + ": " + String.Join(", ", _dailyTrackers.Select(x => x.Symbol)));
                //AddEquity(_dailyTrackers.First().Symbol.Value, Resolution.Minute);
            }
        }

        /// <summary>
        /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        /// </summary>
        /// <param name="data">Slice object keyed by symbol containing the stock data</param>
        public override void OnData(Slice data)
        {
            if (!Portfolio.Invested)
            {
            }
        }
    }
}