Skip to content

Commit

Permalink
Merge pull request #2 from binary-signal/binary-signal-patch-1
Browse files Browse the repository at this point in the history
Fix for benchmark name displayed not correctly
  • Loading branch information
binary-signal authored May 1, 2022
2 parents 546db90 + 6c8633d commit 2efc4e5
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 2efc4e5

Please sign in to comment.