Skip to main content

TaxRebalance

Tax-aware portfolio rebalancing in Python, with Canadian average adjusted cost base (ACB), U.S. tax-lot accounting, and tracking-error constrained optimization.

The package accepts user-supplied securities, prices, target weights, covariance matrices, and dated taxable holdings. It produces proposed trades with modeled tax effects, transaction fees, risk penalties, post-trade cash, and solver feasibility diagnostics.

Python 3.10+ · CVXPY and Clarabel · CAD and USD research models

Install

pip install taxrebalance

Quickstart

from datetime import date
from taxrebalance import (
    CADTransaction, CanadaACB, Portfolio, RebalanceConfig, rebalance
)

portfolio = Portfolio(
    jurisdiction="CA",
    prices={"XIC": 100.0, "XEF": 100.0},
    transactions=(
        CADTransaction(date(2025, 1, 10), "XIC", "BUY", 60, 115),
        CADTransaction(date(2025, 2, 12), "XEF", "BUY", 40, 85),
    ),
    valuation_date=date(2026, 10, 8),
)
result = rebalance(
    portfolio,
    target_weights={"XIC": 0.50, "XEF": 0.50},
    covariance=[[0.04, 0.01], [0.01, 0.04]],
    tax_policy=CanadaACB(marginal_rate=0.42, inclusion_rate=0.50),
    config=RebalanceConfig(max_tracking_error=0.015),
)
print(result.summary())
print(result.trades)

The default tax_aware method uses a convex relaxation and local fixed-direction search. The package also supports risk_only, greedy, hold, and small_exact. Exhaustive direction enumeration applies to at most four securities in the continuous-share model.

Inputs and results

  • Canada: dated purchase and sale transactions, aggregated into average ACB pools for identical securities across the taxpayer's own taxable accounts.
  • United States: individual tax lots with acquisition basis, holding period, and limited replacement-purchase flags.
  • Constraints: target weights, annual tracking-error cap, transaction fees, cash availability, nonnegative holdings, and sale quantities.
  • Results: per-security trades, modeled current and future tax effects, estimated trading fees, risk penalties, solver status, and risk feasibility.
  • Interfaces: Python API, CSV and JSON inputs, JSON results, CSV trade export, and a command-line entry point.

This is a continuous-share decision model. Tax-loss eligibility, superficial-loss and wash-sale treatment, and future transactions require review outside the package. No live market feed, trading execution, tax-return filing, or return forecast is provided.

MIT License.

Metadata

Release files for taxrebalance 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for taxrebalance 0.1.0
File Size Uploaded
taxrebalance-0.1.0.tar.gz 20.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for taxrebalance 0.1.0
File Interpreter ABI Platform
taxrebalance-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 40.0 kB

Release files / taxrebalance-0.1.0.tar.gz

Download URL taxrebalance-0.1.0.tar.gz
Size 20.1 kB
Tags Source
SHA-256 checksum
How to use checksums
211f8042d664ca50b4343b821c2f8ea6e1e2d56f5d0c06dc2f4e57bef210a7da
BLAKE2b-256 checksum
How to use checksums
e613a68d882e050a1a1da6f9a41638d235060a1806f57b89b1e0783c06583a42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.

Transparency log

Release files / taxrebalance-0.1.0-py3-none-any.whl

Download URL taxrebalance-0.1.0-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
469f4515b162063d0e8fd084406fb9927e050d66694f06ff121560f2021e460b
BLAKE2b-256 checksum
How to use checksums
c46ab9d9ff10917ac03ce5345f3d027959936607eb7de7df20d67f5020b318c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page