Skip to content

Commit

Permalink
Merge pull request #186 from binary-signal/main
Browse files Browse the repository at this point in the history
Fix for benchmark name when supplied by the user
  • Loading branch information
ranaroussi authored May 1, 2022
2 parents 546db90 + 2efc4e5 commit b82e191
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion quantstats/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,18 @@ def html(returns, benchmark=None, rf=0., grayscale=False,
# prepare timeseries
returns = _utils._prepare_returns(returns)
if benchmark is not None:
tpl = tpl.replace('{{benchmark_title}}', f"Benchmark is {benchmark} | ")

def get_benchmark_title(bench):
if isinstance(bench, str):
return bench
elif isinstance(bench, _pd.Series):
return bench.name
elif isinstance(bench, _pd.DataFrame):
return bench[bench.columns[0]].name
else:
raise ValueError("Can't infer benchmark title")

tpl = tpl.replace('{{benchmark_title}}', f"Benchmark is {get_benchmark_title(benchmark)} | ")
benchmark = _utils._prepare_benchmark(benchmark, returns.index, rf)
if match_dates is True:
returns, benchmark = _match_dates(returns, benchmark)
Expand Down

0 comments on commit b82e191

Please sign in to comment.