Dear All,
The statement pf.create_simple_tear_sheet(df['strategy_returns'].diff()) returns the error
, returns the error.
`/home/enri/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/utils.py:440: UserWarning: Yahoo Finance read failed: 'date', falling back to Google
warnings.warn(
KeyError Traceback (most recent call last)
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3360 try:
-> 3361 return self._engine.get_loc(casted_key)
3362 except KeyError as err:
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'date'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/utils.py in get_symbol_returns_from_yahoo(symbol, start, end)
435 px = web.get_data_yahoo(symbol, start=start, end=end)
--> 436 px['date'] = pd.to_datetime(px['date'])
437 px.set_index('date', drop=False, inplace=True)
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pandas/core/frame.py in getitem(self, key)
3457 return self._getitem_multilevel(key)
-> 3458 indexer = self.columns.get_loc(key)
3459 if is_integer(indexer):
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
3362 except KeyError as err:
-> 3363 raise KeyError(key) from err
3364
KeyError: 'date'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
/tmp/ipykernel_3857/3291042158.py in
1 import pyfolio as pf
----> 2 pf.create_simple_tear_sheet(df['strategy_returns'].diff())
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pyfolio/tears.py in create_simple_tear_sheet(returns, positions, transactions, benchmark_rets, slippage, estimate_intraday, live_start_date)
291
292 if benchmark_rets is None:
--> 293 benchmark_rets = utils.get_symbol_rets('SPY')
294
295 if (slippage is not None) and (transactions is not None):
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pyfolio/utils.py in get_symbol_rets(symbol, start, end)
596 """
597
--> 598 return SETTINGS['returns_func'](symbol,
599 start=start,
600 end=end)
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pyfolio/deprecate.py in wrapper(*args, **kwargs)
41 stacklevel=stacklevel
42 )
---> 43 return fn(*args, **kwargs)
44 return wrapper
45 return deprecated_dec
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/pyfolio/utils.py in default_returns_func(symbol, start, end)
399 - See full explanation in tears.create_full_tear_sheet (returns).
400 """
--> 401 return empyrical.utils.default_returns_func(symbol, start=None, end=None)
402
403
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/deprecate.py in wrapper(*args, **kwargs)
41 stacklevel=stacklevel
42 )
---> 43 return fn(*args, **kwargs)
44 return wrapper
45 return deprecated_dec
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/utils.py in default_returns_func(symbol, start, end)
483 if symbol == 'SPY':
484 filepath = data_path('spy.csv')
--> 485 rets = get_returns_cached(filepath,
486 get_symbol_returns_from_yahoo,
487 end,
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/deprecate.py in wrapper(*args, **kwargs)
41 stacklevel=stacklevel
42 )
---> 43 return fn(*args, **kwargs)
44 return wrapper
45 return deprecated_dec
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/utils.py in get_returns_cached(filepath, update_func, latest_dt, **kwargs)
322
323 if update_cache:
--> 324 returns = update_func(**kwargs)
325 try:
326 ensure_directory(cache_dir())
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/deprecate.py in wrapper(*args, **kwargs)
41 stacklevel=stacklevel
42 )
---> 43 return fn(*args, **kwargs)
44 return wrapper
45 return deprecated_dec
~/anaconda3/envs/yfinance1/lib/python3.9/site-packages/empyrical/utils.py in get_symbol_returns_from_yahoo(symbol, start, end)
441 'Yahoo Finance read failed: {}, falling back to Google'.format(e),
442 UserWarning)
--> 443 px = web.get_data_google(symbol, start=start, end=end)
444 rets = px[['Close']].pct_change().dropna()
445
AttributeError: module 'pandas_datareader.data' has no attribute 'get_data_google'`
When importing from yahoo using yfinance or datareader, the DataFrame's index tag is named 'Date'. The problem seems to point to what should be named 'date'.
I have made the modification of this name in the DataFrame and the problem continues. How can I fix this problem?. Thanks in advanced.