ranaroussi / quantstats

Portfolio analytics for quants, written in Python
Apache License 2.0
4.91k stars 851 forks source link

add prepare_returns inside prepare_benchmark and make_index #211

Closed BoudewijnKlijn closed 1 year ago

BoudewijnKlijn commented 2 years ago

This PR fixes an unexpected result when a ticker is compared with a benchmark.

If the ticker and the benchmark are identical, the metrics in the report should be identical as well.

In the basic report, the returns of the ticker are prepared: returns = _utils._prepare_returns(returns)

Hence, to get consistent results, the benchmark should also be prepared.

Code to show old benchmark gives inconsistent metrics

import quantstats as qs

qs.extend_pandas()
TICKER = 'SPY'
returns = qs.utils.download_returns(TICKER)

# Create report. Note inconsistent 'Cumulative Return'.
metrics = qs.reports.basic(returns, returns)