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
-4.086
Tracking Error
0.183
Treynor Ratio
0
Total Fees
$0.00
class Algo(QCAlgorithm):
    
    def Initialize(self):
        
        self.SetStartDate(2020, 8, 1)
        self.SetEndDate(2020, 8, 15)
        self.SetCash(100000)
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
        
        self.UniverseSettings.Resolution = Resolution.Minute
        
        self.symbol = "QQQ"
        self.qqq = self.AddEquity(self.symbol, Resolution.Minute)
        self.qqq.SetDataNormalizationMode(DataNormalizationMode.SplitAdjusted)
        
        self.SetBenchmark(self.symbol)
        
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen(self.symbol, 1), self.scheduleMarketOpen1)
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen(self.symbol, 2), self.scheduleMarketOpen2)

        self.firstDay = 1
        self.missing = 0
        
        self.SetWarmup(5000)
        
    
    def OnData(self, data):
        pass
        
    
    def scheduleMarketOpen1(self):
        
        self.Log("scheduleMarketOpen1")
        if self.firstDay != 1:
            history = self.History([self.symbol], 1, Resolution.Daily)
            if str(self.symbol) in history.index:
                for time, row in history.loc[self.symbol].iterrows():
                    self.Log(str(row["close"]))
                    self.missing = 0
            else:
                self.Debug("missing")
                self.missing = 1
        else:
            self.firstDay = 0
    
    
    # run in case of missing data -> doesn't seem to fetch correct data on 2020-08-11
    def scheduleMarketOpen2(self):
        
        if self.missing:
            self.Log("scheduleMarketOpen2")
            if self.firstDay != 1:
                history = self.History([self.symbol], 1, Resolution.Daily)
                if str(self.symbol) in history.index:
                    for time, row in history.loc[self.symbol].iterrows():
                        self.Log(str(row["close"]))
                        self.missing = 0
                else:
                    self.Debug("missing")
                    self.missing = 1
            else:
                self.firstDay = 0