Portfolio analysis with DIY tool in Python

Hey !

I’m working on a tool to analyse the evolution of my portfolio on Interactive Brokers, which contains ETF, shares and cash.
As a prototype, I’m writing it in Python programming language, using the Jupyter Notebook framework and some data files in YAML standard. To me the requirements are:

  • dynamic computation of the portfolio content (dynamic = updated with the last data for the products),
  • manage CHF, USD and EUR,
  • one global view the content as a table with:
    • product symbol,
    • quantity,
    • mean buy price (mean computation if I buy the same product at different times),
    • last known value,
    • P&L (CHF and %),
    • dividende estimate for the year,
  • one detailed pie by ratio (%) with the markets repartition (USA, EUROPE, EMERGING, PACIFIC, MID. EAST),
  • one detailed pie by ratio (%) with products types (CASH, ETF, SHARE),
  • one detailed pie by ratio (%) with sectors (TECH, FINANCIALS, ENERGY…),
  • one detailed pie by ratio (%) of products in the while portfolio),
  • a graph of positive/negatives P&L in % and CHF for each product.

To feed the tool, the data to process must be ‘easy’ to setup. I choose a text format (YAML):

  • a file for products descriptions (tickers.yaml): it contains the definition of each product (symbol, description, geographic repartition, sectors repartition)
  • a file for transactions (transactions.yaml): it contains the list of the whole transactions I have made for the portfolio. It could be:
    • INSERT_MONEY when I move money from by bank account to IB in CHF (qty, date),
    • BUY_CURRENCY to convert CHF to USD (from/to currencies, qty, rate),
    • BUY_SHARE to buy a product (symbol, qty, rate, commission, date).

The technology behind this uses: yahoo finance for dynamic products information, pandas for dataframe manipulation and matplotlib for graphs.

Afterwords, I’m not really convince in the way I manipulate the data and it may be more powerful to setup a real database (SQLite?) to increase the modularity.

Have a look here to view the files (still in development :sunglasses:). The transaction.yaml contains data for testing.

Example of outputs:


My questions:

  • any of you has already think about a kind of tool ?
  • do you already use something DIY or on the shelf ?
  • any constructive comment ?

Thank you for your attention.
πR

2 Likes

I use Portfolio Performance, it’s free and satisfies all my needs.

3 Likes

I use beancount. Use the search function to find the various threads about it.

3 Likes

I also use beancount for tracking trades and expenses, but for performance calculations portfolio allocations it’s not really useful.

I use beancount as the core and then a python app on top of it for very similar kind of reporting and graphs. The query language of beancount is really nice for something like this and it supports custom metadata e.g. I use it for asset classes.

If you want do to xirr calculations, I created a small python library for this that might be useful for you xirr — xirr 0.1.6.post1.dev20 documentation

2 Likes

Re portofolio allocation, did someone build a tool to generate a list of % shares which are contained in the ETFs & shares in your portofolio?

  • IBKR offers it in their portofolio checkups (I have two brokerage accounts though…)
  • Morningstar X-ray used to do it for free, but it’s now under a paid subscription

Do FTSE/MSCI offer good APIs to enable building such a product?

1 Like

MSCI has an API that should allow to do it, but as dar as I can see you need to be an MSCI client and their subscriptions are far from cheap.

I thought about creating such a tool myself even though I’m not a software developer or something like that, but Python seems to be pretty straight forward and with NumPy and Pandas etc. one could create an MVP quite quickly I guess.

Nevertheless, I would prefer to use a tool that already exists and save myself the time, but I wasn’t really successful in finding one.

It would be good if the tool could track several portfolios and their performances, but also overall performance, net worth, and include a portfolio optimiser / rebalancing tool, modelling different asset allocations / efficient frontiers etc. and also with detailed analytics / statistics. Most tools have no idea what’s inside of ETFs so statistics are usually worthless (it shows 98% US for regional distribution if you have US domiciled ETFs, etc.). The tool should cover stocks and ETFs. JustETF does not have US ETFs but otherwise seems to have a rebalancing tool included. Most other portfolio tools e.g. Seeking Alpha, Morningstar are quite basic in functionality. I would even pay for a good one but it doesn’t seem to exist.

I’m currently using various Apple Numbers sheets for tracking but a comprehensive tool would be more nice.

Nice! This isn’t an actual beancount plugin, though, is it? I’ve been hoping to see some progress to https://github.com/beancount/fava/issues/1082, but it’s moving very slowly.