Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reports.metrics failed to calculate Omega: KeyError: 'returns' #378

Open
josephchenhk opened this issue Nov 8, 2024 · 0 comments
Open

Comments

@josephchenhk
Copy link

There is a bug in the current release (0.0.63 & 0.0.64):

In line 862 of reports.py, when calculating Omega, the passing param is df['returns']. However, when passing a returns with multiple columns, the column names are converted to ['returns_1', 'returns_2', ...]. Therefore we will see the error below:

File /opt/kernel/lib/python3.9/site-packages/quantstats/reports.py:862, in metrics(returns, benchmark, rf, display, mode, sep, compounded, periods_per_year, prepare_returns, match_dates, **kwargs)
    860     metrics["Smart Sortino/√2"] = metrics["Smart Sortino"] / _sqrt(2)
    861     # metrics['Prob. Smart Sortino/√2 Ratio %'] = _stats.probabilistic_adjusted_sortino_ratio(df, rf, win_year, False, True) * pct
--> 862 metrics["Omega"] = _stats.omega(df["returns"], rf, 0.0, win_year)
    864 metrics["~~~~~~~~"] = blank
    865 metrics["Max Drawdown %"] = blank

File /opt/kernel/lib/python3.9/site-packages/pandas/core/frame.py:3807, in DataFrame.__getitem__(self, key)
   3805 if self.columns.nlevels > 1:
   3806     return self._getitem_multilevel(key)
-> 3807 indexer = self.columns.get_loc(key)
   3808 if is_integer(indexer):
   3809     indexer = [indexer]

File /opt/kernel/lib/python3.9/site-packages/pandas/core/indexes/base.py:3804, in Index.get_loc(self, key, method, tolerance)
   3802     return self._engine.get_loc(casted_key)
   3803 except KeyError as err:
-> 3804     raise KeyError(key) from err
   3805 except TypeError:
   3806     # If we have a listlike key, _check_indexing_error will raise
   3807     #  InvalidIndexError. Otherwise we fall through and re-raise
   3808     #  the TypeError.
   3809     self._check_indexing_error(key)

KeyError: 'returns'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant