Skip to content

⚖️ A simple tool for calculating the optimal number of shares to buy to maintain a proportional portfolio

License

Notifications You must be signed in to change notification settings

bcongdon/optimal_balancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

optimal_balancer

A simple tool for calculating the optimal number of shares to buy to maintain a proportional portfolio.

The tool takes into account the current price of each fund, the number of shares of each fund already in the portfolio, and the desired target proportion of each fund. From that information, it calculates the optimal number of shares of each fund to buy to get closest to the desired target proportion for the portfolio, using a "buy only" strategy.

Installation

$ cargo install --git https://github.com/bcongdon/optimal_balancer --branch main

Usage

optimal_balancer 1.0

USAGE:
    optimal_balancer [FLAGS] [OPTIONS] --config <config>

FLAGS:
    -d, --download-current-prices
    -h, --help                       Prints help information
    -V, --version                    Prints version information

OPTIONS:
    -c, --config <config>
    -t, --target-buy <target-buy>

Examples

$ optimal_balancer --config path/to/config

# Download the current price for ticker symbols at runtime.
$ optimal_balancer --config path/to/config --download-current-prices

Config File Format

# The desired total purchase price of new shares. ($)
target_buy = 6000.0

# A list of funds in the portfolio.
[[funds]]
symbol = "BND"              # The fund's ticker symbol.
shares = 100                # The number of shares already owned.
price = 85.40               # The current share price.
target_proportion = 0.15    # The desired fund allocation in the portfolio.

[[funds]]
symbol = "VTI"
shares =  200
price = 216.3
target_proportion = 0.70

[[funds]]
symbol = "VXUS"
shares =  100
price = 65.66
target_proportion = 0.15

Notes:

  • You can omit including the price for each fund, and pass the -d flag to have price be downloaded at runtime (uses yahoo-finance data).
  • The sum of target_proportions for all funds in the config should be 1.

Attribution

Uses the excellent z3 crate for calculating the optimal strategy.

About

⚖️ A simple tool for calculating the optimal number of shares to buy to maintain a proportional portfolio

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages