Back

Get ticker from history

Hi,

I have this code here:

h2 = self.History(stock_list, 1, Resolution.Minute)
self.Debug(h2)

WIth stock_list being a list of stocks (symbol objcts) from my universe

THat returns the following:

close high low open volume
symbol time
AEMD W25U9A0OOMLH 2016-10-28 16:00:00 4.670000 4.670000 4.670000 4.670000 99.0
ASYS R735QTJ8XC9X 2016-10-28 16:00:00 4.580000 4.580000 4.520000 4.560000 1413.0
FTEKF R735QTJ8XC9X 2016-10-28 16:00:00 1.270000 1.280000 1.270000 1.280000 1213.0
GFN TJFSF5NSW38L 2016-10-28 16:00:00 4.300000 4.300000 4.300000 4.300000 67.0
GIGA R735QTJ8XC9X 2016-10-28 16:00:00 0.890000 0.890000 0.890000 0.890000 NaN
HGO TKM4N6E26J51 2016-10-28 16:00:00 0.183000 0.183000 0.183000 0.183000 100.0
JYNT VVDNE3ATPISL 2016-10-28 16:00:00 2.570000 2.570000 2.570000 2.570000 100.0
OCCF R735QTJ8XC9X 2016-10-28 16:00:00 2.800000 2.800000 2.800000 2.800000 100.0
PRSS V5BACZOYSIUD 2016-10-28 16:00:00 3.050000 3.050000 3.040000 3.040000 252.0
PZZI R735QTJ8XC9X 2016-10-28 16:00:00 2.760000 2.770000 2.760000 2.770000 93.0
SMSI R735QTJ8XC9X 2016-10-28 16:00:00 1.490000 1.490000 1.490000 1.490000 NaN
TSRI R735QTJ8XC9X 2016-10-28 16:00:00 5.344262 5.388798 5.344262 5.344262 337.0

The question is;

How can I extract the ticker from the symbol column........ I went with the first 3-4 letters but it doesnt match what I get from the stock_list list.

THanks in advance for your help

Update Backtest







If stock_list is a list of symbol object instead of the string ticker, the symbol index in the history data frame will be the string format of symbol object because Python dataframe can only take the string index not object. You can filter those symbol object in the data frame with

h2 = self.History(stock_list, 1, Resolution.Minute)
# get the symbol index in dataframe
symbols_in_df = h2.index.levels[0]
symbols = [i for i in stock_list if str(i) in symbols_in_df]
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