Back

Equity vs. Crypto and using .History()

Equity returns DataFrame as expected but Crypto doesn't.

What am I missing?

Thanks,

Tony

Update Backtest







0

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.


So, I got this to work

history = qb.History(qb.Securities.Keys, 60, Resolution.Hour)

but if I change Resolution to Minute, I get the same output as above. Is there an issue pulling crypto minute History()?

0

Hi Tony.

Thank you for sharing! You can retrieve 60 minute data history for a crypto currency pair such as BTC/USD by using timedelta(60) instead of 60 in History():

# Import timedelta
from datetime import timedelta

# Add the security
qb.AddCrypto('BTCUSD', Resolution.Minute)

# Retrieve minute data history for BTC/USD
history = qb.History(['BTCUSD'], timedelta(60))

I've attached a notebook where I retrieve 60 minute data history to a DataFrame for AMZN and also the crypto currency pair BTC/USD.

 

0

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.


If I run this code, the request automatically returns 86.400 minute observations, which equals in total 60 days.
How can I limit the number of observations in the qb.History() request for cryptocurrency?

Thanks in advance for your time and help!

0

Hi Serkan,

qb.History() method takes many forms of period definitions. Here are some common examples:

# self.AddEquity("SPY")

1. qb.History(Symbols, Timedelta). For example, 

qb.History(['SPY'], timedelta(days=60))

 requests data for "SPY" in most recent 60 days, and

qb.History(['SPY'], timedelta(minuts = 20))

 requests data in most recent 20 minutes.

2. qb.History(Symbols, StartDate, EndDate). For example,

qb.History(['SPY'], datetime(2017, 1, 11, 10, 10), datetime(2017, 1, 13, 12, 10))

 requests data for SPY from 2017-01-11 10:10 to 2017-01-13 12:10

3. qbHistory(Symbols, int). For example,

qb.History(['SPY'], 100)

 requests most recent 100 bars for "SPY"

You could find more History() overloads here is some information regarding usage of python datetime and timedelta.

Hope it helps.

0

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.


Hi Link Liang,

Thank you for your fast response.

I agree with your response for the use of equities. However, when I implement your code for cryptocurrencies, the behaviour is different.

The code below returns a filled DataFrame for 60 days

btc = qb.AddCrypto("BTCUSD",Resolution.Minute, Market.Bitfinex)
qb.History(qb.Securities.Keys,timedelta(60),Resolution.Minute)

The code below returns an empty DataFrame

btc = qb.AddCrypto("BTCUSD",Resolution.Minute, Market.Bitfinex)
qb.History(qb.Securities.Keys,timedelta(10),Resolution.Minute)

also if I replace timedelta(60) by any lower integer than 60 or days=1 for example, I get an empty Dataframe.

It is not possible to only retrieve 1 day with the History method for cryptocurrency?

Thank again for the help of the community!

0

Hi Serkan,

The problem is our crypto data was missing, and we have fixed it. Please give it another try and let us know if it still does not work for you. Meanwhile, you could always check our data avaibility in our data explorer. Thanks for your support!

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed