Back

Ticker vs Symbol in History requests in research

Bonjour,

I am struggling with an admittedly minor issue, but still...

When requesting historical data in research, I can do so with the Equity Ticker, such as "AAPL".
Nevertheless, in a multi-security request (see below), the DataFrame returned uses as level-0 index the Symbol, such as "AAPL R753QTJ8XC9X". I have searched around on how to get the full symbol string from the symbol object, but so far without success.

For clarification of the question, see the code:

# init the QuantBook --------------
qb = QuantBook()
# add some Equities --------------
spy = qb.AddEquity("SPY")
aapl = qb.AddEquity("AAPL")
goog = qb.AddEquity("GOOG")

# request history ------------
history = qb.History(qb.Securities.Keys,10)

# now, the level-0 key in history is NOT "SPY","AAPL" and "GOOG", but "SPY R735QTJ8XC9X","AAPL R735QTJ8XC9X" and "AAPL R735QTJ8XC9X" <- how can I get those ones from the Equity objects that I created previously with AddEquity, instead of doing some pattern matching (i.e. identify which keys start with "SPY")?

 

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.


You can convert back and forth like:

ticker = 'SPY'

# API Methods
symbol = qb.Symbol(ticker).Symbol # Symbol Object; returned by qb.AddEquity(*)
securityID = symbol.ID # Security IDs (the keys of history)
ticker = symbol.Value # Get string ticker

For instance, to slice 'SPY':

spyData = history.ix(qb.Symbol('SPY').ID, level=0)

or

spyData = history.ix(spy.ID, level=0) # since you saved a reference to the symbol in spy

 

1

symbol = qb.Symbol(ticker).Symbol

does not work, since Symbol does not have another Symbol attribute, but the .Value vs .ID was exactly what I was looking for, thanks a lot!

0

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