Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Issue with data.history on stock list

Hello All,

When I try to get a stock list historical prices through data.history, I get the following error:

context.stocks = algo.pipeline_output('pipe').index.tolist()

context.symbols = []  
    for stock in context.stocks:  
       context.symbols.append(stock.symbol)

prices = pd.DataFrame([data.history(context.symbols, 'price', 100, '1d')])  

ValueError: invalid literal for int() with base 10: 'UTX'

I first thought that it was caused by a single stock, so I used try/except, but I then realized that the error occured on about half of the list.
I don't understand since I'm using symbols... Anyone encoutered this before?

3 responses

Anyone ?

Same issue here, have tried searching the forums but none worked. Anyone else has the same error?

    fast=12  
    slow=26  
    sig=9  
    period = fast+slow+sig  
    stk = []  
    for stock in result.index:  
        stk.append(stock.symbol)  
    prices = data.history(stk, 'price', bar_count= period, frequency='1d')  

The data.history method expects an asset or an iterable (eg a list or series) of assets. An asset is an object. It's not the ticker symbol. In the code above stk is just a list of symbols. Assuming result.index is the index of a pipeline, that is all you need. It's already the asset objects and can be iterated. So, something like this should work

    prices = data.history(result.index, 'price', bar_count= period, frequency='1d')  

There is no need to create a separate list and the following code can be deleted

    for stock in result.index:  
        stk.append(stock.symbol)

There is more detail on the data.history method in the docs. Check it out here. Good luck.

(This same question was also answered in a separate post https://www.quantopian.com/posts/valueerror-invalid-literal-for-int-with-base-10)

Disclaimer

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 Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian 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.