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 -13.002 Tracking Error 0.069 Treynor Ratio 0 Total Fees $0.00 |
from System import * from QuantConnect import * from QuantConnect.Data.Consolidators import * from QuantConnect.Data.Market import * from QuantConnect.Orders import OrderStatus from QuantConnect.Algorithm import QCAlgorithm from QuantConnect.Indicators import * import numpy as np from datetime import timedelta, datetime ### <summary> ### Example structure for structuring an algorithm with indicator and consolidator data for many tickers. ### </summary> ### <meta name="tag" content="consolidating data" /> ### <meta name="tag" content="indicators" /> ### <meta name="tag" content="using data" /> ### <meta name="tag" content="strategy example" /> class MultipleSymbolConsolidationAlgorithm(QCAlgorithm): # Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized. def Initialize(self): #self.SetStartDate(2014, 8, 1) self.SetStartDate(2020, 8, 24) # self.SetEndDate(2015, 2, 1) self.SetEndDate(datetime.now().date()) self.SetCash(100000) # Set Strategy Cash # This is the period of bars we'll be creating # Holds all of our data keyed by each symbol self.Data = {} self.daily = {} self.window = {} self.securities = [] # consolidation_size = 24 consolidation_size = 1 EquitySymbols = ["AAPL", "SPY", "IBM"] # Contains all of our forex symbols ForexSymbols = ["EURUSD", "USDJPY", "EURGBP", "EURCHF", "USDCAD", "USDCHF", "AUDUSD", "NZDUSD"] CryptoSymbols = ["BTCUSD", "ETHUSD", "LTCUSD", "BCHUSD", "XRPUSD", "BCHUSD", "XLMUSD", "EOSUSD", "REPUSD", "XTZUSD", "ETCUSD", "ZRXUSD"] self.cryptosymbols = [] for symbol in CryptoSymbols: crypto = self.AddCrypto(symbol, Resolution.Daily, Market.GDAX).Symbol self.securities.append(crypto) HourlyConsolidator = TradeBarConsolidator(consolidation_size) HourlyConsolidator.DataConsolidated += self.HourlyConsolidator self.SubscriptionManager.AddConsolidator(crypto, HourlyConsolidator) self.daily[crypto] = RollingWindow[TradeBar](1000 * consolidation_size) self.window[crypto] = RollingWindow[TradeBar](1000 * consolidation_size) self.cryptosymbols.append(crypto) self.equitysymbols = [] for symbol in EquitySymbols: equity = self.AddEquity(symbol, Resolution.Daily, Market.USA).Symbol self.equitysymbols.append(equity) HourlyConsolidator = TradeBarConsolidator(consolidation_size) HourlyConsolidator.DataConsolidated += self.HourlyConsolidator self.SubscriptionManager.AddConsolidator(equity, HourlyConsolidator) self.daily[equity] = RollingWindow[TradeBar](1000 * consolidation_size) self.window[equity] = RollingWindow[TradeBar](1000 * consolidation_size) self.equitysymbols.append(equity) #consolidates daily data for crypto so far def HourlyConsolidator(self, sender, bar): self.daily[bar.Symbol].Add(bar) def OnData(self, data): # for symbol in self.securities: # sell_len = 120 # buy_len = 180 # buy_ticks = list(range(0, buy_len)) # sell_ticks = list(range(0, sell_len)) # solves issue of wasn't found in the TradeBars object, likely because there was no-data at this moment in time and it wasn't possible to fillforward historical data if not all([data.Bars.ContainsKey(symbol) for symbol in self.cryptosymbols]): return for symbol in self.cryptosymbols: if not data.ContainsKey(symbol): return self.window[symbol].Add(data.Bars[symbol]) if not self.window[symbol].IsReady: continue current_close = self.window[symbol][0].Close prev_daily_close = self.daily[symbol][1].Close second_last_daily_close = self.daily[symbol][999].Close last_daily_close = self.daily[symbol][1000].Close self.Debug(type(last_daily_close)) if not all([data.Bars.ContainsKey(symbol) for symbol in self.equitysymbols]): return for symbol in self.equitysymbols: # self.Debug(symbol) if not data.ContainsKey(symbol): return self.window[symbol].Add(data.Bars[symbol]) #self.window[symbol].Add(data[symbol]) # Access bar properties from the `window` if not self.window[symbol].IsReady: continue