Skip to content

Commit

Permalink
Simplified benchmark_title
Browse files Browse the repository at this point in the history
  • Loading branch information
ranaroussi authored May 2, 2022
1 parent a9bb2ca commit 666eecd
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions quantstats/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,17 @@ def html(returns, benchmark=None, rf=0., grayscale=False,

# prepare timeseries
returns = _utils._prepare_returns(returns)

if benchmark is not None:

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_title = "Benchmark"
if isinstance(benchmark, str):
benchmark_title = benchmark
elif isinstance(benchmark, _pd.Series):
benchmark_title = benchmark.name
elif isinstance(benchmark, _pd.DataFrame):
benchmark_title = benchmark[benchmark.columns[0]].name

tpl = tpl.replace('{{benchmark_title}}', f"Benchmark is {benchmark_title.upper()} | ")
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 666eecd

Please sign in to comment.