简体   繁体   English

Python Finance:get_data_yahoo 未检索数据

[英]Python Finance: get_data_yahoo Not Retrieving Data

I ran this code about a year ago and it was working fine.大约一年前我运行了这段代码,它运行良好。 Now it has stopped working, and I think it has to do with the get_data_yahoo function.现在它已经停止工作,我认为它与 get_data_yahoo 函数有关。 Here is part of the code I am trying to run:这是我尝试运行的部分代码:

pd.options.display.width = 0

stocklist = si.tickers_sp500()
index_name = '^GSPC'  # S&P 500: ^GSPC  Dow Jones: ^DJI   Nasdaq: ^IXIC

# Initiate stock index
n = -1

for stock in stocklist:
    n += 1

    # Set a time delay between each stock
    time.sleep(0.25)

    # Inform user which stock is being evaluated
    print("\nPulling {} with Index {}".format(stock, n))

    # Set 1-year time duration starting from 365 days ago today
    start_date = datetime.datetime.now() - datetime.timedelta(days=365)
    end_date = datetime.date.today()

    # Download stock data for set time duration
    # (Optional??) stock = [stock + '.AX' for stock in stocklist]
    df = pdr.get_data_yahoo(stock, start=start_date, end=end_date)

Now this is returning no data.现在这不返回任何数据。 What am I missing?我错过了什么?

Probably the syntax of the library has changed.可能库的语法已经改变。 I changed your code and tried to request a few 10 shares.我更改了您的代码并尝试请求几个 10 股。 After 40, I stopped it myself. 40岁以后,我自己停止了。 It seems to me that there is no need to abuse and request data often and not so much.在我看来,没有必要经常滥用和请求数据,而不是太多。 And also reduced the depth of the request by four days.并且还将请求的深度减少了四天。 It is quite possible, if you request deep data, that you will come across a stock that is not traded and the script will shut down (I have seen questions like this).如果您请求深度数据,很有可能您会遇到未交易的股票并且脚本将关闭(我见过这样的问题)。

import pandas_datareader.data as web
import yahoo_fin.stock_info as si
import pandas as pd
import datetime
import time

pd.options.display.width = 0

stocklist = si.tickers_sp500()
index_name = '^GSPC'  # S&P 500: ^GSPC  Dow Jones: ^DJI   Nasdaq: ^IXIC
n = -1

for stock in stocklist:
    n += 1

    # Set a time delay between each stock
    time.sleep(0.25)

    # Inform user which stock is being evaluated
    print("\nPulling {} with Index {}".format(stock, n))

    # Set 1-year time duration starting from 365 days ago today
    start_date = datetime.datetime.now() - datetime.timedelta(days=4)
    end_date = datetime.date.today()

    df = web.DataReader(stock, 'yahoo', start=start_date, end=end_date)
    print(df)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM