Skip to main content

WealthSimple Portfolio Rebalancer

Build codecov

A CLI tool that helps you rebalance your WealthSimple portfolio. The tool takes in a CSV-file that contains the target allocations for your portfolio, and prints out a list of buys you should make to bring your portfolio closer to the target allocations you specified.

The tool will log you in to your WealthSimple account, where it will fetch your current positions & buying power, and will parse the CSV-file you defined to determine how far away each position is from the target allocation. It will then select the positions that are the farthest away from their target positions iteratively, until your buying power is used up.

Limitations

  • Currently the tool only supports doing buy-only rebalancing, meaning it won't try to simulate any sells in order to rebalance.
  • The tool only works with CAD denominated stocks and assumes your buying power is in CAD. If there is appetite for supporting other currencies then I can try to support that as well.
  • Prices for the stocks are fetched off the WealthSimple Trade API as well, so the quotes may be delayed by 15 minutes.

Installation

# To get the latest release
pip install ws-rebalancer

CSV-file requirements

To start, create a CSV file that will contain tickers from assets in your current portfolio, as well as tickers for any new assets you would like to add. In the CSV file, each line will represent a unique asset you own or want to own. On each line, you need to include the correct ticker for the asset and the target allocation for that asset. The format for each line is as follows:

<stock ticker>, <target allocation>

Here is a sample CSV file:

# sample-target-allocations.csv
MSFT, 50%
APPL, 30%
GOOG, 20%

In other words, I want my sample portfolio to be 50% Microsoft, 30% Apple, and 20% Google.

Make sure that the target allocations add up to 100%. The tool will raise an error and quit if that is not the case. You can also use decimals to represent fractional target allocations. Also don't repeat the same ticker twice. I've tried my best to sanitize the input and raise any errors that I can forsee with the CSV-file, but there may be some things that I didn't catch so please be careful.

Usage

To generate the buys that will rebalance your portfolio as close as possible to the target allocation, run the tool as follows:

$ ws-rebalancer rebalance -t <target-allocations-CSV-file> --email <WealthSimple-email-login> [--2fa]

Using our sample-target-allocations.csv as above, a sample run could look as follows:

$ ws-rebalancer rebalance -t sample-target-allocations.csv --email test@gmail.com --2fa
Password:
Repeat for confirmation:
Enter 2FA code: 12345
0. non-registered
Please input the account you want: 0
Buy 5X MSFT @ 10.00 - New allocation 40.00%
Buy 1X APPL @ 20.00 - New allocation 30.00%
Buy 1X GOOG @ 30.00 - New allocation 30.00%
Remaining cash $0.00

Note that in this example, MSFT price was $10.00, APPL price was $20.00, and GOOG price was $30.00, and we had a buying power of $60.00 in this account (although it is not shown). The tool also fetched our current positions and buying power for the specified account and then provided a list of buys we should make in order to try to meet the specified target allocations.

Finding Issues

If you find issues using this tool, please create an Issue using the Github issue tracker and I will try to address it as soon as I can.

Contributing

If you would like to contribute, please read the CONTRIBUTING.md page

Metadata

Release files for ws-rebalancer 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ws-rebalancer 2.0.0
File Size Uploaded
ws_rebalancer-2.0.0.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ws-rebalancer 2.0.0
File Interpreter ABI Platform
ws_rebalancer-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.5 kB

Release files / ws_rebalancer-2.0.0.tar.gz

Download URL ws_rebalancer-2.0.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ce426658fd351bb85467724787c5218b2d346b4d503eb964b748b870127267db
BLAKE2b-256 checksum
How to use checksums
d2629148df8824cd93c88ea763964684acafdb1faf463ca4a598fbdc6c5a3d8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 17, 2025.

Transparency log

Release files / ws_rebalancer-2.0.0-py3-none-any.whl

Download URL ws_rebalancer-2.0.0-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
695a92739c84b63feb9afb15b0682af2c196f51094c7b01e17402149b334dfe9
BLAKE2b-256 checksum
How to use checksums
8d867bb0debeca68710101a056a1632dc75c0a23542ef5e2375a867c919096a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 17, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page