quantopian / pyfolio

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

zipline_algo_example.ipynb does not work. #368

Closed hkopp closed 7 years ago

hkopp commented 7 years ago

Everything works up to the command

pf.create_full_tear_sheet(returns, positions=positions, transactions=transactions, live_start_date='2009-10-22', round_trips=True)

There, i get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-c157a656c557> in <module>()
      1 pf.create_full_tear_sheet(returns, positions=positions, transactions=transactions,
----> 2                           live_start_date='2009-10-22', round_trips=True)

/home/hjgk/venv/lib64/python3.5/site-packages/pyfolio/tears.py in create_full_tear_sheet(returns, positions, transactions, market_data, benchmark_rets, slippage, live_start_date, sector_mappings, bayesian, round_trips, estimate_intraday, hide_positions, cone_std, bootstrap, unadjusted_returns, set_context)
    168         benchmark_rets=benchmark_rets,
    169         bootstrap=bootstrap,
--> 170         set_context=set_context)
    171 
    172     create_interesting_times_tear_sheet(returns,

/home/hjgk/venv/lib64/python3.5/site-packages/pyfolio/plotting.py in call_w_context(*args, **kwargs)
     54         if set_context:
     55             with context():
---> 56                 return func(*args, **kwargs)
     57         else:
     58             return func(*args, **kwargs)

/home/hjgk/venv/lib64/python3.5/site-packages/pyfolio/tears.py in create_returns_tear_sheet(returns, positions, live_start_date, cone_std, benchmark_rets, bootstrap, return_fig)
    355 
    356     plotting.plot_rolling_sharpe(
--> 357         returns, ax=ax_rolling_sharpe)
    358 
    359     plotting.plot_rolling_fama_french(

/home/hjgk/venv/lib64/python3.5/site-packages/pyfolio/plotting.py in plot_rolling_sharpe(returns, rolling_window, legend_loc, ax, **kwargs)
    907 
    908     rolling_sharpe_ts = timeseries.rolling_sharpe(
--> 909         returns, rolling_window)
    910     rolling_sharpe_ts.plot(alpha=.7, lw=3, color='orangered', ax=ax,
    911                            **kwargs)

/home/hjgk/venv/lib64/python3.5/site-packages/pyfolio/timeseries.py in rolling_sharpe(returns, rolling_sharpe_window)
   1004     return returns.rolling(rolling_sharpe_window).mean() \
   1005         / returns.rolling(rolling_sharpe_window).std() \
-> 1006         * np.sqrt(APPROX_BDAYS_PER_YEAR)
   1007 
   1008 

/home/hjgk/venv/lib64/python3.5/site-packages/pandas/core/generic.py in __getattr__(self, name)
   2358                 return self[name]
   2359             raise AttributeError("'%s' object has no attribute '%s'" %
-> 2360                                  (type(self).__name__, name))
   2361 
   2362     def __setattr__(self, name, value):

AttributeError: 'Series' object has no attribute 'rolling'

I strongly assume the problem is, that rolling is time-series aware since pandas 0.19.0 see here, but in the setup.py pyfolio only requires 'pandas>=0.18.0'

My current version of pandas is 0.17.0 My version of pyfolio is:

In [8]: pf._version.get_versions()

Out[8]: 
{'dirty': False,
 'error': None,
 'full-revisionid': '3dcb13fa259ee2a32a8406b22d3860fe6b1d0e7f',
 'version': 'v0.7.0'}
gusgordon commented 7 years ago

Thanks for pointing this out - seems like you're right.

hkopp commented 7 years ago

If you tell me against which branch I should do my pull-request, then I can fix it myself.

gusgordon commented 7 years ago

Awesome, thanks! You can just use master, it's up to date.

yankees714 commented 6 years ago

Went back and investigated this - the issue here is not with rolling being time-series aware, but that the method wasn't yet added to Series. This happened in 0.18, so >=0.18 should be fine, 0.17.0 won't work.

http://pandas.pydata.org/pandas-docs/version/0.18.0/whatsnew.html#window-functions-are-now-methods