Skip to content

Commit

Permalink
Added option to explicitly provide the benchmark title
Browse files Browse the repository at this point in the history
  • Loading branch information
ranaroussi committed May 2, 2022
1 parent 666eecd commit bfc2470
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
@@ -1,6 +1,10 @@
Change Log
===========

0.0.56
-----
- Added option to explicitly provide the benchmark title via `benchmark_title=...`

0.0.55
-----
- Fix for benchmark name in html report when supplied by the user
Expand Down
19 changes: 10 additions & 9 deletions quantstats/reports.py
Expand Up @@ -58,7 +58,7 @@ def _match_dates(returns, benchmark):
def html(returns, benchmark=None, rf=0., grayscale=False,
title='Strategy Tearsheet', output=None, compounded=True,
periods_per_year=252, download_filename='quantstats-tearsheet.html',
figfmt='svg', template_path=None, match_dates=False):
figfmt='svg', template_path=None, match_dates=False, **kwargs):

if output is None and not _utils._in_notebook():
raise ValueError("`file` must be specified")
Expand All @@ -74,14 +74,15 @@ def html(returns, benchmark=None, rf=0., grayscale=False,
returns = _utils._prepare_returns(returns)

if benchmark is not None:
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

benchmark_title = kwargs.get('benchmark_title', 'Benchmark')
if kwargs.get('benchmark_title') is None:
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:
Expand Down
2 changes: 1 addition & 1 deletion quantstats/version.py
@@ -1 +1 @@
version = "0.0.55"
version = "0.0.56"

0 comments on commit bfc2470

Please sign in to comment.