Skip to main content

Analytics for quants

Project description

jQuantStats: Portfolio Analytics for Quants

PyPI version License Downloads Coverage CodeFactor Renovate enabled Rhiza

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:

  • Polars-native design with zero pandas runtime dependency
  • 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
  • Polars-native: Pure polars at runtime; pandas is not required and not supported as input

๐Ÿ“ฆ Installation

pip install jquantstats

For development:

pip install jquantstats[dev]

๐Ÿš€ Quick Start

If you have price series and position sizes (recommended):

import polars as pl
from jquantstats import Portfolio

prices = pl.DataFrame({
    "date": ["2023-01-01", "2023-01-02", "2023-01-03"],
    "Asset1": [100.0, 101.0, 99.5],
}).with_columns(pl.col("date").str.to_date())

positions = pl.DataFrame({
    "date": ["2023-01-01", "2023-01-02", "2023-01-03"],
    "Asset1": [1000.0, 1000.0, 1200.0],
}).with_columns(pl.col("date").str.to_date())

pf = Portfolio.from_cash_position(prices=prices, cash_position=positions, aum=1_000_000)

sharpe = pf.stats.sharpe()
fig = pf.plots.snapshot()  # call fig.show() to display

If you already have a returns series:

import polars as pl
from jquantstats import build_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())

data = build_data(returns=returns)

sharpe = data.stats.sharpe()
fig = data.plots.plot_snapshot(title="Portfolio Performance")  # call fig.show() to display

๐Ÿ—๏ธ Architecture

jQuantStats has two layered entry points:

Entry point 1 โ€” prices + positions
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
prices_df + positions_df + aum
        โ”‚
        โ–ผ
  Portfolio.from_cash_position(...)   โ† NAV compiler
        โ”‚
        โ”œโ”€โ”€ .stats.sharpe()           โ† full stats suite
        โ”œโ”€โ”€ .plots.snapshot()         โ† portfolio-specific plots
        โ”œโ”€โ”€ .report.full()            โ† HTML report
        โ””โ”€โ”€ .data                     โ† drop into Entry point 2 โ”€โ”€โ”
                                                                    โ”‚
Entry point 2 โ€” returns series                                      โ”‚
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€        โ”‚
returns_df [+ benchmark_df]  โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚
        โ–ผ
  build_data(returns=..., benchmark=...)   โ† Data object
        โ”‚
        โ”œโ”€โ”€ .stats.sharpe()           โ† full stats suite
        โ””โ”€โ”€ .plots.plot_snapshot()    โ† snapshot chart

Entry point 1 (Portfolio) is for active portfolios where you have price series and position sizes. It compiles the NAV curve and exposes the full analytics suite.

Entry point 2 (build_data) is for arbitrary return streams โ€” e.g. returns downloaded from a data vendor โ€” with optional benchmark comparison.

The two APIs are layered: portfolio.data returns a Data object, so you can always drop from a Portfolio into the returns-series API.

๐Ÿ“š Documentation

For detailed documentation, visit jQuantStats Documentation.

๐Ÿ”ง Requirements

  • Python 3.11+
  • numpy
  • polars
  • 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 MIT License - see the LICENSE 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.1.1.tar.gz (52.9 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.1.1-py3-none-any.whl (52.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jquantstats-0.1.1.tar.gz
Algorithm Hash digest
SHA256 feaf4a9016300fa7a44df22015ffe1bfd24e4fd9b3478c89ed8f1efd0dd8b9d8
MD5 7a0fc54ccede11ee1636199cd0bc4b1a
BLAKE2b-256 382412079e54a7d256b24649fafdd425d5625c3babd0dd0adf3d3c9a3f58f8a4

See more details on using hashes here.

Provenance

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

Publisher: rhiza_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.1.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for jquantstats-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0ec8126efc1a8d32a7c14ec34dd6f29208bad34533ae408c19a541ceb304ea6a
MD5 688f72ffd1e4d7dd3d7a8762b598e847
BLAKE2b-256 16e0e979b993998f7e44159e934d55873cc172e761615ccf1fb9b5d3121824c0

See more details on using hashes here.

Provenance

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

Publisher: rhiza_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