quantstats
quantstats copied to clipboard
Inconsistent results strategy vs. benchmark
When you compare the returns of a strategy with a benchmark, results are slightly different when the input returns for the strategy and the benchmark are identical.
Expected When returns of strategy and benchmark are identical, the report should give back identical performance metrics.
Solution When the benchmark is prepared, it yields the same results.
See minimum code below:
import quantstats as qs
# extend pandas functionality with metrics, etc.
qs.extend_pandas()
# fetch the daily returns for a stock
TICKER = 'SPY'
returns = qs.utils.download_returns(TICKER)
# prepare returns
prepared_returns = qs.utils._prepare_returns(returns)
# Create report to observe differences.
metrics = qs.reports.basic(returns, returns) # different cumulative return for strategy and benchmark
metrics = qs.reports.basic(returns, TICKER) # different cumulative return for strategy and benchmark
metrics = qs.reports.basic(returns, prepared_returns) # __SAME__ cumulative return for strategy and benchmark
Interesting