Skip to main content

Standard financial plots

Project description

finance plots

Matplotlib plots and performance tables for financial return series, price paths, and technical-indicator panels.

Build Status codecov License PyPI

Overview

finance-plots is the presentation layer for the finance stack. It accepts Narwhals-compatible inputs such as pandas, Polars, numpy, and other supported series-like objects, then returns ordinary matplotlib figures or Great Tables objects that can be saved, embedded in notebooks, or composed into tearsheets.

The initial release focuses on a compact, useful surface:

  • Return/risk plots for cumulative returns, rolling volatility, rolling Sharpe, rolling beta/correlation, benchmark scatter, drawdowns, and period-return views.
  • Technical-indicator plots for price overlays, secondary-axis indicators, and indicator sub-panels.
  • Performance summary tables backed by great-tables.

Install

pip install finance-plots

The gallery and documentation examples use the released data/calculation stack:

pip install "finance-plots[examples]"

Quick Start

Generate deterministic prices with finance-datagen, compute returns with finance-calcs, and plot them with finance-plots.

from datetime import datetime, timezone

import polars as pl
from finance_datagen import generate_prices

import finance_calcs as fc
import finance_plots as fp

start_ms = int(datetime(2021, 1, 4, tzinfo=timezone.utc).timestamp() * 1000)
prices = generate_prices(symbol="ACME", seed=7, start_ms=start_ms)
returns = prices.with_columns(
    fc.simple_returns(pl.col("price")).alias("ret"),
).select("ret").drop_nulls()["ret"]

fig = fp.plot_rolling_returns(returns)

Current Plot Catalog

Function Use it for
plot_returns(returns) Simple cumulative return path
plot_rolling_returns(returns, benchmark=None, live_start=None) Cumulative return path with optional benchmark and out-of-sample shading
plot_rolling_volatility(returns, window=63) Rolling annualized volatility
plot_rolling_sharpe(returns, window=63) Rolling annualized Sharpe ratio
plot_rolling_beta(returns, benchmark, window=63) Rolling beta versus a benchmark
plot_rolling_correlation(returns, benchmark, window=63) Rolling correlation versus a benchmark
plot_return_scatter(returns, benchmark) Strategy returns against benchmark returns with a fitted beta line
plot_drawdown_underwater(returns) Filled underwater drawdown chart
plot_returns_heatmap(returns, period="month") Year-by-month, year-by-quarter, or year-by-week return heatmap
plot_returns_bar(returns, period="year") Compounded period returns as a bar chart
plot_returns_dist(returns, period="month") Distribution of compounded period returns
plot_returns_timeseries(returns, period="month") Compounded period returns through time
plot_price_with_overlays(price, overlays, secondary_overlays) Price line with moving averages and secondary-axis indicators
plot_indicator_panel(price, panels) Price chart with one or more aligned indicator sub-panels

Current Table Catalog

Function Use it for
perf_stats(returns) Dictionary of cumulative return, annualized return/volatility, Sharpe, Sortino, max drawdown, and Calmar
table_perf_stats(returns, benchmark=None) Great Tables performance summary with optional benchmark column
table_period_returns(returns, period="year") Great Tables period-return summary
table_drawdowns(returns, top=5) Great Tables largest-drawdown-period summary

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

finance_plots-0.1.0.tar.gz (22.1 kB view details)

Uploaded Source

Built Distribution

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

finance_plots-0.1.0-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file finance_plots-0.1.0.tar.gz.

File metadata

  • Download URL: finance_plots-0.1.0.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for finance_plots-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1f0f08b914a0ae1c807c506e15649fc2f56095dac401d27af433222c537e9ba6
MD5 2929c91ae86549ef938bb46a707e5a9e
BLAKE2b-256 a6125ce6f90758c88be16bf81725c0c11fabeba4ae0df529263a2b97e94185e8

See more details on using hashes here.

File details

Details for the file finance_plots-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: finance_plots-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for finance_plots-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a84292f6e10894b39bc1888a73f8be50d631cd00802a706c47c4ff68c6db57e
MD5 9cc3a32bbc9134ac2beeab8c8fc850e6
BLAKE2b-256 c3792c071f558e0a98f28517ac153c64de3c345e7f8eec29a8b5034a00672973

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