QuantStats


NameQuantStats JSON
Version 0.0.64 PyPI version JSON
download
home_pagehttps://github.com/ranaroussi/quantstats
SummaryPortfolio analytics for quants
upload_time2024-10-25 23:26:14
maintainerNone
docs_urlNone
authorRan Aroussi
requires_pythonNone
licenseApache Software License
keywords quant algotrading algorithmic-trading quantitative-trading quantitative-analysis algo-trading visualization plotting
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            .. image:: https://img.shields.io/badge/python-3.6+-blue.svg?style=flat
    :target: https://pypi.python.org/pypi/quantstats
    :alt: Python version

.. image:: https://img.shields.io/pypi/v/quantstats.svg?maxAge=60
    :target: https://pypi.python.org/pypi/quantstats
    :alt: PyPi version

.. image:: https://img.shields.io/pypi/status/quantstats.svg?maxAge=60
    :target: https://pypi.python.org/pypi/quantstats
    :alt: PyPi status

.. image:: https://img.shields.io/pypi/dm/quantstats.svg?maxAge=2592000&label=installs&color=%2327B1FF
    :target: https://pypi.python.org/pypi/quantstats
    :alt: PyPi downloads

.. image:: https://www.codefactor.io/repository/github/ranaroussi/quantstats/badge
    :target: https://www.codefactor.io/repository/github/ranaroussi/quantstats
    :alt: CodeFactor

.. image:: https://img.shields.io/github/stars/ranaroussi/quantstats.svg?style=social&label=Star&maxAge=60
    :target: https://github.com/ranaroussi/quantstats
    :alt: Star this repo

.. image:: https://img.shields.io/twitter/follow/aroussi.svg?style=social&label=Follow&maxAge=60
    :target: https://twitter.com/aroussi
    :alt: Follow me on twitter

\

QuantStats: Portfolio analytics for quants
==========================================

**QuantStats** 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 ยป <./CHANGELOG.rst>`__

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
===========

.. code:: python

    %matplotlib inline
    import quantstats 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:

.. code:: text

    0.8135304438803402


Visualize stock performance
~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

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

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

Output:

.. image:: https://github.com/ranaroussi/quantstats/blob/main/docs/snapshot.jpg?raw=true
    :alt: 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

.. code:: python

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

Output will generate something like this:

.. image:: https://github.com/ranaroussi/quantstats/blob/main/docs/report.jpg?raw=true
    :alt: HTML tearsheet

(`view original html file <https://rawcdn.githack.com/ranaroussi/quantstats/main/docs/tearsheet.html>`_)


To view a complete list of available methods, run
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    [f for f in dir(qs.stats) if f[0] != '_']


.. code:: text

	['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']

.. code:: python

    [f for f in dir(qs.plots) if f[0] != '_']

.. code:: text

	['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:

.. code:: python

    help(qs.stats.conditional_value_at_risk)

.. code:: text

	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``:

.. code:: bash

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


Install using ``conda``:

.. code:: bash

    $ conda install -c ranaroussi quantstats


Requirements
------------

* `Python <https://www.python.org>`_ >= 3.5+
* `pandas <https://github.com/pydata/pandas>`_ (tested to work with >=0.24.0)
* `numpy <http://www.numpy.org>`_ >= 1.15.0
* `scipy <https://www.scipy.org>`_ >= 1.2.0
* `matplotlib <https://matplotlib.org>`_ >= 3.0.0
* `seaborn <https://seaborn.pydata.org>`_ >= 0.9.0
* `tabulate <https://bitbucket.org/astanin/python-tabulate>`_ >= 0.8.0
* `yfinance <https://github.com/ranaroussi/yfinance>`_ >= 0.1.38
* `plotly <https://plot.ly/>`_ >= 3.4.1 (optional, for using ``plots.to_plotly()``)

Questions?
----------

This is a new library... If you find a bug, please
`open an issue <https://github.com/ranaroussi/quantstats/issues>`_
in this repository.

If you'd like to contribute, a great place to look is the
`issues marked with help-wanted <https://github.com/ranaroussi/quantstats/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22>`_.


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** is distributed under the **Apache Software License**. See the `LICENSE.txt <./LICENSE.txt>`_ file in the release for details.


P.S.
------------

Please drop me a note with any feedback you have.

**Ran Aroussi**

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ranaroussi/quantstats",
    "name": "QuantStats",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "quant algotrading algorithmic-trading quantitative-trading quantitative-analysis algo-trading visualization plotting",
    "author": "Ran Aroussi",
    "author_email": "ran@aroussi.com",
    "download_url": "https://files.pythonhosted.org/packages/2c/fa/6954a2b52d2a9ab995e67e3446234022b5f8a5bf5fd9006467fca4971ba3/quantstats-0.0.64.tar.gz",
    "platform": "any",
    "description": ".. image:: https://img.shields.io/badge/python-3.6+-blue.svg?style=flat\n    :target: https://pypi.python.org/pypi/quantstats\n    :alt: Python version\n\n.. image:: https://img.shields.io/pypi/v/quantstats.svg?maxAge=60\n    :target: https://pypi.python.org/pypi/quantstats\n    :alt: PyPi version\n\n.. image:: https://img.shields.io/pypi/status/quantstats.svg?maxAge=60\n    :target: https://pypi.python.org/pypi/quantstats\n    :alt: PyPi status\n\n.. image:: https://img.shields.io/pypi/dm/quantstats.svg?maxAge=2592000&label=installs&color=%2327B1FF\n    :target: https://pypi.python.org/pypi/quantstats\n    :alt: PyPi downloads\n\n.. image:: https://www.codefactor.io/repository/github/ranaroussi/quantstats/badge\n    :target: https://www.codefactor.io/repository/github/ranaroussi/quantstats\n    :alt: CodeFactor\n\n.. image:: https://img.shields.io/github/stars/ranaroussi/quantstats.svg?style=social&label=Star&maxAge=60\n    :target: https://github.com/ranaroussi/quantstats\n    :alt: Star this repo\n\n.. image:: https://img.shields.io/twitter/follow/aroussi.svg?style=social&label=Follow&maxAge=60\n    :target: https://twitter.com/aroussi\n    :alt: Follow me on twitter\n\n\\\n\nQuantStats: Portfolio analytics for quants\n==========================================\n\n**QuantStats** 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.\n\n`Changelog \u00bb <./CHANGELOG.rst>`__\n\nQuantStats is comprised of 3 main modules:\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n1. ``quantstats.stats`` - for calculating various performance metrics, like Sharpe ratio, Win rate, Volatility, etc.\n2. ``quantstats.plots`` - for visualizing performance, drawdowns, rolling statistics, monthly returns, etc.\n3. ``quantstats.reports`` - for generating metrics reports, batch plotting, and creating tear sheets that can be saved as an HTML file.\n\nHere's an example of a simple tear sheet analyzing a strategy:\n\nQuick Start\n===========\n\n.. code:: python\n\n    %matplotlib inline\n    import quantstats as qs\n\n    # extend pandas functionality with metrics, etc.\n    qs.extend_pandas()\n\n    # fetch the daily returns for a stock\n    stock = qs.utils.download_returns('META')\n\n    # show sharpe ratio\n    qs.stats.sharpe(stock)\n\n    # or using extend_pandas() :)\n    stock.sharpe()\n\nOutput:\n\n.. code:: text\n\n    0.8135304438803402\n\n\nVisualize stock performance\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n    qs.plots.snapshot(stock, title='Facebook Performance', show=True)\n\n    # can also be called via:\n    # stock.plot_snapshot(title='Facebook Performance', show=True)\n\nOutput:\n\n.. image:: https://github.com/ranaroussi/quantstats/blob/main/docs/snapshot.jpg?raw=true\n    :alt: Snapshot plot\n\n\nCreating a report\n~~~~~~~~~~~~~~~~~\n\nYou can create 7 different report tearsheets:\n\n1. ``qs.reports.metrics(mode='basic|full\", ...)`` - shows basic/full metrics\n2. ``qs.reports.plots(mode='basic|full\", ...)`` - shows basic/full plots\n3. ``qs.reports.basic(...)`` - shows basic metrics and plots\n4. ``qs.reports.full(...)`` - shows full metrics and plots\n5. ``qs.reports.html(...)`` - generates a complete report as html\n\nLet' create an html tearsheet\n\n.. code:: python\n\n    (benchmark can be a pandas Series or ticker)\n    qs.reports.html(stock, \"SPY\")\n\nOutput will generate something like this:\n\n.. image:: https://github.com/ranaroussi/quantstats/blob/main/docs/report.jpg?raw=true\n    :alt: HTML tearsheet\n\n(`view original html file <https://rawcdn.githack.com/ranaroussi/quantstats/main/docs/tearsheet.html>`_)\n\n\nTo view a complete list of available methods, run\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n    [f for f in dir(qs.stats) if f[0] != '_']\n\n\n.. code:: text\n\n\t['avg_loss',\n\t 'avg_return',\n\t 'avg_win',\n\t 'best',\n\t 'cagr',\n\t 'calmar',\n\t 'common_sense_ratio',\n\t 'comp',\n\t 'compare',\n\t 'compsum',\n\t 'conditional_value_at_risk',\n\t 'consecutive_losses',\n\t 'consecutive_wins',\n\t 'cpc_index',\n\t 'cvar',\n\t 'drawdown_details',\n\t 'expected_return',\n\t 'expected_shortfall',\n\t 'exposure',\n\t 'gain_to_pain_ratio',\n\t 'geometric_mean',\n\t 'ghpr',\n\t 'greeks',\n\t 'implied_volatility',\n\t 'information_ratio',\n\t 'kelly_criterion',\n\t 'kurtosis',\n\t 'max_drawdown',\n\t 'monthly_returns',\n\t 'outlier_loss_ratio',\n\t 'outlier_win_ratio',\n\t 'outliers',\n\t 'payoff_ratio',\n\t 'profit_factor',\n\t 'profit_ratio',\n\t 'r2',\n\t 'r_squared',\n\t 'rar',\n\t 'recovery_factor',\n\t 'remove_outliers',\n\t 'risk_of_ruin',\n\t 'risk_return_ratio',\n\t 'rolling_greeks',\n\t 'ror',\n\t 'sharpe',\n\t 'skew',\n\t 'sortino',\n\t 'adjusted_sortino',\n\t 'tail_ratio',\n\t 'to_drawdown_series',\n\t 'ulcer_index',\n\t 'ulcer_performance_index',\n\t 'upi',\n\t 'utils',\n\t 'value_at_risk',\n\t 'var',\n\t 'volatility',\n\t 'win_loss_ratio',\n\t 'win_rate',\n\t 'worst']\n\n.. code:: python\n\n    [f for f in dir(qs.plots) if f[0] != '_']\n\n.. code:: text\n\n\t['daily_returns',\n\t 'distribution',\n\t 'drawdown',\n\t 'drawdowns_periods',\n\t 'earnings',\n\t 'histogram',\n\t 'log_returns',\n\t 'monthly_heatmap',\n\t 'returns',\n\t 'rolling_beta',\n\t 'rolling_sharpe',\n\t 'rolling_sortino',\n\t 'rolling_volatility',\n\t 'snapshot',\n\t 'yearly_returns']\n\n\n**\\*\\*\\* Full documenttion coming soon \\*\\*\\***\n\nIn the meantime, you can get insights as to optional parameters for each method, by using Python's ``help`` method:\n\n.. code:: python\n\n    help(qs.stats.conditional_value_at_risk)\n\n.. code:: text\n\n\tHelp on function conditional_value_at_risk in module quantstats.stats:\n\n\tconditional_value_at_risk(returns, sigma=1, confidence=0.99)\n\t    calculats the conditional daily value-at-risk (aka expected shortfall)\n\t    quantifies the amount of tail risk an investment\n\n\nInstallation\n------------\n\nInstall using ``pip``:\n\n.. code:: bash\n\n    $ pip install quantstats --upgrade --no-cache-dir\n\n\nInstall using ``conda``:\n\n.. code:: bash\n\n    $ conda install -c ranaroussi quantstats\n\n\nRequirements\n------------\n\n* `Python <https://www.python.org>`_ >= 3.5+\n* `pandas <https://github.com/pydata/pandas>`_ (tested to work with >=0.24.0)\n* `numpy <http://www.numpy.org>`_ >= 1.15.0\n* `scipy <https://www.scipy.org>`_ >= 1.2.0\n* `matplotlib <https://matplotlib.org>`_ >= 3.0.0\n* `seaborn <https://seaborn.pydata.org>`_ >= 0.9.0\n* `tabulate <https://bitbucket.org/astanin/python-tabulate>`_ >= 0.8.0\n* `yfinance <https://github.com/ranaroussi/yfinance>`_ >= 0.1.38\n* `plotly <https://plot.ly/>`_ >= 3.4.1 (optional, for using ``plots.to_plotly()``)\n\nQuestions?\n----------\n\nThis is a new library... If you find a bug, please\n`open an issue <https://github.com/ranaroussi/quantstats/issues>`_\nin this repository.\n\nIf you'd like to contribute, a great place to look is the\n`issues marked with help-wanted <https://github.com/ranaroussi/quantstats/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22>`_.\n\n\nKnown Issues\n------------\n\nFor some reason, I couldn't find a way to tell seaborn not to return the\nmonthly returns heatmap when instructed to save - so even if you save the plot (by passing ``savefig={...}``) it will still show the plot.\n\n\nLegal Stuff\n------------\n\n**QuantStats** is distributed under the **Apache Software License**. See the `LICENSE.txt <./LICENSE.txt>`_ file in the release for details.\n\n\nP.S.\n------------\n\nPlease drop me a note with any feedback you have.\n\n**Ran Aroussi**\n",
    "bugtrack_url": null,
    "license": "Apache Software License",
    "summary": "Portfolio analytics for quants",
    "version": "0.0.64",
    "project_urls": {
        "Homepage": "https://github.com/ranaroussi/quantstats"
    },
    "split_keywords": [
        "quant",
        "algotrading",
        "algorithmic-trading",
        "quantitative-trading",
        "quantitative-analysis",
        "algo-trading",
        "visualization",
        "plotting"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cc74b9cf9a2cf911d48c120635b71281a3a28323e97813e7a4d459b6acfd6447",
                "md5": "ce484fa308d7f20cdc50910ba42ec72d",
                "sha256": "2dc6c2c54e0d879fc31e854c6015047366e30042d01892e127dcb07797e91107"
            },
            "downloads": -1,
            "filename": "QuantStats-0.0.64-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ce484fa308d7f20cdc50910ba42ec72d",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 45751,
            "upload_time": "2024-10-25T23:26:12",
            "upload_time_iso_8601": "2024-10-25T23:26:12.546584Z",
            "url": "https://files.pythonhosted.org/packages/cc/74/b9cf9a2cf911d48c120635b71281a3a28323e97813e7a4d459b6acfd6447/QuantStats-0.0.64-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2cfa6954a2b52d2a9ab995e67e3446234022b5f8a5bf5fd9006467fca4971ba3",
                "md5": "f6ce0e453850b805854247c4e395758d",
                "sha256": "a1e2533d751805d47303d8c053192fca12820b06f38b6a171bda2177ac8824cf"
            },
            "downloads": -1,
            "filename": "quantstats-0.0.64.tar.gz",
            "has_sig": false,
            "md5_digest": "f6ce0e453850b805854247c4e395758d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 41166,
            "upload_time": "2024-10-25T23:26:14",
            "upload_time_iso_8601": "2024-10-25T23:26:14.778092Z",
            "url": "https://files.pythonhosted.org/packages/2c/fa/6954a2b52d2a9ab995e67e3446234022b5f8a5bf5fd9006467fca4971ba3/quantstats-0.0.64.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-25 23:26:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ranaroussi",
    "github_project": "quantstats",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "quantstats"
}
        
Elapsed time: 0.38232s