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
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
from QuantConnect.Data.Market import TradeBar
from datetime import *
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
import decimal as d
import operator


class MyAlgorithm(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2018, 3, 8)  # Set Start Date
        self.SetEndDate(2018, 3, 14)
        self.SetCash(100000)  # Set Strategy Cash
        
        self.symbolData = dict()
        
        for ticker in ["SCHW", "IVR", "ABBV", "SPG",
"RY", "BHGE", "REGN", "ONB", "ELY", "ESNT", "PACW", "TTS", "WUBA",
"WERN", "TRPE", "SINA"]:
    
            symbol = self.AddEquity(ticker, Resolution.Second).Symbol
            consolidator_daily = TradeBarConsolidator(timedelta(1))
            consolidator_daily.DataConsolidated += self.OnDailyData
            self.SubscriptionManager.AddConsolidator(symbol, consolidator_daily)
            
            self.symbolData[symbol] = SymbolData()

        self.Schedule.On(self.DateRules.EveryDay(),
                         self.TimeRules.At(9, 30, 2),
                         Action(self.shortly_after_open_market))
                        
    def OnDailyData(self, sender, bar):
        self.symbolData[bar.Symbol].daily_rw.Add(bar)

    def shortly_after_open_market(self):

        for symbol in self.symbolData:
            if (self.Securities[symbol].Exchange.ExchangeOpen
                ):
                window = self.symbolData[symbol].window
                daily = self.symbolData[symbol].daily_rw
                if not (window.IsReady and daily.IsReady): continue
                self.Log(str(symbol))

    def OnData(self, data):

        for symbol in data.Keys:
                
            if data[symbol] is None: continue
            window = self.symbolData[symbol].window
            window.Add(data[symbol])
            daily = self.symbolData[symbol].daily_rw
  
class SymbolData(object):
            
    def __init__(self):
        self.daily_rw = RollingWindow[TradeBar](2)
        self.window = RollingWindow[TradeBar](1)