GithubHelp home page GithubHelp logo

sudarsansridharan16 / rebalance Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jordao76/rebalance

0.0 1.0 0.0 140 KB

Python code to aid in Exchange-Traded Funds (ETFs) portfolio rebalancing

License: MIT License

Python 100.00%

rebalance's Introduction

rebalance

Build Status License

Python code to aid in Exchange-Traded Funds (ETFs) portfolio rebalancing.

To install: with python 3, git clone, cd into it and run:

$ pip install -r requirements.txt
...
$ python setup.py install

Use it like this:

from decimal import *
from rebalance import Instrument, CASH, Portfolio, Plotter

# instruments (ETFs)
ZAG = Instrument('ZAG', 'BMO Aggregate Bond Index EFT')
VCN = Instrument('VCN', 'Vanguard FTSE Canada All Cap Index ETF')
XAW = Instrument('XAW', 'iShares Core MSCI All Country World ex Canada Index ETF')

my_portfolio = Portfolio({
    CASH: Decimal(500),
    ZAG: Decimal(1000),
    VCN: Decimal(3000),
    XAW: Decimal(5500)})
assert my_portfolio.total == Decimal(10000)

# canadian couch potato assertive model portfolio (2016)
model_portfolio = Portfolio({
    ZAG: Decimal(25),
    VCN: Decimal(25),
    XAW: Decimal(50)})
assert model_portfolio.total == Decimal(100)

orders = my_portfolio.rebalance(model_portfolio)
print(orders)
# [Order(action=Sell, instrument=VCN, amount=Decimal('500.00')),
# Order(action=Sell, instrument=XAW, amount=Decimal('500.00')),
# Order(action=Buy, instrument=ZAG, amount=Decimal('1500.00'))]

The results are the necessary orders to rebalance my_portfolio with the model_portfolio as a model, where an order includes the desired action (Buy or Sell), the instrument (ETF) symbol and the dollar amount (with default precision and rounding rules, discrepancies may occur).

There's also a method to plot your portfolio:

my_portfolio.plot()
Plotter.show()

My Portfolio

You can also plot the returns of your portfolio. This will use google finance and plot the daily value of the portfolio for a year until today, assuming the portfolio debuted one year ago with its recorded composition:

my_portfolio.plot_returns()
Plotter.show()

My Portfolio Returns

Note that this is for illustrative purposes only and does not account for fees or dividends. Also remember, past performance does not guarantee future results.

rebalance's People

Contributors

jordao76 avatar

Watchers

James Cloos avatar

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.