Skip to main content

A modular Python library for multi-account portfolio trade allocation

Project description

realloc


A modular Python library for managing and rebalancing multi-account investment portfolios.

It handles account-aware trade allocation, portfolio-level targets, and execution constraints across multiple real-world accounts.


🚀 Features

  • Allocate trades across multiple accounts
  • Enforce constraints (e.g. no negative positions, long-only models)
  • Simulate rebalancing with real-time cash and price updates
  • Split trades into buys and sells
  • Fully tested with pytest
  • Clean, modular, extensible API

📦 Installation

Clone the repo and install in editable mode:

git clone https://github.com/yourname/realloc.git
cd realloc
pip install -e .[dev]

🏁 Quick Start

from realloc import Account, PortfolioModel, PortfolioAllocator

Define accounts

accounts = [ Account("IRA", "A1", 1000, {"AAPL": 5}, {}), Account("Taxable", "A2", 2000, {"GOOG": 3}, {}) ]

Define target model

model = PortfolioModel("Balanced", {"AAPL": 0.5, "GOOG": 0.5})

Define prices

prices = {"AAPL": 100, "GOOG": 200}

Allocate trades

allocator = PortfolioAllocator(accounts, model, prices) trades = allocator.rebalance()

print(trades)

📄 rebalance-cli

This is a ready-made script that demonstrates a full re-balance (not just a slice re-balance) of realloc.

Input Format

To use rebalance-cli, you must provide a JSON file with:

  • prices: { symbol → float }
  • accounts: list of account dictionaries
  • model: portfolio model with name and targets

📂 Example:

{
  "prices": { "AAPL": 100, "GOOG": 100 },
  "accounts": [
    { "label": "A", "account_number": "1", "cash": 1000, "positions": { "AAPL": 5 }, "targets": {} }
  ],
  "model": {
    "name": "Balanced",
    "targets": { "AAPL": 0.6, "GOOG": 0.4 }
  }
}


## 🗂 Project Structure

src/ realloc/ plugins/ base.py csv_exporter.py loader.py cli/ reblance-cli portfolio-cli accounts.py models.py trades.py selectors.py matrix.py utils.py allocator.py init.py tests/ test_realloc.py Dockerfile Makefile README.md setup.py

🔌 Export Plugins

Realloc supports custom export plugins to output rebalancing data in different formats. Plugins are loaded dynamically using entry points.

Using Plugins

To use an export plugin with the CLI:

bash rebalance-cli --exporter plugin_name input.json

Available Plugins

  • csv - Built-in CSV exporter (included with realloc)
  • csvplus - Enhanced CSV export with metadata (realloc-csvplus)

Creating Plugins

To create your own export plugin, see our Plugin Development Guide.

Basic example:

from realloc.plugins import ExportPlugin


class MyExporter(ExportPlugin):
    def export(self, data):
        # Your export logic here
        pass

📄 License

MIT License.

🙌 Contributing

Pull requests welcome! Please open an issue or contact first if proposing large changes.

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

realloc-0.1.3.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

realloc-0.1.3-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file realloc-0.1.3.tar.gz.

File metadata

  • Download URL: realloc-0.1.3.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for realloc-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a861379da137cf0a861252fee7390ea3e6c31b1b05566f7c38519bb3f6a082d1
MD5 d4630ecf5647e35e3caaba720dd98dc3
BLAKE2b-256 d2fb47873be8d4a43170577c64364cb321ee69445421ef6896175af237236d42

See more details on using hashes here.

File details

Details for the file realloc-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: realloc-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for realloc-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c02ff94880127a3bd836d446afb503d583c14c669a007dc875c75440d9a7699d
MD5 efea330fea3eddfdf16e328d22347bb8
BLAKE2b-256 1874dd9d3e58026d2a72972663bce354ca813729b55183f2ed14605a2abab723

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