【问题标题】:Running zipline causes urlopen error [Errno 11001] getaddrinfo failed运行 zipline 导致 urlopen 错误 [Errno 11001] getaddrinfo failed
【发布时间】:2017-07-01 09:03:56
【问题描述】:

我正在尝试通过终端运行zipline buyapple.py 示例,如here 所述:

zipline run -f ../../zipline/examples/buyapple.py --start 2000-1-1 --end 2014-1-1 -o buyapple_out.pickle

但它会导致以下错误:

request.py", line 1320, in do_open raise URLError(err) 

urllib.error.URLError: <urlopen error [Errno 11001] getaddrinfo failed>

有人知道怎么回事吗?

【问题讨论】:

    标签: python urllib urlopen zipline


    【解决方案1】:

    似乎它与雅虎的财务 API 有关。 我使用以下方法来解决此问题:

    pip 安装 pandas-datareader

    pip install fix-yahoo-finance-0.0.18.tar from here

    然后使用用户edmunch提供的以下代码修补zipline Benchmarks.py:

    import pandas as pd
    
    from six.moves.urllib_parse import urlencode
    
    import pandas_datareader as pdr #NEW
    import fix_yahoo_finance as yf #NEW
    yf.pdr_override()#NEW
    
    def get_benchmark_returns(symbol, start_date, end_date):
        print('NEW')
        df = pdr.data.get_data_yahoo(symbol, start=start_date, end=end_date)
        df.to_csv('{}_D1.csv'.format(symbol))
        return pd.read_csv('{}_D1.csv'.format(symbol),
            parse_dates=['Date'],
            index_col='Date',
            usecols=["Adj Close", "Date"],
            squeeze=True,  # squeeze tells pandas to make this a Series
                           # instead of a 1-column DataFrame
        ).sort_index().tz_localize('UTC').pct_change(1).iloc[1:]    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-26
      • 1970-01-01
      • 1970-01-01
      • 2020-01-28
      • 1970-01-01
      相关资源
      最近更新 更多