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 1.682 Tracking Error 0.15 Treynor Ratio 0 Total Fees $0.00 |
import numpy as np import random as rand rand.seed(22) 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 self.AddUniverse(self.CoarseSelectionFunction) def OnData(self, data): '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. Arguments: 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
# Your New Python File