Skip to main content

Analytics for quants

Project description

jQuantStats: Portfolio Analytics for Quants

PyPI version License CI Downloads Coverage Status CodeFactor Renovate enabled

Open in GitHub Codespaces

๐Ÿ“Š Overview

jQuantStats is a Python library for portfolio analytics that helps quants and portfolio managers understand their performance through in-depth analytics and risk metrics. It provides tools for calculating various performance metrics and visualizing portfolio performance using interactive Plotly charts.

The library is inspired by QuantStats, but focuses on providing a clean, modern API with enhanced visualization capabilities. Key improvements include:

  • Support for both pandas and polars DataFrames
  • Modern interactive visualizations using Plotly
  • Comprehensive test coverage with pytest
  • Clean, well-documented API
  • Efficient data processing with polars

โœจ Features

  • Performance Metrics: Calculate key metrics like Sharpe ratio, Sortino ratio, drawdowns, volatility, and more
  • Risk Analysis: Analyze risk through metrics like Value at Risk (VaR), Conditional VaR, and drawdown analysis
  • Interactive Visualizations: Create interactive plots for portfolio performance, drawdowns, and return distributions
  • Benchmark Comparison: Compare your portfolio performance against benchmarks
  • Pandas & Polars Support: Work with either pandas or polars DataFrames as input

๐Ÿ“ฆ Installation

pip install jquantstats

For development:

pip install jquantstats[dev]

๐Ÿš€ Quick Start

>>> # Import jquantstats
>>> import polars as pl
>>> from jquantstats import build_data

>>> # Create sample returns data
>>> returns = pl.DataFrame({
...     "Date": ["2023-01-01", "2023-01-02", "2023-01-03"],
...     "Asset1": [0.01, -0.02, 0.03],
...     "Asset2": [0.02, 0.01, -0.01]
... }).with_columns(pl.col("Date").str.to_date())
>>> returns
shape: (3, 3)
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Date       โ”† Asset1 โ”† Asset2 โ”‚
โ”‚ ---        โ”† ---    โ”† ---    โ”‚
โ”‚ date       โ”† f64    โ”† f64    โ”‚
โ•žโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•โ•โ•ก
โ”‚ 2023-01-01 โ”† 0.01   โ”† 0.02   โ”‚
โ”‚ 2023-01-02 โ”† -0.02  โ”† 0.01   โ”‚
โ”‚ 2023-01-03 โ”† 0.03   โ”† -0.01  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

>>> # Basic usage
>>> data = build_data(returns=returns)
>>>
>>> # With benchmark and risk-free rate
>>> benchmark = pl.DataFrame({
...     "Date": ["2023-01-01", "2023-01-02", "2023-01-03"],
...     "Market": [0.005, -0.01, 0.02]
... }).with_columns(pl.col("Date").str.to_date())
>>> benchmark
shape: (3, 2)
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Date       โ”† Market โ”‚
โ”‚ ---        โ”† ---    โ”‚
โ”‚ date       โ”† f64    โ”‚
โ•žโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ชโ•โ•โ•โ•โ•โ•โ•โ•โ•ก
โ”‚ 2023-01-01 โ”† 0.005  โ”‚
โ”‚ 2023-01-02 โ”† -0.01  โ”‚
โ”‚ 2023-01-03 โ”† 0.02   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

>>> data = build_data(
...     returns=returns,
...     benchmark=benchmark,
...     rf=0.0002,  # risk-free rate (e.g., 0.02% per day)
... )

>>> # Calculate statistics
>>> sharpe = data.stats.sharpe()
>>> sharpe
{'Asset1': np.float64(4.909200099205072),
 'Asset2': np.float64(8.08795106197808),
 'Market': np.float64(6.113591415853696)}

>>> volatility = data.stats.volatility()
>>> volatility
{'Asset1': np.float64(0.4807979478602905),
 'Asset2': np.float64(0.2918332857414772),
 'Market': np.float64(0.286574597618142)}

>>> # Create visualizations
>>> fig = data.plots.plot_snapshot(title="Portfolio Performance")
>>> type(fig)
<class 'plotly.graph_objs._figure.Figure'>
>>> # End of example

๐Ÿ“š Documentation

For detailed documentation, visit jQuantStats Documentation.

๐Ÿ”ง Requirements

  • Python 3.10+
  • numpy
  • polars
  • pandas
  • plotly
  • scipy

๐Ÿ‘ฅ Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

โš–๏ธ License

This project is licensed under the Apache License 2.0 - see the LICENSE.txt file for details.

Project details


Download files

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

Source Distribution

jquantstats-0.0.25.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

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

jquantstats-0.0.25-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file jquantstats-0.0.25.tar.gz.

File metadata

  • Download URL: jquantstats-0.0.25.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for jquantstats-0.0.25.tar.gz
Algorithm Hash digest
SHA256 fe979a5b625faaecfa0cb86045a8c89da3039b019205496575e64cd5a31520a4
MD5 f7e8d0f91103852e8603831c372c5428
BLAKE2b-256 e5e3ac0cadb92baea585c30de2ff9703925f3d557fdc6c3b769280e95b98b3b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for jquantstats-0.0.25.tar.gz:

Publisher: release.yml on tschm/jquantstats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jquantstats-0.0.25-py3-none-any.whl.

File metadata

  • Download URL: jquantstats-0.0.25-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for jquantstats-0.0.25-py3-none-any.whl
Algorithm Hash digest
SHA256 9e54182cdad08527a162b73f964e0a8656957e1f7ce67743e5fbaf05843ef04f
MD5 e7ab6fe5f8ca91f4f8434290ffd37528
BLAKE2b-256 59cc7e21f3fd46ac77df2c35dd29a1e8b5688279178090b90bc743576bf342c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for jquantstats-0.0.25-py3-none-any.whl:

Publisher: release.yml on tschm/jquantstats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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