Skip to content

Commit

Permalink
added benchmark name to column
Browse files Browse the repository at this point in the history
  • Loading branch information
ranaroussi committed Apr 23, 2022
1 parent 0f0bde4 commit 98362f9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions quantstats/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,13 @@ def metrics(returns, benchmark=None, rf=0., display=True,

win_year, _ = _get_trading_periods(periods_per_year)

if benchmark is not None \
and isinstance(benchmark, _pd.DataFrame) and len(benchmark.columns) > 1:
raise ValueError("`benchmark` must be a pandas Series, "
"but a multi-column DataFrame was passed")
benchmark_col = 'Benchmark'
if benchmark is not None:
if isinstance(benchmark, str):
benchmark_col = f'Benchmark ({benchmark.upper()})'
elif isinstance(benchmark, _pd.DataFrame) and len(benchmark.columns) > 1:
raise ValueError("`benchmark` must be a pandas Series, "
"but a multi-column DataFrame was passed")

blank = ['']

Expand Down Expand Up @@ -588,7 +591,7 @@ def metrics(returns, benchmark=None, rf=0., display=True,
metrics = metrics.T

if "benchmark" in df:
metrics.columns = ['Strategy', 'Benchmark']
metrics.columns = ['Strategy', benchmark_col]
else:
metrics.columns = ['Strategy']

Expand Down

0 comments on commit 98362f9

Please sign in to comment.