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.
Installation
pip install tiportfolio
# For interactive Plotly charts:
pip install tiportfolio[interactive]
# For Equal Risk Contribution (ERC) weighting:
pip install tiportfolio[erc]
Quick Start
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
- More examples
CLI
Run backtests directly from the terminal — no Python script needed.
# 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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tiportfolio-1.2.0.tar.gz.
File metadata
- Download URL: tiportfolio-1.2.0.tar.gz
- Upload date:
- Size: 2.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
262f2e2ae0ee0968935c1137c3d74011bc616542f1f1319fcae3f405e2d06f4d
|
|
| MD5 |
53e7722e14bb8f3b6585a37ffe340810
|
|
| BLAKE2b-256 |
d6790f70d34cb384ef214513e813b3b8dbfcdcb016a687e2feedc3a0becfb27e
|
Provenance
The following attestation bundles were made for tiportfolio-1.2.0.tar.gz:
Publisher:
publish.yml on TradeInsight-Info/TiPortfolio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tiportfolio-1.2.0.tar.gz -
Subject digest:
262f2e2ae0ee0968935c1137c3d74011bc616542f1f1319fcae3f405e2d06f4d - Sigstore transparency entry: 1233120717
- Sigstore integration time:
-
Permalink:
TradeInsight-Info/TiPortfolio@4b8ddcc5477afe5523202e328ce09f09179b9219 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/TradeInsight-Info
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4b8ddcc5477afe5523202e328ce09f09179b9219 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tiportfolio-1.2.0-py3-none-any.whl.
File metadata
- Download URL: tiportfolio-1.2.0-py3-none-any.whl
- Upload date:
- Size: 52.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01eab22c5174849457b2424a1b7c12d97538905b52bb52a842e4473725d4bf5c
|
|
| MD5 |
13a5be0dc7ddb2e1e29209e74eeafce0
|
|
| BLAKE2b-256 |
103eb44a07ab0451ecabd1ecc9ce74820c52a851edd3f375b9cd57281f1b8f2e
|
Provenance
The following attestation bundles were made for tiportfolio-1.2.0-py3-none-any.whl:
Publisher:
publish.yml on TradeInsight-Info/TiPortfolio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tiportfolio-1.2.0-py3-none-any.whl -
Subject digest:
01eab22c5174849457b2424a1b7c12d97538905b52bb52a842e4473725d4bf5c - Sigstore transparency entry: 1233120766
- Sigstore integration time:
-
Permalink:
TradeInsight-Info/TiPortfolio@4b8ddcc5477afe5523202e328ce09f09179b9219 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/TradeInsight-Info
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4b8ddcc5477afe5523202e328ce09f09179b9219 -
Trigger Event:
push
-
Statement type: