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
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
import pandas as pd
from io import StringIO

class CryingSkyBlueJaguar(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 4, 1)
        self.SetEndDate(2021, 4, 1)
        self.SetCash(100000) 
        self.UniverseSettings.ExtendedMarketHours = True
        #Scheduled universe 
        self.Schedule.On(
            self.DateRules.EveryDay(),
            self.TimeRules.At(4, 0),
            self.csvToSymbols
            )
        #Triggers the method that condenses our coarse dictionary
        self.Schedule.On(
            self.DateRules.EveryDay(),
            self.TimeRules.At(6, 59),
            self.CondensedUniverse
            )
        #Triggers the method that removes unused symbols from our universe
        self.Schedule.On(
            self.DateRules.EveryDay(),
            self.TimeRules.At(7, 1),
            self.RemoveUnusedSymbols
            )
    universeSymbols = {}
    condensedSymbols = {}
    condensedValues = []
    
    #csv has about 1500 tickers on it
    def csvToSymbols(self):
        csv = self.Download("https://www.dropbox.com/s/lkk4eyehh0c6eq3/2021-04-19.csv?dl=1")
        df = pd.read_csv(StringIO(csv), header=None, names=['Ticker', 'Description'])
        self.csvTickerList = list(df.Ticker)
        self.csvSymbolsList = [self.AddEquity(ticker, Resolution.Minute, Market.USA, True, 1, True).Symbol for ticker in self.csvTickerList]
        self.universeSymbols = {
            symbol: 0 for symbol in self.csvSymbolsList
        }
        #Takes ticker from symbol object for logging purposes
        self.universeValues = [symbol.Value for symbol in self.universeSymbols.keys()]
        self.Log(f"Our universe symbols at {self.Time} are: {self.universeValues}")
        return list(self.universeSymbols.keys())
        
    def CondensedUniverse(self):
        #Sorting our coarse symbols base off current change percent
        sortedSymbols = {symbol: value for symbol, value in sorted(
                self.universeSymbols.items(), key=lambda item: item[1], reverse=True
                )}
        for symbol in sortedSymbols.keys():
            if len(self.condensedSymbols) < 50:
                self.condensedSymbols[symbol] = [0, 0, 0, 0]
        #Takes ticker from symbol object for logging purposes
        self.condensedValues = [symbol.Value for symbol in self.condensedSymbols.keys()]
        self.Log(f"At {self.Time}, our tickers are: {self.condensedValues}, and our values are {self.condensedSymbols.values()}")
    
    def RemoveUnusedSymbols(self):
        for symbol in self.universeSymbols.keys():
            if len(self.condensedSymbols) < 50:
                return
            else:
                if not symbol in self.condensedSymbols.keys():
                    self.RemoveSecurity(symbol)

    def OnData(self, data):
        if len(self.universeSymbols) == 0:
            return
        if self.myHour() == 6 and self.myMinute() == 58:
            for symbol in self.universeSymbols.keys():
                if data.Bars.ContainsKey(symbol):
                    self.closeDF = self.History(symbol, 1, Resolution.Daily)
                    self.changePercent = data[symbol].Price / self.closeDF['close'][0]
                    self.universeSymbols[symbol] = self.changePercent

    def OnSecuritiesChanged(self, changes):
        self.changes = changes
        self.Log(f"OnSecuritiesChanged({self.Time}):: {self.changes}")
        
    def myHour(self):
        timeString = str(self.Time)
        return int(timeString[11:13])
        
    def myMinute(self):
        timeString = str(self.Time)
        return int(timeString[14:16])