Hi,
I am trying to get some crypto history into my algorithm but it is not working.
class MyAlgorithm(QCAlgorithm):
def Initialize(self):
self.cryptos = ["BTCEUR", "ETHEUR", "LTCEUR"]
def OnData(self, data):
hist = self.History(self.cryptos, 3, Resolution.Daily)
When I watch hist with the debug tool it is returning "Empty DataFrame Columns: [] Index: []".
Any ideas where I'm going wrong please?
Thanks.
Arthur Asenheimer
Hi Graeme,
data must be added with the AddCrypto() method.
class MyAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2020,1,1) self.SetCash(100000) self.cryptos = ["BTCEUR", "ETHEUR", "LTCEUR"] self.symbols = [self.AddCrypto(crypto).Symbol for crypto in self.cryptos] def OnData(self, data): hist = self.History(self.cryptos, 3, Resolution.Daily) self.Debug(hist.close.head())
By the way, it's not good style to create a history dataframe on every OnData() invoke. Too many unnecessary calculations. I recommend to use Rolling Windows instead.
Graeme Allen
Thank you Arthur.
I have the following:
class MyAlorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2012, 2, 1) self.SetEndDate(2019, 6, 1) self.Portfolio.SetCash(0) # Set USD to 0 since we only have EUR in our account self.Portfolio.SetCash("EUR", 1000, 1.23) # Set EUR strategy cash with current EURUSD conversion rate self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash) self.cryptos = ["BTCEUR", "ETHEUR", "LTCEUR"] for i in self.cryptos: self.symbols.append(self.AddCrypto(i, Resolution.Minute, Market.GDAX).Symbol) def OnData(self, data): hist = self.History(self.symbols, 3, Resolution.Daily)
I revised the code to:
class MyAlorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2012, 2, 1) self.SetEndDate(2019, 6, 1) self.Portfolio.SetCash(0) # Set USD to 0 since we only have EUR in our account self.Portfolio.SetCash("EUR", 1000, 1.23) # Set EUR strategy cash with current EURUSD conversion rate self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash) self.cryptos = ["BTCEUR", "ETHEUR", "LTCEUR"] self.symbols = [self.AddCrypto(crypto).Symbol for crypto in self.cryptos] def OnData(self, data): hist = self.History(self.symbols, 3, Resolution.Daily)
Unfortunately, I am still having the same problem - hist with the debug tool is returning "Empty DataFrame Columns: [] Index: []
I will look into using a rolling window - but one step at a time! :)
Adam W
Possibly data issues? Crypto data is a bit spotty before 2015 anyways
Graeme Allen
Adam - Thank you!!
I changed the start date to 2019 and that solved it. Great!
Graeme Allen
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!