Closed gahabana closed 1 year ago
⚡ ipython ^[[APython 3.11.2 (main, Feb 16 2023, 03:15:23) [Clang 14.0.0 (clang-1400.0.29.202)] Type 'copyright', 'credits' or 'license' for more information IPython 8.9.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import json ...: import ffn ...: ...: # ffn.get returns a pandas dataframe of market data. ...: data = ffn.get( ...: 'tsla,spot,nflx,nke,addyy', ...: start='2019-01-01', ...: end='2020-12-31' ...: ) ...: print(data.head()) ...: stats = data.calc_stats() ...: print(stats.display()) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[1], line 5 2 import ffn 4 # ffn.get returns a pandas dataframe of market data. ----> 5 data = ffn.get( 6 'tsla,spot,nflx,nke,addyy', 7 start='2019-01-01', 8 end='2020-12-31' 9 ) 10 print(data.head()) 11 stats = data.calc_stats() File /usr/local/lib/python3.11/site-packages/decorator.py:232, in decorate.<locals>.fun(*args, **kw) 230 if not kwsyntax: 231 args, kw = fix(args, kw, sig) --> 232 return caller(func, *(extras + args), **kw) File /usr/local/lib/python3.11/site-packages/ffn/utils.py:34, in _memoize(func, *args, **kw) 32 return cache[key] 33 else: ---> 34 cache[key] = result = func(*args, **kw) 35 return result File /usr/local/lib/python3.11/site-packages/ffn/data.py:76, in get(tickers, provider, common_dates, forward_fill, clean_tickers, column_names, ticker_field_sep, mrefresh, existing, **kwargs) 74 # call provider - check if supports memoization 75 if hasattr(provider, "mcache"): ---> 76 data[ticker] = provider(ticker=t, field=f, mrefresh=mrefresh, **kwargs) 77 else: 78 data[ticker] = provider(ticker=t, field=f, **kwargs) File /usr/local/lib/python3.11/site-packages/decorator.py:232, in decorate.<locals>.fun(*args, **kw) 230 if not kwsyntax: 231 args, kw = fix(args, kw, sig) --> 232 return caller(func, *(extras + args), **kw) File /usr/local/lib/python3.11/site-packages/ffn/utils.py:34, in _memoize(func, *args, **kw) 32 return cache[key] 33 else: ---> 34 cache[key] = result = func(*args, **kw) 35 return result File /usr/local/lib/python3.11/site-packages/ffn/data.py:140, in yf(ticker, field, start, end, mrefresh) 137 if field is None: 138 field = "Adj Close" --> 140 tmp = pdata.get_data_yahoo(ticker, start=start, end=end) 142 if tmp is None: 143 raise ValueError("failed to retrieve data for %s:%s" % (ticker, field)) File /usr/local/lib/python3.11/site-packages/pandas_datareader/data.py:80, in get_data_yahoo(*args, **kwargs) 79 def get_data_yahoo(*args, **kwargs): ---> 80 return YahooDailyReader(*args, **kwargs).read() File /usr/local/lib/python3.11/site-packages/pandas_datareader/base.py:253, in _DailyBaseReader.read(self) 251 # If a single symbol, (e.g., 'GOOG') 252 if isinstance(self.symbols, (string_types, int)): --> 253 df = self._read_one_data(self.url, params=self._get_params(self.symbols)) 254 # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT']) 255 elif isinstance(self.symbols, DataFrame): File /usr/local/lib/python3.11/site-packages/pandas_datareader/yahoo/daily.py:153, in YahooDailyReader._read_one_data(self, url, params) 151 try: 152 j = json.loads(re.search(ptrn, resp.text, re.DOTALL).group(1)) --> 153 data = j["context"]["dispatcher"]["stores"]["HistoricalPriceStore"] 154 except KeyError: 155 msg = "No data fetched for symbol {} using {}" TypeError: string indices must be integers, not 'str'
https://github.com/pmorissette/ffn/issues/185