Skip to main content

Quantitative Investment Strategies (QIS) package implements Python analytics for visualisation of financial data, performance reporting, analysis of quantitative strategies

Project description

🚀 Quantitative Investment Strategies: QIS

qis package implements analytics for visualisation of financial data, performance reporting, factsheets and analysis of quantitative strategies.


📊 Metric 🔢 Value
PyPI Version PyPI
Python Versions Python
License License
CI Status CI

📈 Package Statistics

📊 Metric 🔢 Value
Total Downloads Total
Monthly Monthly
Weekly Weekly
GitHub Stars GitHub stars
GitHub Forks GitHub forks

Quantitative Investment Strategies: QIS

The package is split into 5 main modules with the dependency path increasing sequentially as follows.

  1. qis.utils is module containing low level utilities for operations with pandas, numpy, and datetimes.

  2. qis.perfstats is module for computing performance statistics and performance attribution including returns, volatilities, etc.

  3. qis.plots is module for plotting and visualization apis.

  4. qis.models is module containing statistical models including filtering and regressions.

  5. qis.portfolio is high level module for analysis, simulation, backtesting, and reporting of quant strategies. Function backtest_model_portfolio() in qis.portfolio.backtester.py takes instrument prices and simulated weights from a generic strategy and compute the total return, performance attribution, and risk analysis

qis.examples contains scripts with illustrations of QIS analytics.

qis.examples.factheets contains scripts with examples of factsheets for simulated and actual strategies, and cross-sectional analysis of backtests.

Table of contents

  1. Analytics
  2. Installation
  3. Examples
    1. Visualization of price data
    2. Multi assets factsheet
    3. Strategy factsheet
    4. Strategy benchmark factsheet
    5. Multi strategy factsheet
    6. Notebooks
  4. Contributions
  5. Updates
  6. ToDos
  7. Disclaimer

Installation

Install using

pip install qis

Upgrade using

pip install --upgrade qis

Close using

git clone https://github.com/ArturSepp/QuantInvestStrats.git

Core dependencies: python = ">=3.8", numba = ">=0.56.4", numpy = ">=1.22.4", scipy = ">=1.10", statsmodels = ">=0.13.5", pandas = ">=2.2.0", matplotlib = ">=3.2.2", seaborn = ">=0.12.2"

Optional dependencies: yfinance ">=0.1.38" (for getting test price data), pybloqs ">=1.2.13" (for producing html and pdf factsheets)

Examples

1. Visualization of price data

The script is located in qis.examples.performances (https://github.com/ArturSepp/QuantInvestStrats/blob/master/qis/examples/performances.py)

import matplotlib.pyplot as plt
import seaborn as sns
import yfinance as yf
import qis

# define tickers and fetch price data
tickers = ['SPY', 'QQQ', 'EEM', 'TLT', 'IEF', 'SHY', 'LQD', 'HYG', 'GLD']
prices = yf.download(tickers, start="2003-12-31", end=None, ignore_tz=True, auto_adjust=True)['Close'][tickers].dropna()

# plotting price data with minimum usage
with sns.axes_style("darkgrid"):
    fig, ax = plt.subplots(1, 1, figsize=(10, 7))
    qis.plot_prices(prices=prices, x_date_freq='YE', ax=ax)

image info

# 2-axis plot with drawdowns using sns styles
with sns.axes_style("darkgrid"):
    fig, axs = plt.subplots(2, 1, figsize=(10, 7), tight_layout=True)
    qis.plot_prices_with_dd(prices=prices, x_date_freq='YE', axs=axs)

image info

# plot risk-adjusted performance table with excess Sharpe ratio
ust_3m_rate = yf.download('^IRX', start="2003-12-31", end=None, ignore_tz=True, auto_adjust=True)['Close'].dropna() / 100.0
# set parameters for computing performance stats including returns vols and regressions
perf_params = qis.PerfParams(freq='ME', freq_reg='QE', rates_data=ust_3m_rate)
# perf_columns is list to display different perfomance metrics from enumeration PerfStat
fig = qis.plot_ra_perf_table(prices=prices,
                             perf_columns=[PerfStat.TOTAL_RETURN, PerfStat.PA_RETURN, PerfStat.PA_EXCESS_RETURN,
                                           PerfStat.VOL, PerfStat.SHARPE_RF0,
                                           PerfStat.SHARPE_EXCESS, PerfStat.SORTINO_RATIO, PerfStat.CALMAR_RATIO,
                                           PerfStat.MAX_DD, PerfStat.MAX_DD_VOL,
                                           PerfStat.SKEWNESS, PerfStat.KURTOSIS],
                             title=f"Risk-adjusted performance: {qis.get_time_period_label(prices, date_separator='-')}",
                             perf_params=perf_params)

image info

# add benchmark regression using excess returns for linear beta
# regression frequency is specified using perf_params.freq_reg
# regression alpha is multiplied using alpha_an_factor
fig, _ = qis.plot_ra_perf_table_benchmark(prices=prices,
                                          benchmark='SPY',
                                          perf_columns=[PerfStat.TOTAL_RETURN, PerfStat.PA_RETURN, PerfStat.PA_EXCESS_RETURN,
                                                        PerfStat.VOL, PerfStat.SHARPE_RF0,
                                                        PerfStat.SHARPE_EXCESS, PerfStat.SORTINO_RATIO, PerfStat.CALMAR_RATIO,
                                                        PerfStat.MAX_DD, PerfStat.MAX_DD_VOL,
                                                        PerfStat.SKEWNESS, PerfStat.KURTOSIS,
                                                        PerfStat.ALPHA_AN, PerfStat.BETA, PerfStat.R2],
                                          title=f"Risk-adjusted performance: {qis.get_time_period_label(prices, date_separator='-')} benchmarked with SPY",
                                          perf_params=perf_params)

image info

2. Multi assets factsheet

This report is adopted for reporting the risk-adjusted performance of several assets with the goal of cross-sectional comparision

Run example in qis.examples.factsheets.multi_assets.py https://github.com/ArturSepp/QuantInvestStrats/blob/master/qis/examples/factsheets/multi_assets.py

image info

3. Strategy factsheet

This report is adopted for report performance, risk, and trading statistics for either backtested or actual strategy with strategy data passed as PortfolioData object

Run example in qis.examples.factsheets.strategy.py https://github.com/ArturSepp/QuantInvestStrats/blob/master/qis/examples/factsheets/strategy.py

image info image info image info

4. Strategy benchmark factsheet

This report is adopted for report performance and marginal comparison of strategy vs a benchmark strategy (data for both are passed using individual PortfolioData object)

Run example in qis.examples.factsheets.strategy_benchmark.py https://github.com/ArturSepp/QuantInvestStrats/blob/master/qis/examples/factsheets/strategy_benchmark.py

image info

Brinson-Fachler performance attribution (https://en.wikipedia.org/wiki/Performance_attribution) image info

5. Multi strategy factsheet

This report is adopted to examine the sensitivity of backtested strategy to a parameter or set of parameters:

Run example in qis.examples.factsheets.multi_strategy.py https://github.com/ArturSepp/QuantInvestStrats/blob/master/qis/examples/factsheets/multi_strategy.py

image info

6. Notebooks

Recommended package to work with notebooks:

pip install notebook

Starting local server

jupyter notebook

Examples of using qis analytics jupyter notebooks are located here https://github.com/ArturSepp/QuantInvestStrats/blob/master/qis/examples/notebooks

Contributions

If you are interested in extending and improving QIS analytics, please consider contributing to the library.

I have found it is a good practice to isolate general purpose and low level analytics and visualizations, which can be outsourced and shared, while keeping the focus on developing high level commercial applications.

There are a number of requirements:

  • The code is Pep 8 compliant

  • Reliance on common Python data types including numpy arrays, pandas, and dataclasses.

  • Transparent naming of functions and data types with enough comments. Type annotations of functions and arguments is a must.

  • Each submodule has a unit test for core functions and a localised entry point to core functions.

  • Avoid "super" pythonic constructions. Readability is the priority.

Updates

30 December 2022, Version 1.0.1 released

08 July 2023, Version 2.0.1 released

Core Changes

  1. Portfolio optimization (qis.portfolio.optimisation) layer is removed with core functionality moved to a stand-alone Python package: Backtesting Optimal Portfolio (bop)
  • This allows to remove the dependency from cvxpy and sklearn packages and thus to simplify the dependency management for qis
  1. Added factsheet reporting using pybloqs package https://github.com/man-group/PyBloqs
  • Pybloqs is a versatile tool to create customised reporting using Matplotlib figures and table and thus leveraging QIS visualisation analytics
  1. New factsheets are added
  • Examples are added for the four type of reports:
    1. multi assets: report performance of several assets with goal of cross-sectional comparision: see qis.examples.factsheets.multi_asset.py
    2. strategy: report performance, risk, and trading statictics for either backtested or actual strategy with strategy data passed as PortfolioData object: see qis.examples.factsheets.strategy.py
    3. strategy vs benchmark: report performance and marginal comparison of strategy vs a benchmark strategy (data for both are passed using individual PortfolioData object): see qis.examples.factsheets.strategy_benchmark.py
    4. multi_strategy: report for a list of strategies with individual PortfolioData. This report is useful to examine the sensetivity of backtested strategy to a parameter or set of parameters: see qis.examples.factsheets.multi_strategy

ToDos

  1. Enhanced documentation and readme examples.

  2. Docstrings for key functions.

  3. Reporting analytics and factsheets generation enhancing to matplotlib.

Disclaimer

QIS package is distributed FREE & WITHOUT ANY WARRANTY under the GNU GENERAL PUBLIC LICENSE.

See the LICENSE.txt in the release for details.

Please report any bugs or suggestions by opening an issue.

.

BibTeX Citation

If you use BloombergFetch in your research, please cite it as:

@software{sepp2024qis,
  author={Sepp, Artur},
  title={Qua: A Python Package for Bloomberg Terminal Data Access},
  year={2024},
  url={https://github.com/ArturSepp/BloombergFetch},
  version={1.0.27}
}

BibTeX Citations for QIS (Quantitative Investment Strategies) Package

If you use QIS in your research, please cite it as:

@software{sepp2024qis,
  title={qis: Implementation of visualisation and reporting analytics for Quantitative Investment Strategies},
  author={Sepp, Artur},
  year={2024},
  url={https://github.com/ArturSepp/QuantInvestStrats}
}

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qis-4.0.4.tar.gz (345.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qis-4.0.4-py3-none-any.whl (427.1 kB view details)

Uploaded Python 3

File details

Details for the file qis-4.0.4.tar.gz.

File metadata

  • Download URL: qis-4.0.4.tar.gz
  • Upload date:
  • Size: 345.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for qis-4.0.4.tar.gz
Algorithm Hash digest
SHA256 ef68feaa60f548aec16a25562d223bcd03bec1f7ec046df975f76b109f6d8885
MD5 0be470933506713e0fb29cde9aca1bdf
BLAKE2b-256 cc2a99dcc8505fd526c200752ab95c610fa97631e00d682b9e9b37d5775aab65

See more details on using hashes here.

File details

Details for the file qis-4.0.4-py3-none-any.whl.

File metadata

  • Download URL: qis-4.0.4-py3-none-any.whl
  • Upload date:
  • Size: 427.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for qis-4.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 44192cd92e3cb35bb34f0f344cc3fda0c3bda26b0663f39025c73733968d572f
MD5 ac092c5d740f75b011095fd3843636ee
BLAKE2b-256 889c7286b187a013650de1c988b0f52dce9c176d0aac88ec6edc54c87cc3f29e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page