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
9.002
Tracking Error
0.041
Treynor Ratio
0
Total Fees
$0.00
class TimeLimitProblem_002(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2016, 12, 29)  # Set Start Date
        self.SetEndDate(2016, 12, 30)
        self.SetCash(100000)  # Set Strategy Cash
        # self.AddEquity("SPY", Resolution.Minute)

        self.__dataDict = {}

        self.UniverseSettings.Resolution = Resolution.Hour
        self.AddUniverse(self.CoarseSelect, self.FineSelect)


    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
        '''

        # if not self.Portfolio.Invested:
        #    self.SetHoldings("SPY", 1)


    def CoarseSelect(self, coarse):
        self.Debug("CoarseSelect()")
        symbols = []
        for c in coarse:
            if c.HasFundamentalData:
                symbols.append(c.Symbol)
                # self.History(c.Symbol, 150, Resolution.Daily)
                if c.Symbol not in self.__dataDict:
                    try:
                        hist = self.History(c.Symbol, 126, Resolution.Daily)
                        self.__dataDict[c.Symbol] = SMAGroups(self, c.Symbol)
                        self.__dataDict[c.Symbol].UpdateHist(hist, c.Symbol)
                    except:
                        continue
                else:
                    self.__dataDict[c.Symbol].Update(c.EndTime, c.AdjustedPrice)

        self.Debug("CoarseSelect() total: {}".format(len(symbols)))
        return symbols

    def FineSelect(self, fine):
        self.Debug("FineSelect()")

        symbols = [f.Symbol for f in fine]
        pickSize = 10
        self.Debug("FineSelect() total: {}".format(len(symbols[0:pickSize])))
        return symbols[0:pickSize]

class SMAGroups(object):
    def __init__(self, algorithm, symbol):
        self.__sma001 = SimpleMovingAverage(10)
        self.__sma002 = SimpleMovingAverage(20)
        self.__sma003 = SimpleMovingAverage(126)

    def UpdateHist(self, hist, symbol):
        for index, row in hist.loc[symbol].iterrows():
            self.__sma001.Update(index, row["close"])
            self.__sma002.Update(index, row["close"])
            self.__sma003.Update(index, row["close"])

    def Update(self, endTime, adjustedPrice):
        self.__sma001.Update(endTime, adjustedPrice)
        self.__sma002.Update(endTime, adjustedPrice)
        self.__sma003.Update(endTime, adjustedPrice)