Skip to main content

Python version PyPi version PyPi status PyPi downloads CodeFactor Star this repo Follow BotSpot on twitter

Fork of Original QuantStats by Ran Aroussi, Maintained by Lumiwealth BotSpot

This is a forked version of the original QuantStats library by Ran Aroussi. The original library can be found at https://github.com/ranaroussi/quantstats

This forked version is maintained by Lumiwealth BotSpot. For more information, visit https://github.com/Lumiwealth/quantstats_lumi or https://botspot.trade.

This forked version was created because it seems that the original library is no longer being maintained. The original library has a number of issues and pull requests that have been open for a long time and have not been addressed. This forked version aims to address some of these issues and pull requests.

This forked version is created and maintained by the Lumiwealth team. We are a team of data scientists and software engineers who are passionate about quantitative finance and algorithmic trading. We use QuantStats in our daily work with the Lumibot library and we want to make sure that QuantStats is a reliable and well-maintained library.

If you're interested in learning how to make your own trading algorithms, check out our Lumibot library at https://github.com/Lumiwealth/lumibot and check out our courses at https://lumiwealth.com

QuantStats Lumi: Portfolio analytics for quants

QuantStats Lumi is a Python library that performs portfolio profiling, allowing quants and portfolio managers to understand their performance better by providing them with in-depth analytics and risk metrics.

Changelog »

QuantStats is comprised of 3 main modules:

  1. quantstats.stats - for calculating various performance metrics, like Sharpe ratio, Win rate, Volatility, etc.
  2. quantstats.plots - for visualizing performance, drawdowns, rolling statistics, monthly returns, etc.
  3. quantstats.reports - for generating metrics reports, batch plotting, and creating tear sheets that can be saved as an HTML file.

Here's an example of a simple tear sheet analyzing a strategy:

Quick Start

Install QuantStats Lumi using pip:

$ pip install quantstats-lumi
%matplotlib inline
import quantstats_lumi as qs

# extend pandas functionality with metrics, etc.
qs.extend_pandas()

# fetch the daily returns for a stock
stock = qs.utils.download_returns('META')

# show sharpe ratio
qs.stats.sharpe(stock)

# or using extend_pandas() :)
stock.sharpe()

Output:

0.8135304438803402

Visualize stock performance

qs.plots.snapshot(stock, title='Facebook Performance', show=True)

# can also be called via:
# stock.plot_snapshot(title='Facebook Performance', show=True)

Output:

Snapshot plot

Creating a report

You can create 7 different report tearsheets:

  1. qs.reports.metrics(mode='basic|full', ...) - shows basic/full metrics
  2. qs.reports.plots(mode='basic|full', ...) - shows basic/full plots
  3. qs.reports.basic(...) - shows basic metrics and plots
  4. qs.reports.full(...) - shows full metrics and plots
  5. qs.reports.html(...) - generates a complete report as html

Let' create an html tearsheet

# (benchmark can be a pandas Series or ticker)
qs.reports.html(stock, "SPY")

Output will generate something like this:

HTML tearsheet

(view original html file)

Machine-readable tearsheet metrics

quantstats_lumi also exposes a machine-readable tearsheet summary payload:

payload = qs.reports.metrics_json(
    stock,
    benchmark="SPY",
    summary_only=True,
)

Key points:

  • payload["scalar_metrics"] is the canonical summary metric dictionary.
  • Percentage-style metrics are stored as raw decimals in JSON (0.0369, not "3.69%").
  • The monthly downside row is named Worst 1-Month Return.
  • Custom metrics can be appended with custom_metrics={...} and are merged into both the HTML tearsheet table and tearsheet_metrics.json.

See the full machine-readable contract:

To view a complete list of available methods, run

[f for f in dir(qs.stats) if f[0] != '_']
['avg_loss',
 'avg_return',
 'avg_win',
 'best',
 'cagr',
 'calmar',
 'common_sense_ratio',
 'comp',
 'compare',
 'compsum',
 'conditional_value_at_risk',
 'consecutive_losses',
 'consecutive_wins',
 'cpc_index',
 'cvar',
 'drawdown_details',
 'expected_return',
 'expected_shortfall',
 'exposure',
 'gain_to_pain_ratio',
 'geometric_mean',
 'ghpr',
 'greeks',
 'implied_volatility',
 'information_ratio',
 'kelly_criterion',
 'kurtosis',
 'max_drawdown',
 'monthly_returns',
 'outlier_loss_ratio',
 'outlier_win_ratio',
 'outliers',
 'payoff_ratio',
 'profit_factor',
 'profit_ratio',
 'r2',
 'r_squared',
 'rar',
 'recovery_factor',
 'remove_outliers',
 'risk_of_ruin',
 'risk_return_ratio',
 'rolling_greeks',
 'ror',
 'sharpe',
 'skew',
 'sortino',
 'adjusted_sortino',
 'tail_ratio',
 'to_drawdown_series',
 'ulcer_index',
 'ulcer_performance_index',
 'upi',
 'utils',
 'value_at_risk',
 'var',
 'volatility',
 'win_loss_ratio',
 'win_rate',
 'worst']
[f for f in dir(qs.plots) if f[0] != '_']
['daily_returns',
 'distribution',
 'drawdown',
 'drawdowns_periods',
 'earnings',
 'histogram',
 'log_returns',
 'monthly_heatmap',
 'returns',
 'rolling_beta',
 'rolling_sharpe',
 'rolling_sortino',
 'rolling_volatility',
 'snapshot',
 'yearly_returns']

*** Full documenttion coming soon ***

In the meantime, you can get insights as to optional parameters for each method, by using Python's help method:

help(qs.stats.conditional_value_at_risk)
Help on function conditional_value_at_risk in module quantstats.stats:

conditional_value_at_risk(returns, sigma=1, confidence=0.99)
    calculats the conditional daily value-at-risk (aka expected shortfall)
    quantifies the amount of tail risk an investment

Installation

Install using pip:

$ pip install quantstats-lumi --upgrade --no-cache-dir

Install using conda:

$ conda install -c lumiwealth quantstats-lumi # Or your specific channel / remove if not applicable

Requirements

Questions?

This is a new library... If you find a bug, please open an issue in this repository.

If you'd like to contribute, a great place to look is the issues marked with help-wanted.

For more information about Lumiwealth BotSpot, visit https://botspot.trade.

Known Issues

For some reason, I couldn't find a way to tell seaborn not to return the monthly returns heatmap when instructed to save - so even if you save the plot (by passing savefig={...}) it will still show the plot.

Legal Stuff

QuantStats Lumi is distributed under the Apache Software License. See the LICENSE.txt file in the release for details.

Testing

To run the test suite, make sure you have pytest installed, then run:

pytest

This will automatically discover and run all tests in the repository.

P.S.

Please drop us a note with any feedback you have.

Lumiwealth BotSpot https://github.com/Lumiwealth/quantstats_lumi https://botspot.trade

Metadata

Release files for quantstats-lumi 1.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quantstats-lumi 1.1.5
File Size Uploaded
quantstats_lumi-1.1.5.tar.gz 68.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for quantstats-lumi 1.1.5
File Interpreter ABI Platform
quantstats_lumi-1.1.5-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 130.4 kB

Release files / quantstats_lumi-1.1.5.tar.gz

Download URL quantstats_lumi-1.1.5.tar.gz
Size 68.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ab53017d7856ba03c50dd7edb3b4f9bca92176556b006e5b4365ea76ec4207e0
BLAKE2b-256 checksum
How to use checksums
1d255425fd7d2232d7ad1c4af19a585fcce84e0223c11c34afb33e63c91dd6e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / quantstats_lumi-1.1.5-py2.py3-none-any.whl

Download URL quantstats_lumi-1.1.5-py2.py3-none-any.whl
Size 62.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
623855e0dafb22ebf232d9477fc4f2b42be1f44f10fda535fb65b38f57e8549b
BLAKE2b-256 checksum
How to use checksums
21cf48a85de9a6c6d1ed8434e27dfd7488b37bc668ffd1e710fac3119db208b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

1.1.5 This release

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.0

2 release files

1.0.1

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.73

2 release files

0.0.72

2 release files

0.0.71

2 release files

0.0.70

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page