Skip to main content

Toying with quantstats

Project description

jQuantStats: Portfolio analytics for quants

PyPI version License: Apache 2.0 CI 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.

The library is inspired by and currently exposes a subset of the functionality of QuantStats, focusing on providing a clean, modern API with enhanced visualization capabilities using Plotly.

We have made the following changes when compared to quantstats:

  • added tests (based on pytest), pre-commit hooks and github ci/cd workflows
  • removed a direct dependency on yfinance to inject data
  • moved all graphical output to plotly and removed the matplotlib dependency
  • removed some statistical metrics but intend to bring them back
  • moved to Marimo for demos
  • gave up on the very tight coupling with pandas

Along the way we broke downwards compatibility with quantstats but the underlying usage pattern is too different. Users familiar with Dataclasses may find the chosen path appealing. A data class is constructed using the build_data function. This function is essentially the only viable entry point into jquantstats. It constructs and returns a _Data object which exposes plots and stats via its member attributes.

At this early stage the user would have to define a benchmark and set the underlying risk-free rate.

Features

  • Performance Metrics: Calculate key metrics like Sharpe ratio, Sortino ratio, drawdowns, volatility, and many more
  • Risk Analysis: Analyze risk through metrics like Value at Risk (VaR), Conditional VaR, and drawdown analysis
  • Visualization: Create interactive plots for portfolio performance, drawdowns, return distributions, and monthly heatmaps
  • Benchmark Comparison: Compare your portfolio performance against benchmarks

Installation

pip install jquantstats

For development:

pip install jquantstats[dev]

Quick Start

import pandas as pd
from jquantstats.api import build_data

# Create a Data object from returns
returns = pd.DataFrame(...)  # Your returns data

# Basic usage
data = build_data(returns=returns)

# With benchmark and risk-free rate
benchmark = pd.Series(...)  # Your benchmark returns
data = build_data(
    returns=returns,
    benchmark=benchmark,
    rf=0.02,      # risk-free rate (e.g., 2% annual rate)
    nperiods=252  # number of trading days per year
)

# Calculate statistics
sharpe = data.stats.sharpe()
volatility = data.stats.volatility()

# Create visualizations
fig = data.plots.plot_snapshot(title="Portfolio Performance")
fig.show()

# Monthly returns heatmap
fig = data.plots.monthly_heatmap()
fig.show()

Documentation

For detailed documentation, visit jQuantStats Documentation.

Requirements

  • Python 3.10+
  • numpy
  • pandas
  • scipy
  • plotly
  • kaleido (for static image export)

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.2.tar.gz (14.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.0.2-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jquantstats-0.0.2.tar.gz
  • Upload date:
  • Size: 14.9 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.2.tar.gz
Algorithm Hash digest
SHA256 e8aabe44e6fcf7bf2899a8733164433ad9d3a16d207e1e5a6e58f9b9501c63ec
MD5 7c7a64b3f48edcef319b9d3d6c0e4ee2
BLAKE2b-256 53a54630d1f7080f9b7f5092a8b2b6a3a73acc70d0f5d7c6d5379add89b26ebc

See more details on using hashes here.

Provenance

The following attestation bundles were made for jquantstats-0.0.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: jquantstats-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 16.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6f5ba399fa377bd9b97c919e1d9206d5e51f3261b112d093d0bc118a01196e94
MD5 514edf28dd11e3f0e660bc9084af5bd9
BLAKE2b-256 7fd42144380f5283d371f8ab68d8d68a6538d43d0d9ebc92f711056b77bf5f2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for jquantstats-0.0.2-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