Overall Statistics
# Your New Python File
import numpy as np
import random as rand

class RandomShortUniverseAlgo(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2015, 1, 1)  # Set Start Date
        self.SetEndDate(2015, 2, 1)
        self.SetCash(1000000)  # Set Strategy Cash
        self._maxCoarse = 800
        self.UniverseSettings.Resolution = Resolution.Daily

    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
                data: Slice object keyed by symbol containing the stock data

        all_symbols = [ x.Value for x in self.Portfolio.Keys ][:10]
        self.Log("all: " + str(all_symbols))

    def CoarseSelectionFunction(self, coarse):
        self.Log('Length coarse: {}'.format(len(list(coarse))))
        filtered = [x for x in coarse if x.HasFundamentalData]
        self.Log("Num filtered for fundamental data: {}".format(len(filtered)))
        filtered = [x.Symbol for x in filtered if x.Price > 0.001]
        self.Log("Num filtered for price: {}".format(len(filtered)))
        for symbol in filtered:
            ticker = symbol.Value
            # do something with ticker
        # alternatively: tickers_list = [symbol.Value for symbol in filtered]
        selection = rand.sample(filtered, self._maxCoarse)
        #self.Log('Universe {}'.format(list(selection)))
        return selection