Overall Statistics |
Total Orders 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Start Equity 100000 End Equity 100000 Net Profit 0% Sharpe Ratio 0 Sortino 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.672 Tracking Error 0.173 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset Portfolio Turnover 0% |
from AlgorithmImports import * class CryptoMarketCapUniverseAlgorithm(QCAlgorithm): def initialize(self) -> None: self.set_start_date(2020, 1, 1) self.set_start_date(2020, 1, 10) self.set_account_currency("USD") self._market = Market.COINBASE self._market_pairs = [ x.key.symbol for x in self.symbol_properties_database.get_symbol_properties_list(self._market) if x.value.quote_currency == self.account_currency ] self.universe_settings.resolution = Resolution.HOUR self._universe = self.add_universe(CoinGeckoUniverse, self._select_assets) def _select_assets(self, data: List[CoinGeckoUniverse]) -> List[Symbol]: for datum in data: self.debug(f'{datum.coin},{datum.market_cap},{datum.price}') # Select the coins that our brokerage supports and have a quote currency that matches # our account currency. tradable_coins = [d for d in data if d.coin + self.account_currency in self._market_pairs] # Select the largest coins and create their Symbol objects. return [ c.create_symbol(self._market, self.account_currency) for c in sorted(tradable_coins, key=lambda x: x.market_cap)[-10:] ] def on_data(self, data): if self._universe.selected: symbols = [symbol for symbol in self._universe.selected if self.securities[symbol].price] for s in symbols: self.debug(f"Symbol {symbol}") # class GeekyLightBrownPigeon(QCAlgorithm): # def initialize(self) -> None: # # Setup # self.set_start_date(2021, 1, 1) # self.set_end_date(2021, 3, 1) # self.set_account_currency("USD") # self.set_cash(100_000) # self.set_brokerage_model(BrokerageName.COINBASE, AccountType.CASH) # # Universe # self.universe_settings.resolution = Resolution.HOUR # self._market = Market.COINBASE # self._market_pairs = [ # x.key.symbol # for x in self.symbol_properties_database.get_symbol_properties_list(self._market) # if x.value.quote_currency == self.account_currency # ] # self.debug(f"Market pairs {self._market_pairs}") # self._universe = self.add_universe(CoinGeckoUniverse, self._select_assets) # # Init # self._data_symbol = {} # def _select_assets(self, data: List[CoinGeckoUniverse]) -> List[Symbol]: # for datum in data: # self.debug(f'{datum.coin},{datum.market_cap},{datum.price}') # # Select the coins that our brokerage supports and have a quote currency that matches # # our account currency. # [self.debug(f"Coin {d.coin}") for d in data] # tradable_coins = [d for d in data if d.coin + self.account_currency in self._market_pairs] # # Select the largest coins and create their Symbol objects. # return [ # c.create_symbol(self._market, self.account_currency) # for c in sorted(tradable_coins, key=lambda x: x.market_cap)[-50:] # ] # # 2 # # selected = sorted(data, key=lambda x: x.market_cap, reverse=True)[:5] # # # Use the CreateSymbol method to generate the Symbol object for # # return [x.create_symbol(Market.BINANCE, "USD") for x in selected] # def on_securities_changed(self, changes): # for security in changes.added_securities: # symbol = security.symbol # if symbol not in self._data_symbol: # self._data_symbol[symbol] = SymbolData(symbol, self) # self.debug("Symbol added {symbol}") # for security in chagnes.removed_securities: # symbol = security.symbol # self.debug("Symbol removed {symbol}") # def on_data(self, data: Slice): # self.debug("Time {self.time}") # for x in self.active_securities.values: # symbol = x.symbol # self.set_holdings(symbol, 0.02) # for x in self._universe: # symbol = x.symbol # self.set_holdings(symbol, 0.02) # symbols = [symbol for symbol in self._universe.selected if self.securities[symbol].price] # for s in symbols: # self.debug(f"Symbol {symbol}") # self.set_holdings(symbol, 0.02) # class SymbolData(object): # def __init__(self, symbol, algo): # self.symbol = symbol # self.algo = algo # history_df = self.algo.history(self.symbol, 30, Resolution.HOUR, flatten=True) # # self.debug(f"history {history_df}") # from AlgorithmImports import * # class HighlyVolatileCryptoUniverseAlgorithm(QCAlgorithm): # def initialize(self): # self.set_start_date(2021, 1, 1) # self.set_end_date(2021, 6, 1) # self.set_cash(100_000) # self.set_brokerage_model(BrokerageName.COINBASE, AccountType.CASH) # self.universe_settings.resolution = Resolution.MINUTE # self._universe = self.add_universe(CryptoUniverse.coinbase(self._select_assets)) # # Init # self._time = -1 # self._data = {} # def _select_assets(self, data): # if self._time == self.time.month: # return Universe.UNCHANGED # self._time = self.time.month # coarse = [x for x in data if x.price > 5] # selected = sorted(coarse, key=lambda x: (x.high - x.low) / x.low)[-500:] # return [x.symbol for x in selected] # def on_securities_changed(self, changes): # for security in changes.added_securities: # symbol = security.symbol # if symbol not in self._data: # self._data[symbol] = SymbolData(symbol, self) # for security in changes.removed_securities: # symbol = security.symbol # if not self.portfolio[symbol].invested: # self._data.pop(symbol, None) # def on_data(self, data): # for symbol in self._data: # # Check if data is available # if not data.contains_key(symbol): continue # if not symbol in data: continue # # Update close window # close_ = data[symbol].close # self._data[symbol].update(close_) # # Calculate last hour return # if self._data[symbol].close[1] == 0: # continue # last_hour_ret = self._data[symbol].close[0] / self._data[symbol].close[1] - 1 # # Buy if > 20% # if not self.portfolio[symbol].invested and last_hour_ret > 0.2: # q = self.set_crypto_holdings(symbol, .1) # self.limit_order(symbol, -q, close_* 1.2) # self.stop_limit_order(symbol, -q, close_* 0.8) # def set_crypto_holdings(self, symbol, percentage): # crypto = self.securities[symbol] # base_currency = crypto.base_currency # # Calculate the target quantity in the base currency # target_quantity = percentage * (self.portfolio.total_portfolio_value) / base_currency.conversion_rate # quantity = target_quantity - base_currency.amount # # Round down to observe the lot size # lot_size = crypto.symbol_properties.lot_size # quantity = round(quantity / lot_size) * lot_size # if self.is_valid_order_size(crypto, quantity): # self.market_order(symbol, quantity) # return quantity # # Brokerages have different order size rules # # Binance considers the minimum volume (price x quantity): # def is_valid_order_size(self, crypto, quantity): # return abs(crypto.price * quantity) > crypto.symbol_properties.minimum_order_size # # def on_order_event(self, order_event): # # order = self.Transactions.GetOrderById(order_event.OrderId) # # if order.status == OrderStatus.FILLED: # # if order.Type == OrderType.Limit or order.Type == OrderType.StopMarket or order.Type == OrderType.MarketOnOpen: # # self.Transactions.CancelOpenOrders(order.Symbol) # # # self._data.pop(order.Symbol.Value, None) # # return # # active = self.active_securities.keys # # invested = [x.key for x in self.portfolio if x.value.invested] # # for symbol in invested: # # if symbol not in active: # # self.liquidate(symbol) # # for symbol in active: # # if not self.portfolio[symbol].invested: # # self.set_holdings(symbol, 0.05) # class SymbolData(object): # def __init__(self, symbol, algo): # self.symbol = symbol # self.algo = algo # # Create and warm up close rolling window # self.close = RollingWindow[float](2) # history = self.algo.history(symbol, 3, Resolution.HOUR) # if history.shape[0] == 0: # self.algo.debug("No history for symbol {symbol}") # return # for index, row in history.loc[symbol].iterrows(): # self.close.add(row["close"]) # def update(self, price): # self.close.add(price)