rebalance is a simple Python 3.9+ library for rebalancing investment portfolios

Overview

rebalance

docs license pypi

rebalance is a simple Python 3.9+ library for rebalancing investment portfolios. It supports cash flow rebalancing with contributions and withdrawals, opportunistic rebalancing with symmetric and asymmetric rebalance bands, and traditional calendar-based rebalancing. Works with any currency. Precise to the smallest unit.

>> b = Asset("B", Decimal("0.4"), 25_00) >>> portfolio = Portfolio((a, b)) >>> for result in cash_flow_rebalance(portfolio, 50_00): ... print(result.asset.name, result.delta) ... A 3500 B 1500 >>> for result in cash_flow_rebalance(portfolio, -40_00): ... print(result.asset.name, result.delta) ... B -2100 A -1900 >>> for result in opportunistic_rebalance(portfolio): ... print(result.asset.name, result.delta) ... A 300 B -300">
>>> from decimal import Decimal
>>> from rebalance import Asset, Portfolio, Result, cash_flow_rebalance, opportunistic_rebalance

>>> a = Asset("A", Decimal("0.6"), 25_00)
>>> b = Asset("B", Decimal("0.4"), 25_00)

>>> portfolio = Portfolio((a, b))

>>> for result in cash_flow_rebalance(portfolio, 50_00):
...     print(result.asset.name, result.delta)
...
A 3500
B 1500

>>> for result in cash_flow_rebalance(portfolio, -40_00):
...     print(result.asset.name, result.delta)
...
B -2100
A -1900

>>> for result in opportunistic_rebalance(portfolio):
...     print(result.asset.name, result.delta)
...
A 300
B -300

Use

Install rebalance:

pip install rebalance

Then read the documentation.

Test

Install Hypothesis:

pip install hypothesis

Then run this command in the project root directory:

python -m unittest

Build

Documentation

Install Sphinx:

pip install sphinx

Then run this command in the docs/ directory:

make html

Distribution package

Install build:

pip install build

Then run this command in the project root directory:

python -m build
You might also like...
Msgpack serialization/deserialization library for Python, written in Rust using PyO3 and rust-msgpack. Reboot of orjson. msgpack.org[Python]

ormsgpack ormsgpack is a fast msgpack library for Python. It is a fork/reboot of orjson It serializes faster than msgpack-python and deserializes a bi

PyPIContents is an application that generates a Module Index from the Python Package Index (PyPI) and also from various versions of the Python Standard Library.

PyPIContents is an application that generates a Module Index from the Python Package Index (PyPI) and also from various versions of the Python Standar

The purpose is to have a fairly simple python assignment that introduces the basic features and tools of python

This repository contains the code for the python introduction lab. The purpose is to have a fairly simple python assignment that introduces the basic

Python-Kite: Simple python code to make kite pattern
Python-Kite: Simple python code to make kite pattern

Python-Kite Simple python code to make kite pattern. Getting Started These instr

🔩 Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.

Boltons boltons should be builtins. Boltons is a set of over 230 BSD-licensed, pure-Python utilities in the same spirit as — and yet conspicuously mis

A Python library to simulate a Zoom H6 recorder remote control
A Python library to simulate a Zoom H6 recorder remote control

H6 A Python library to emulate a Zoom H6 recorder remote control Introduction This library allows you to control your Zoom H6 recorder from your compu

Python library for creating PEG parsers

PyParsing -- A Python Parsing Module Introduction The pyparsing module is an alternative approach to creating and executing simple grammars, vs. the t

Python library to natively send files to Trash (or Recycle bin) on all platforms.

Send2Trash -- Send files to trash on all platforms Send2Trash is a small package that sends files to the Trash (or Recycle Bin) natively and on all pl

Python screenshot library, replacement for the Pillow ImageGrab module on Linux.

tldr: Use Pillow The pyscreenshot module is obsolete in most cases. It was created because PIL ImageGrab module worked on Windows only, but now Linux

Releases(v1.1.0)
Owner
Darik Harter
Darik Harter
This is the old code for bitcoin risk metric, the whole purpose form it is to help you DCA your investment according to bitcoin risk.

About The Project This is the old code for bitcoin risk metric, the whole purpose form it is to help you DCA your investment according to bitcoin risk

BitcoinRaven 2 Aug 3, 2022
Margin Calculator - Personally tailored investment tool

Margin Calculator - Personally tailored investment tool

null 1 Jul 19, 2022
CBO uses its Capital Tax model (CBO-CapTax) to estimate the effects of federal taxes on capital income from new investment

CBO’s CapTax Model CBO uses its Capital Tax model (CBO-CapTax) to estimate the effects of federal taxes on capital income from new investment. Specifi

Congressional Budget Office 7 Dec 16, 2022
JLC2KICAD_lib is a python script that generate a component library for KiCad from the JLCPCB/easyEDA library.

JLC2KiCad_lib is a python script that generate a component library (schematic, footprint and 3D model) for KiCad from the JLCPCB/easyEDA library. This script requires Python 3.6 or higher.

Nicolas Toussaint 73 Dec 26, 2022
K2HASH Python library - NoSQL Key Value Store(KVS) library

k2hash_python Overview k2hash_python is an official python driver for k2hash. Install Firstly you must install the k2hash shared library: curl -o- htt

Yahoo! JAPAN 3 Oct 19, 2022
Simple but maybe too simple config management through python data classes. We use it for machine learning.

??‍✈️ Coqpit Simple, light-weight and no dependency config handling through python data classes with to/from JSON serialization/deserialization. Curre

coqui 67 Nov 29, 2022
A simple wrapper for joy library

Joy CodeGround A simple wrapper for joy library to render joy sketches in browser using vs code, (or in other words, for those who are allergic to Jup

rijfas 9 Sep 8, 2022
LanguageCreator - Simple library for easy creation transpilator.

LanguageCreator - Simple library for easy creation transpilator. Create transpilators in one hour! Install. Download code, rename folder to "LanguageC

Ivan Perzhinsky. 2 Dec 31, 2021
A simple program to recolour simple png icon-like pictures with just one colour + transparent or white background. Resulting images all have transparent background and a new colour.

A simple program to recolour simple png icon-like pictures with just one colour + transparent or white background. Resulting images all have transparent background and a new colour.

Anna Tůmová 0 Jan 30, 2022