A calculator which tells you how to split your investment amongst your portfolio's assets based on your target asset allocation.
To use it, install the package and write a driver file as described below.
The driver file is where we create our portfolio. We specify all of its assets and the available cash we have to invest.
Follow the steps below for a detailed description. Alternatively, you can simply modify the example driver file.
cd rebalance
touch driver_file.py
from rebalance import Portfolio
# My portfolio
p = Portfolio()
We must specify the ticker symbol and the quantity of each asset we currently have in our portfolio.
The portfolio used in this example is one of Canadian Portfolio Manager's model portfolios. This blog along with Canadian Couch Potato advocate low-cost, globally diversified index funds for DIY investors.# Assets in portfolio
# The price will be retrieved automatically
tickers = ["XBB.TO", # iShares Core Canadian Universe Bond Index ETF
"XIC.TO", # iShares Core S&P/TSX Capped Composite Index ETF
"ITOT", # iShares Core S&P Total U.S. Stock Market ETF
"IEFA", # iShares Core MSCI EAFE ETF
"IEMG"] # iShares Core MSCI Emerging Markets ETF
quantities = [36, 64, 32, 8, 7]
p.easy_add_assets(tickers=tickers, quantities=quantities)
This is the amount that we are investing. We can add cash in different currencies.
# Cash in portfolio
cash_amounts = [3000., 200.]
cash_currency = ["USD", "CAD"]
p.easy_add_cash(amounts=cash_amounts, currencies=cash_currency)
# Target asset allocation (in %)
target_asset_alloc = {
"XBB.TO": 20,
"XIC.TO": 20,
"ITOT": 36,
"IEFA": 20,
"IEMG": 4
}
# rebalance
p.selling_allowed = False # We don't want to sell any of our assets for this case
p.rebalance(target_asset_alloc, verbose=True)
You should see something similar to this (the actual values might differ due to changes in prices and exchange rates).
Ticker Ask Quantity Amount Currency Old allocation New allocation Target allocation
to buy ($) (%) (%) (%)
---------------------------------------------------------------------------------------------------------------
XBB.TO 33.43 30 1002.90 CAD 17.52 19.99 20.00
XIC.TO 24.27 27 655.29 CAD 22.61 20.01 20.00
ITOT 69.38 10 693.80 USD 43.93 35.88 36.00
IEFA 57.65 20 1153.00 USD 9.13 19.88 20.00
IEMG 49.14 0 0.00 USD 6.81 4.24 4.00
Largest discrepancy between the new and the target asset allocation is 0.24 %.
Before making the above purchases, the following currency conversion is required:
1072.88 USD to 1458.19 CAD at a rate of 1.3591.
Remaining cash:
80.32 USD.
0.00 CAD.