Skip to main content

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.

Project description

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

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

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

tiportfolio-1.3.1.tar.gz (3.0 MB view details)

Uploaded Source

Built Distribution

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

tiportfolio-1.3.1-py3-none-any.whl (54.2 kB view details)

Uploaded Python 3

File details

Details for the file tiportfolio-1.3.1.tar.gz.

File metadata

  • Download URL: tiportfolio-1.3.1.tar.gz
  • Upload date:
  • Size: 3.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tiportfolio-1.3.1.tar.gz
Algorithm Hash digest
SHA256 fd22a31060704bab3613078b6d62bfcd504a931dee155e2dd2ff5d58fc269119
MD5 fe6fa7987843fe6e302bb0cc7d0f01ca
BLAKE2b-256 b81f7d1ff05de724949cd0680c1046fbcbaf9bcc5b3ad38d97f413885655ff9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiportfolio-1.3.1.tar.gz:

Publisher: publish.yml on TradeInsight-Info/TiPortfolio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tiportfolio-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: tiportfolio-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 54.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tiportfolio-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce7e4ec582cf71a26071e59268f6ce9dae32b31865b6c7cdb87503c3df9c8cd2
MD5 632264e9b78529fd19dbc75f887fd276
BLAKE2b-256 1bf10fee3e0c7ddd3d6052ea1e5df7fdfea15ea040fa62c5e51c1523dbb29227

See more details on using hashes here.

Provenance

The following attestation bundles were made for tiportfolio-1.3.1-py3-none-any.whl:

Publisher: publish.yml on TradeInsight-Info/TiPortfolio

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