Giter VIP home page Giter VIP logo

rebalance-app's Introduction

rebalance-app

Build Status

Optimal lazy portfolio rebalancing calculator (in Rust)

Usage

$ rebalance-app --help
rebalance-app 1.2.0
Alberto Leal (github.com/dashed) <[email protected]>
Optimal lazy portfolio rebalancing calculator

USAGE:
    rebalance-app [OPTIONS] <contribution> --portfolio <FILE> --targets <FILE>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -p, --portfolio <FILE>                 Sets a portfolio file
    -i, --portfolio_value_index <INDEX>    Sets CSV index of the portfolio value
    -t, --targets <FILE>                   Sets a targets file

ARGS:
    <contribution>    Sets the contribution amount

Quickstart

  1. Set up targets.csv. Example: example/targets.csv

  2. Set up portfolio.csv. Usually you export this from your favourite broker. Example: example/portfolio.csv

  3. Run: rebalance-app --portfolio example/portfolio.csv --targets example/targets.csv 5000

By default, rebalance-app assumes the values of your assets in your portfolio CSV file is at the 2nd column (i.e. index 1). For example:

Bond fund,                 roi %, ticker symbol, $16500.00
TIPS fund,                 roi %, ticker symbol, $6500.00
Domestic Stock ETF,        roi %, ticker symbol, $43500.00
International Stock ETF,   roi %, ticker symbol, $33500.00

You can adjust this using the -i flag:

rebalance-app -i 3 --portfolio example/portfolio.csv --targets example/targets.csv 5000

About

Rationale: Rather than rebalance your portfolio internally, add/remove money such that your asset targets % are achieved as close as possible.

See this article on rebalancing: https://www.bogleheads.org/wiki/Rebalancing

Based on:

How it works:

Source: http://optimalrebalancing.tk/explanation.html (archived snapshot)

Step 1: Calculate How Each Asset Deviates From Its Target

  1. Define the difference between each asset's actual value and its intended portion after factoring in the new contribution. This difference is expressed as a percentage f, termed the fractional deviation.
  2. Compute f as: f = a/t - 1, where:
    • a is the current value of the asset.
    • t is the intended portion of the asset relative to the final total portfolio value, which is obtained by adding the new contribution to the original total portfolio value.

A negative f indicates the asset is below its target, while a positive f means it's over its target.

Step 2: Distribute Funds to Assets to Equalize Their Deviations

  1. Start by identifying the group of assets with the most negative (lowest) f values, i.e., those furthest below their target.

  2. Allocate a portion of the contribution to this group of assets. The goal is to bring their f values close to or equal to the next lowest f value among the remaining assets.

  3. Within this group of most underweight assets, distribute the contribution proportionally based on their target allocations. For instance, if two assets in this group have target allocations of 10% and 20% respectively, and you're adding $30, the first should get $10, and the second should get $20.

  4. Repeat steps 1 through 3 until all of the new contribution is distributed across the assets.

Chores

  • cargo fmt

License

GPL-3.0+.

rebalance-app's People

Contributors

dashed avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rebalance-app's Issues

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.


  • Check this box to trigger a request for Renovate to run again on this repository

Improve docs

Docs to elaborate more on:

  • What is the targets csv file? And what is the expected setup?

  • What is the portfolio csv file? And what is the expected setup?

Exception thrown when parsing numbers with thousands comma separators

If you try to run the app with a contribution amount that contains a comma thousands separator (i.e. 10,000) you will get the following exception:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseFloatError { kind: Invalid }', src\libcore\result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

The same error occurs if any number within the portfolio.csv or targets.csv has a comma separated number.

Fund A, $40000
Fund B, $40,000 <-- ๐Ÿ˜ข
Fund C, $1000

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.