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.889 Tracking Error 0.146 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
# region imports from AlgorithmImports import * # endregion class CryingYellowGreenCrocodile(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 1, 1) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.nq = self.AddFuture("NQ", Resolution.Daily) # is the same as: self.nq.SetFilter(0, 240) # self.AddFuture(Futures.Indices.NASDAQ100EMini) # self.min = self.MIN(self.nq, 14, Resolution.Minute) # self.max = self.MAX(self.nq, 14, Resolution.Minute) self.symbols = [] self.count = 0 self.day_count = 0 def OnData(self, data): chains_count = 0 for chain in data.FutureChains: self.day_count += 1 chains_count += 1 self.count += 1 contracts = [contract for contract in chain.Value if contract.Expiry > self.Time + timedelta(days=8)] sorted_contracts = sorted(contracts, key=lambda x: x.Expiry) if len(sorted_contracts) == 0: continue # for x in contracts: self.symbols.append(str(sorted_contracts[0].Symbol)) if self.count < 20: self.Debug(f'{chains_count}, @{self.Time}') def OnEndOfAlgorithm(self): self.Debug(f'Day amount; {self.day_count}') self.Debug(f'len(symbols) = {len(self.symbols)}') self.Debug(f'{self.symbols}') # conclusion: yes, it selects the correct one
# region imports from AlgorithmImports import * # endregion class CryingYellowGreenCrocodile(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 5, 10) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.nq = self.AddFuture(Futures.Indices.NASDAQ100EMini, Resolution.Minute) # is the same as: self.nq.SetFilter(8, 240) # self.AddFuture(Futures.Indices.NASDAQ100EMini) self.Indicators = { 'sma': SimpleMovingAverage(11), 'ema_fast': ExponentialMovingAverage(12), 'ema_slow': ExponentialMovingAverage(26), 'min': Minimum(14), 'max': Maximum(14), } self.symbol = [] self.consolidator = None def OnData(self, data): holding = None if self.symbol is None else self.Portfolio.get(self.symbol) if holding is None: return if not data.Bars.ContainsKey(self.symbol): return # if self.Indicators['ema_fast'].Current.Value > self.Indicators['ema_slow'].Current.Value: if not holding.Invested: self.SetHoldings(self.symbol, 0.1) elif holding.Invested: self.Liquidate(self.symbol) def OnSecuritiesChanged(self, changes): if len(changes.RemovedSecurities) > 0: # Remove the consolidator for the previous contract # and reset the indicators if self.symbol is not None and self.consolidator is not None: self.SubscriptionManager.RemoveConsolidator(self.symbol, self.consolidator) for indicator in self.Indicators: self.Indicators[indicator].Reset() # We don't need to call Liquidate(_symbol), # since its positions are liquidated because the contract has expired. if len(changes.AddedSecurities) == 0: return # Only one security will be added: the new front contract self.symbol = changes.AddedSecurities[0].Symbol # Create a new consolidator and register the indicators to it self.consolidator = self.ResolveConsolidator(self.symbol, Resolution.Minute) for indicator in self.Indicators: self.RegisterIndicator(self.symbol, self.Indicators[indicator], self.consolidator) self.WarmUpIndicator(self.symbol, self.Indicators[indicator], Resolution.Minute) def MinutesHandler(self, sender, bar): # close_window.Add(bar.Close) # high_window.Add(bar.High) # low_window.Add(bar.low) pass def OnEndOfAlgorithm(self): pass