Skip to main content

TiPortfolio

A portfolio management tool with built-in state-of-the-art portfolio optimization algorithms, with extensibility for different use cases for both institutes and retail traders.

Documentation | PyPI | GitHub

Quick Start

pip install tiportfolio

# For interactive Plotly charts:
pip install tiportfolio[interactive]

# For Equal Risk Contribution (ERC) weighting:
pip install tiportfolio[erc]
import tiportfolio as ti

# 1. Fetch data (Yahoo Finance by default, or Alpaca if API keys are set)
data = ti.fetch_data(["QQQ", "BIL", "GLD"], start="2019-01-01", end="2024-12-31")

# 2. Define strategy using the algo stack: Signal → Select → Weigh → Action
portfolio = ti.Portfolio(
    "monthly_equal_weight",
    [
        ti.Signal.Monthly(),    # WHEN to rebalance
        ti.Select.All(),        # WHAT to include
        ti.Weigh.Equally(),     # HOW MUCH to allocate
        ti.Action.Rebalance(),  # EXECUTE trades
    ],
    ["QQQ", "BIL", "GLD"],
)

# 3. Run backtest
result = ti.run(ti.Backtest(portfolio, data))

# 4. View results
result.summary()       # key metrics: Sharpe, CAGR, max drawdown, etc.
result.plot()          # equity curve + drawdown chart

CLI

Run backtests directly from the terminal — no Python script needed.

Use pipx install tiportfolio --python python3.12 to install the CLI tool globally without affecting your Python environment.

Or use uvx to run the CLI without installing: uvx run tiportfolio -- [options] instead of tiportfolio [options].

# Monthly rebalance QQQ/BIL/GLD at 70/20/10
tiportfolio monthly --tickers QQQ,BIL,GLD --start 2019-01-01 --end 2024-12-31 --ratio 0.7,0.2,0.1

# Quarterly equal-weight rebalance
tiportfolio quarterly --tickers QQQ,BIL,GLD --start 2019-01-01 --end 2024-12-31 --ratio equal

# Compare at 1x, 1.5x, 2x leverage (includes borrowing cost)
tiportfolio monthly --tickers QQQ,BIL,GLD --start 2019-01-01 --end 2024-12-31 --ratio 0.7,0.2,0.1 --leverage 1.0,1.5,2.0

# Save equity curve chart
tiportfolio monthly --tickers QQQ,BIL,GLD --start 2019-01-01 --end 2024-12-31 --ratio equal --plot chart.png

See docs/cli.md for the full CLI reference with all subcommands and options.

Agent Skill

TiPortfolio includes an agent skill that lets you backtest strategies using natural language — no CLI flags to remember.

Install the skill for any agent that supports the Skills standard:

npx skills add https://github.com/TradeInsight-Info/TiPortfolio/tree/master/agent-plugins

For Claude Code specifically:

claude plugin add https://github.com/TradeInsight-Info/TiPortfolio

Then just ask your agent:

"Backtest QQQ BIL GLD equal weight monthly from 2019 to 2024"

"Monthly $1000 DCA into QQQ BIL GLD"

"Compare 1x vs 1.5x vs 2x leverage on quarterly QQQ BIL GLD"

The skill maps your request to uvx tiportfolio CLI commands, runs the backtest, and presents the results. Requires uv to be installed.

Requirements

  • Python 3.10+
  • pandas, numpy, matplotlib

Data fetching uses Yahoo Finance by default. For Alpaca, set ALPACA_API_KEY and ALPACA_API_SECRET in your environment (see .env.example).

Development

uv sync
uv run python -m pytest

License

Apache 2.0

Metadata

Release files for tiportfolio 1.4.1

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

Source distribution (sdist)

Source distribution for tiportfolio 1.4.1
File Size Uploaded
tiportfolio-1.4.1.tar.gz 2.9 MB Details

Built distribution (wheel)

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

Total release size: 2.9 MB

Release files / tiportfolio-1.4.1.tar.gz

Download URL tiportfolio-1.4.1.tar.gz
Size 2.9 MB
Tags Source
SHA-256 checksum
How to use checksums
0f1138fd338fe52084a424f424f09ab4e012100cff57002e3902a27da84640d5
BLAKE2b-256 checksum
How to use checksums
2c5b77078c1e25e4ba96c7a7b4abbea9b9bfd5a8f5606caf76e397d89ab75d3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 12, 2026.

Transparency log

Release files / tiportfolio-1.4.1-py3-none-any.whl

Download URL tiportfolio-1.4.1-py3-none-any.whl
Size 43.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
060fca95923c3f276f7a864e362e49253d1d96c4d30a9a80f5e3c013fcbad4bd
BLAKE2b-256 checksum
How to use checksums
f9b1560919f96b9b5e6990815f1440742280d14f7bf54db05e50a5aab0883691
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 12, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.4.1 This release

2 release files

1.4.0

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

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