{"id":8574,"library":"quantstats","title":"QuantStats","description":"QuantStats is a Python library for portfolio analytics that enables quantitative analysts and portfolio managers to gain in-depth insights into their investment performance and risk metrics. It provides modules for calculating various statistics, generating plots, and creating comprehensive HTML reports. The library is actively maintained with frequent updates, with the current version being 0.0.81.","status":"active","version":"0.0.81","language":"en","source_language":"en","source_url":"https://github.com/ranaroussi/quantstats","tags":["finance","quantitative analysis","portfolio management","backtesting","risk metrics","performance analysis","trading","visualization"],"install":[{"cmd":"pip install quantstats","lang":"bash","label":"Install QuantStats"}],"dependencies":[{"reason":"Required Python version","package":"python","version":">=3.10"},{"reason":"Core data structures and manipulation","package":"pandas","version":">=1.5.0"},{"reason":"Numerical operations","package":"numpy","version":">=1.24.0"},{"reason":"Scientific computing functions","package":"scipy","version":">=1.11.0"},{"reason":"Plotting and visualization","package":"matplotlib","version":">=3.7.0"},{"reason":"Statistical data visualization","package":"seaborn","version":">=0.13.0"},{"reason":"Pretty-printing tabular data","package":"tabulate","version":">=0.9.0"},{"reason":"Used by qs.utils.download_returns for fetching financial data","package":"yfinance","version":">=0.2.40"},{"reason":"Optional, for interactive plots using plots.to_plotly()","package":"plotly","version":">=5.0.0","optional":true}],"imports":[{"note":"Standard import alias for brevity.","symbol":"quantstats","correct":"import quantstats as qs"},{"note":"Extends pandas DataFrames/Series with QuantStats metrics and plotting methods, allowing method chaining (e.g., `df.sharpe()`). Should be called after importing quantstats.","symbol":"extend_pandas","correct":"qs.extend_pandas()"}],"quickstart":{"code":"import quantstats as qs\nimport yfinance as yf\nimport pandas as pd\n\n# Extend pandas functionality with QuantStats methods\nqs.extend_pandas()\n\n# Download daily returns for a stock using yfinance\nticker = 'AAPL'\nstock_data = yf.download(ticker, start='2020-01-01', end='2023-12-31')\nreturns = stock_data['Adj Close'].pct_change().dropna()\n\n# Optionally, download benchmark returns\nbenchmark_ticker = 'SPY'\nbenchmark_data = yf.download(benchmark_ticker, start='2020-01-01', end='2023-12-31')\nbenchmark_returns = benchmark_data['Adj Close'].pct_change().dropna()\n\n# Calculate and print Sharpe Ratio\nsharpe_ratio = returns.sharpe()\nprint(f\"Sharpe Ratio for {ticker}: {sharpe_ratio:.4f}\")\n\n# Generate a full HTML report (opens in browser by default)\n# Ensure you have matplotlib and seaborn installed for plots\nqs.reports.html(returns, benchmark=benchmark_returns, title=f'{ticker} vs {benchmark_ticker} Performance', output='quantstats_report.html')","lang":"python","description":"This quickstart demonstrates how to import QuantStats, extend pandas DataFrames for easy access to metrics, download historical stock data using `yfinance`, calculate a basic performance metric like the Sharpe Ratio, and generate a comprehensive HTML tearsheet comparing a stock's performance against a benchmark."},"warnings":[{"fix":"Upgrade to version 0.0.80 or later. These issues were resolved by implementing lazy imports.","message":"Circular import errors (e.g., 'ImportError: cannot import name \"stats\" from partially initialized module \"quantstats\"') were prevalent in versions 0.0.78 and 0.0.79.","severity":"breaking","affected_versions":"0.0.78, 0.0.79"},{"fix":"Upgrade to version 0.0.81 or later. The typo was corrected in this release.","message":"A `NameError: name 'dd_get_stats' is not defined` occurred in `reports.full()` due to a typo in versions 0.0.78 and 0.0.79, preventing full report generation.","severity":"breaking","affected_versions":"0.0.78, 0.0.79"},{"fix":"Upgrade to version 0.0.78 or later, where `pct_change()` calls were updated to use `fill_method=None` or equivalent, suppressing the warning.","message":"Older versions of QuantStats might trigger `FutureWarning`s from pandas regarding the deprecated `fill_method` in `Series.pct_change()`. This could clutter console output.","severity":"deprecated","affected_versions":"<0.0.78"},{"fix":"Upgrade to version 0.0.75 or later. The library was updated to use modern pandas frequency aliases (e.g., '1ME' for month end) for compatibility.","message":"Pandas `FutureWarning`s related to deprecated frequency aliases (e.g., '1M' for monthly) were common in older versions, especially with pandas 2.0+.","severity":"deprecated","affected_versions":"<0.0.75"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"This was a known bug in `quantstats` versions 0.0.78 and 0.0.79. Upgrade your `quantstats` package to version 0.0.80 or newer: `pip install quantstats --upgrade`.","cause":"This error typically indicates a circular dependency issue during module loading, often triggered when `quantstats` itself tries to import a submodule that, in turn, attempts to import a parent module before it's fully initialized.","error":"ImportError: cannot import name 'stats' from partially initialized module 'quantstats' (most likely due to a circular import)"},{"fix":"This bug was fixed in `quantstats` version 0.0.81. Upgrade your package: `pip install quantstats --upgrade`.","cause":"This error occurs specifically when attempting to generate a full report using `qs.reports.full()` in certain versions of `quantstats` due to a mistyped internal function name.","error":"NameError: name 'dd_get_stats' is not defined"},{"fix":"This warning was addressed in `quantstats` version 0.0.78. Upgrade your `quantstats` package to this version or newer: `pip install quantstats --upgrade`.","cause":"This `FutureWarning` originates from pandas, indicating that `quantstats` functions using `pct_change()` with the implicit default `fill_method='pad'` are relying on deprecated behavior.","error":"FutureWarning: The default fill_method='pad' in Series.pct_change is deprecated and will be removed in a future version."},{"fix":"This warning was resolved in `quantstats` version 0.0.75 by updating internal usage to modern pandas frequency aliases (e.g., '1ME'). Upgrade your package: `pip install quantstats --upgrade`.","cause":"This `FutureWarning` is from pandas, indicating that `quantstats` or user code is using outdated frequency aliases (e.g., '1M') that are no longer recommended and will be removed.","error":"FutureWarning: The '1M' freq alias is deprecated and will be removed in a future version, use 'M' instead."}]}