I am working on a simple crypto algorithm that works, but the backtest results do not incorporate fees from IBKR. I want to include IBKR's fee structure and trade execution for this algo, but when I run the algo, I get the error that Crypto is supported. I wondered if I did not understand something or if there wasn't support for the IBKR broker model and crypto. Here is my algorithm with the ibkr lines commented out:
from AlgorithmImports import *
class CryptoMomentumStrategy(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 1, 1)
self.SetEndDate(2024, 1, 1)
self.SetCash(1_000_000)
# self.set_brokerage_model(BrokerageName.INTERACTIVE_BROKERS_BROKERAGE, AccountType.CASH)
# Add BTCUSD crypto asset
self.btc = self.AddCrypto("BTCUSD", Resolution.Hour, Market.GDAX).Symbol
# Set the fee model for Interactive Brokers
# self.Securities[self.btc].SetFeeModel(InteractiveBrokersFeeModel())
self.lookback = 20 # Lookback period for momentum calculation
self.momentum = None
def OnData(self, data):
if not data.Bars.ContainsKey(self.btc):
return
# Fetch historical data for momentum calculation
history = self.History(self.btc, self.lookback, Resolution.Daily)
if len(history) < self.lookback:
return
# Calculate momentum as the percentage price change over the lookback period
start_price = history["close"].iloc[0]
end_price = history["close"].iloc[-1]
self.momentum = (end_price - start_price) / start_price
# Trading logic based on momentum
if self.momentum > 0 and not self.Portfolio[self.btc].Invested:
self.SetHoldings(self.btc, 1.0) # Go long on positive momentum
elif self.momentum < 0 and self.Portfolio[self.btc].Invested:
self.Liquidate(self.btc) # Exit position on negative momentum
Mia Alissi
To incorporate a fee structure and trade execution for your crypto algorithm, you need to use a brokerage model that supports cryptocurrency trading. Since Interactive Brokers does not support crypto, you can use the
CoinbaseBrokerageModel
instead. Here's how you can modify your algorithm:This setup should correctly simulate the fees and trade execution for your crypto algorithm using Coinbase's fee structure.
Sources: Supported Models - QuantConnect.com, Requesting Data - QuantConnect.com, Coinbase - QuantConnect.com, Brokerage Model Algorithm, Coinbase Crypto Price Data - QuantConnect.com
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.
Thomas Zaborenko
The AI did anwser my question in regards to solving the algo. I am still interested to know if or when IBKR broker model will include support for Crypto? Thanks!
Thomas Zaborenko
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!