pyfolio
pyfolio copied to clipboard
create_returns_tear_sheet gives a ValueError
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
~/.local/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)
~/.local/lib/python3.6/site-packages/pyfolio/tears.py in create_returns_tear_sheet(returns, positions, transactions, live_start_date, cone_std, benchmark_rets, bootstrap, turnover_denom, header_rows, return_fig)
524 bootstrap=bootstrap,
525 live_start_date=live_start_date,
--> 526 header_rows=header_rows)
527
528 plotting.show_worst_drawdown_periods(returns)
~/.local/lib/python3.6/site-packages/pyfolio/plotting.py in show_perf_stats(returns, factor_returns, positions, transactions, turnover_denom, live_start_date, bootstrap, header_rows)
589 positions=positions,
590 transactions=transactions,
--> 591 turnover_denom=turnover_denom)
592
593 date_rows = OrderedDict()
~/.local/lib/python3.6/site-packages/pyfolio/timeseries.py in perf_stats(returns, factor_returns, positions, transactions, turnover_denom)
724 stats = pd.Series()
725 for stat_func in SIMPLE_STAT_FUNCS:
--> 726 stats[STAT_FUNC_NAMES[stat_func.__name__]] = stat_func(returns)
727
728 if positions is not None:
~/.local/lib/python3.6/site-packages/empyrical/stats.py in calmar_ratio(returns, period, annualization)
573
574 max_dd = max_drawdown(returns=returns)
--> 575 if max_dd < 0:
576 temp = annual_return(
577 returns=returns,
/anaconda/lib/python3.6/site-packages/pandas/core/generic.py in __nonzero__(self)
1571 raise ValueError("The truth value of a {0} is ambiguous. "
1572 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1573 .format(self.__class__.__name__))
1574
1575 __bool__ = __nonzero__
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Hi,
I had the exact same issue but I later noticed that it was just my fault: instead of passing a pd.Series, I passed a pd.DataFrame for the "returns" parameter.
My pyfolio version is '0.9.0'
Hope it may help.
Thank you very much, I will try that solution.
On Mon, Dec 3, 2018 at 1:18 PM abk11 [email protected] wrote:
Hi,
I had the exact same issue but I later noticed that it was just my fault: instead of passing a pd.Series, I passed a pd.DataFrame for the "returns" parameter.
My pyfolio version is '0.9.0'
Hope it may help.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/quantopian/pyfolio/issues/581#issuecomment-443690814, or mute the thread https://github.com/notifications/unsubscribe-auth/AHMEpLEBQmrGMoGOMvdnuqIFKZtJyWIvks5u1RaZgaJpZM4YmDGl .
Would it makes sense to check the data that was loaded into 'create_returns_tear_sheet' and raise a more specific error message "returns are type pandas.core.frame.DataFrame and must be type pandas.core.series.Series"?
I had this same issue and it was not clear at all by the error message that the series should be passed as opposed to a data frame. A more meaningful error message would be very helpful. Thanks for the solution here.