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
class MyUniverseSelection(QCAlgorithm):

    def Initialize(self):
        # Set Start Date
        self.SetStartDate(2017, 1, 1)
        self.SetEndDate(2017, 1, 2)
        
        # Set Strategy Cash
        self.SetCash(100000)
         
        # Make dictionary for universe selection
        self.stateData = { }
        
         # Add the universe
        self.AddUniverse(self.CoarseSelectionFilter)
        
        # Schdule for everyday on market open
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(9, 33), self.EveryDayAfterMarketOpen)
        
        # Schedule for everyday before market close
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(15, 57), self.EveryDayBeforeMarketClose)
        
        self.securities = []
        
    # Function for coarse selection (to define our universe)
    def CoarseSelectionFilter(self, coarse):
        self.coarse = coarse
        
        # We are going to use a dictionary to refer the object that will keep the moving averages
        # Adds the stocks that fit the volume criteria to the dictionary
        for c in coarse:
            if c.Symbol not in self.stateData:
                self.stateData[c.Symbol] = SelectionData(c.Symbol, 10)
                
            # Update the stateData to make sure it has the most recent stock data
            avg = self.stateData[c.Symbol]
            avg.update(c.EndTime, c.AdjustedPrice, c.DollarVolume)
        
        # Makes sure price is between 1 and 100
        filtered = [symbol for symbol, sd in self.stateData.items() if sd.price >= 1 and sd.price <= 100]
                     
        return filtered
    
    # Everyday after market open
    def EveryDayAfterMarketOpen(self):
        # If current slice contains "SPY" data place a market order
        
        pass
        
        # for c in self.securities:
        #     if c.Open[0] < c.Close[1]:
        #         self.MarketOrder(c, .01)
    
    # Everyday before market close
    def EveryDayBeforeMarketClose(self):
        # Liquidate all holdings
        self.Liquidate()
        
    # Chnages self.securitues as the universe changes
    def OnSecuritiesChanged(self, changes):
        
        # add new securities
        for added in changes.AddedSecurities:
            self.securities.append(added)

        # remove securities
        for removed in changes.RemovedSecurities:
            if removed in self.securities:
                self.securities.remove(removed)

class SelectionData(object):
    def __init__(self, symbol, period):
        self.symbol = symbol
        self.price = 0
        self.volume = 0
        self.sma = SimpleMovingAverage(period)
        self.is_above_vol = False
        
    def update(self, time, price, volume):
        self.volume = volume
        self.price = price
        if self.sma.Update(time, volume):
            self.is_above_vol = sma > 3500000