Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Pyfolio error - module 'empyrical.utils' has no attribute 'default_returns_func' #428

Open
eranhirs opened this issue Aug 5, 2018 · 3 comments

Comments

@eranhirs
Copy link

eranhirs commented Aug 5, 2018

Dear Catalyst Maintainers,

Description of Issue

Trying to use pyfolio with catalyst.
Specifically, the Full tear sheet report like in this example:
https://quantopian.github.io/pyfolio/notebooks/zipline_algo_example/

As documented here:
#73
You have to use pip install empyrical==0.2.2 otherwise I get the error
ImportError: cannot import name information_ratio

So I did and it solved that specific error.

What happened instead?

Now I get the error
{AttributeError}module 'empyrical.utils' has no attribute 'default_returns_func'

Reproduction Steps

  1. run pip install pyfolio
  2. run pip install empyrical==0.2.2
  3. Taking perf from catalyst def analyze, run import pyfolio and then pyfolio.create_full_tear_sheet(perf.returns, positions=perf.positions, transactions=perf.transactions)

What steps have you taken to resolve this already?

In this issue
quantopian/zipline#1855
It seems they solved this problem, which doesn't require downgrading empyrical.

Here is another user having the same problem as I do:
quantopian/empyrical#91

Anything else?

Catalyst should have documentation on adding pyfolio as it really seems as a great tool for visualizing the results.

@eranhirs
Copy link
Author

eranhirs commented Aug 5, 2018

Work in progress using pyfolio.create_full_tear_sheet.

Problems run into & fixed:

  1. pyfolio 0.7.0 is the latest working version.
  2. transactions requires reformatting, fixed using extract_transactions.
  3. transactions requires a symbol column, fixed with code below.
  4. benchmark_rets is required, otherwise it tries fetching from Yahoo Finance the data, fixed.
  5. create_full_tear_sheet only works with daily returns, fixed with code below.

Todo:

  1. positions requires a different format, for now I removed positions from the call.
  2. APPROX_BDAYS_PER_MONTH = 21 is incorrect for crypto.
  3. Check why results are different from catalyst results.

Here is the code so far:

transaction_df = extract_transactions(perf)
transaction_df['symbol'] = transaction_df['sid'].apply(lambda x: x.base_currency)
returns_daily = perf.returns.resample("D", how="ohlc")['close']
benchmark_returns_daily = perf.benchmark_period_return.resample("D", how="ohlc")['close']
pyfolio.create_full_tear_sheet(returns_daily, transactions=transaction_df, benchmark_rets=benchmark_returns_daily)

@sam31415
Copy link

sam31415 commented Aug 5, 2018

Does this help? https://forum.catalystcrypto.io/t/a-shot-at-pyfolio/89

@eranhirs
Copy link
Author

eranhirs commented Aug 6, 2018

Thanks @sam31415 this helps! Managed to use gen_round_trip_stats which is great 👍

In any case, it is still using pyfolio 0.7.0, ideally would like to upgrade to pyfolio 0.9.0 like described in the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants