quantopian / pyfolio

Portfolio and risk analytics in Python
https://quantopian.github.io/pyfolio
Apache License 2.0
5.69k stars 1.78k forks source link

import problem with pyfolio 0.8 #539

Closed stnatter closed 6 years ago

stnatter commented 6 years ago

Hello!

installed pyfolio like this: conda install -c conda-forge pyfolio

when trying: import pyfolio as pf i get the following traceback:


ImportError Traceback (most recent call last)

in () 1 import pandas as pd ----> 2 import pyfolio as pf 3 get_ipython().run_line_magic('matplotlib', 'inline') ~/miniconda3/lib/python3.6/site-packages/pyfolio/__init__.py in () 1 import warnings 2 ----> 3 from . import utils 4 from . import timeseries 5 from . import pos ~/miniconda3/lib/python3.6/site-packages/pyfolio/utils.py in () 22 from IPython.display import display 23 ---> 24 import empyrical.utils 25 from os import environ 26 from .deprecate import deprecated ~/miniconda3/lib/python3.6/site-packages/empyrical/__init__.py in () 19 del get_versions 20 ---> 21 from .stats import ( 22 cum_returns, 23 cum_returns_final, ~/miniconda3/lib/python3.6/site-packages/empyrical/stats.py in () 21 from six import iteritems 22 ---> 23 from .utils import nanmean, nanstd, nanmin, up, down, roll 24 from .periods import ANNUALIZATION_FACTORS, APPROX_BDAYS_PER_YEAR 25 from .periods import DAILY, WEEKLY, MONTHLY, YEARLY ~/miniconda3/lib/python3.6/site-packages/empyrical/utils.py in () 23 from pandas.tseries.offsets import BDay 24 ---> 25 from pandas_datareader import data as web 26 27 try: ~/miniconda3/lib/python3.6/site-packages/pandas_datareader/__init__.py in () 1 from ._version import get_versions ----> 2 from .data import (DataReader, Options, get_components_yahoo, 3 get_dailysummary_iex, get_data_enigma, get_data_famafrench, 4 get_data_fred, get_data_google, get_data_moex, 5 get_data_morningstar, get_data_quandl, get_data_stooq, ~/miniconda3/lib/python3.6/site-packages/pandas_datareader/data.py in () 12 ImmediateDeprecationError 13 from pandas_datareader.famafrench import FamaFrenchReader ---> 14 from pandas_datareader.fred import FredReader 15 from pandas_datareader.google.daily import GoogleDailyReader 16 from pandas_datareader.google.options import Options as GoogleOptions ~/miniconda3/lib/python3.6/site-packages/pandas_datareader/fred.py in () ----> 1 from pandas.core.common import is_list_like 2 from pandas import concat, read_csv 3 4 from pandas_datareader.base import _BaseReader 5 ImportError: cannot import name 'is_list_like' Python 3.6.5 any help would be appreciated. Regards, Steffen
eigenfoo commented 6 years ago

Hello Steffen!

What version of pandas_datareader are you using? It appears that there is this bug on the current version, but will only be included in a future release (v0.7.0). The thread also describes some workarounds you can implement in the meantime.

FYI, you should be aware that we have a pull request for empyrical to deprecate all functionality relying on pandas-datareader, so hopefully this will not be a problem going forwards.

stnatter commented 6 years ago

Hihi. Am using pandas_datareader v0.6.0. Thanks for the quick response!

eigenfoo commented 6 years ago

I see. That's the latest version, but unfortunately it still contains the bug I described. This is not a problem with pyfolio, but with the upstream pandas-datareader dependency. We're fixing that up, but in the meantime I can only suggest that you try out the solution described on Stack Overflow.

stnatter commented 6 years ago

i applied the suggest fix and it works. thanks for your help. When you expect to have the pandas-datareader dependency removed? The one thing i really do not like about pyfolio is the very long list of dependencies which make it fickle.

eigenfoo commented 6 years ago

We're hoping to merge the PR as soon as possible. And yes, dependencies are an unfortunate necessity.

@twiecki looks like we can close this issue.

stnatter commented 6 years ago

I have one more question if you don't mind me asking. I get the output of the full tear sheet within the output cell where i need to scroll. Is there any way to get the full output without having to scroll in the cell?

stnatter commented 6 years ago

And another problem I encountered with the bayesian tearsheet which I think is because of Pandas 0.23 which if very fickle about tz aware and naive datetime. I pass in columns from a pd.df with returns and benchmark returns. The index is a DatetimeIndex with dtype='datetime64[ns]'. I am getting: TypeError: Cannot compare tz-naive and tz-aware datetime-like objects.

The traceback:

TypeError Traceback (most recent call last)

in () ----> 1 pf.create_bayesian_tear_sheet(ret.equity, benchmark_rets = ret.spy, live_start_date = ret.index[-40]) ~/miniconda3/lib/python3.6/site-packages/pyfolio/plotting.py in call_w_context(*args, **kwargs) 50 if set_context: 51 with plotting_context(), axes_style(): ---> 52 return func(*args, **kwargs) 53 else: 54 return func(*args, **kwargs) ~/miniconda3/lib/python3.6/site-packages/pyfolio/tears.py in create_bayesian_tear_sheet(returns, benchmark_rets, live_start_date, samples, return_fig, stoch_vol) 1093 1094 live_start_date = ep.utils.get_utc_timestamp(live_start_date) -> 1095 df_train = returns.loc[returns.index < live_start_date] 1096 df_test = returns.loc[returns.index >= live_start_date] 1097 ~/miniconda3/lib/python3.6/site-packages/pandas/core/indexes/datetimes.py in wrapper(self, other) 113 if isinstance(other, datetime): 114 # GH#18435 strings get a pass from tzawareness compat --> 115 self._assert_tzawareness_compat(other) 116 117 other = _to_m8(other, tz=self.tz) ~/miniconda3/lib/python3.6/site-packages/pandas/core/indexes/datetimes.py in _assert_tzawareness_compat(self, other) 667 elif self.tz is None: 668 if other_tz is not None: --> 669 raise TypeError('Cannot compare tz-naive and tz-aware ' 670 'datetime-like objects.') 671 elif other_tz is None: TypeError: Cannot compare tz-naive and tz-aware datetime-like objects.
stnatter commented 6 years ago

works when i make the index timezone aware with ret.index = ret.index.tz_localize(pytz.utc)

eigenfoo commented 6 years ago

I'm unsure what you mean by scroll. All tear sheets are very long, so you would have to scroll no matter what. Perhaps if you clarify your question I could help. Maybe saving the tear sheets as jpg images would help?

As to the tz problem, it's a very common problem when dealing with pandas. It's not a bug with pyfolio, it's a feature in pandas: it is there to avoid ambiguity. It forces you to be explicit about your data.

stnatter commented 6 years ago

Never mind. I saved the file as jpg indeed. Thanks or your help. And thanks for this amazing software. I do have one suggestion though. You might want to consider to make pyfolio less US equity centric. Common benchmarks are Hedge Fund performance indices and 60/40 portfolios (60% equity and 40% Bonds). Of course showing a beta with SP500 is fine but the way you show the Fama-French beta will be useless for many people (or is there a r way to change that already?).

eigenfoo commented 6 years ago

Thank you! It's good to hear that this library is useful to somebody :)

@twiecki please close this issue