This code from documentation returns an error
:
Runtime Error: 'NoneType' object is not iterable
at _rebalance
symbols = [symbol for symbol in self._universe.selected if self.securities[symbol].price]
from AlgorithmImports import *
class LargeCapCryptoUniverseAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2020, 1, 1)
self.set_end_date(2021, 1, 1)
# Set the account currency. USD is already the default value. Change it here if you want.
self.set_account_currency("USD")
# Get the pairs that our brokerage supports and have a quote currency that
# matches your account currency. We need this list in the universe selection function.
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
]
# Add a universe of Cryptocurrencies.
self._universe = self.add_universe(CoinGeckoUniverse, self._select_assets)
# Add a Sheduled Event to rebalance the portfolio.
self.schedule.on(self.date_rules.every_day(), self.time_rules.at(12, 0), self._rebalance)
def _select_assets(self, data: List[CoinGeckoUniverse]) -> List[Symbol]:
# 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 _rebalance(self):
symbols = [symbol for symbol in self._universe.selected if self.securities[symbol].price]
# Liquidate coins that are no longer in the universe.
targets = [PortfolioTarget(symbol, 0) for symbol, holding in self.portfolio.items() if holding.invested and symbol not in symbols]
# Form an equal weighted portfolio of the coins in the universe.
targets += [PortfolioTarget(symbol, 0.5/len(symbols)) for symbol in symbols]
# Place orders to rebalance the portfolio.
self.set_holdings(targets)
Mia Alissi
Sources: Key Concepts - QuantConnect.com, Copying Congress Trades, Crypto - QuantConnect.com, Liquidity Effect In Stocks, Dropbox Base Data Universe Selection Algorithm
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Mislav Sagovac
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!