From bfc247071fa1b80772cb101f2b31b72b8227cabf Mon Sep 17 00:00:00 2001 From: ran Date: Mon, 2 May 2022 10:49:09 +0100 Subject: [PATCH] Added option to explicitly provide the benchmark title --- CHANGELOG.rst | 4 ++++ quantstats/reports.py | 19 ++++++++++--------- quantstats/version.py | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index daa25eeb..cee40642 100644 --- a/CHANGELOG.rst +++ b/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 diff --git a/quantstats/reports.py b/quantstats/reports.py index 21686dfb..1321c5fd 100644 --- a/quantstats/reports.py +++ b/quantstats/reports.py @@ -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") @@ -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: diff --git a/quantstats/version.py b/quantstats/version.py index 8ebb7b76..b907675f 100644 --- a/quantstats/version.py +++ b/quantstats/version.py @@ -1 +1 @@ -version = "0.0.55" +version = "0.0.56"