# Portfolio analysis with DIY tool in Python

**URL:** <https://forum.mustachianpost.com/t/portfolio-analysis-with-diy-tool-in-python/7826>\
**Category:** Uncategorized\
**Created:** [February 1, 2022, 2:37pm UTC](https://forum.mustachianpost.com/t/portfolio-analysis-with-diy-tool-in-python/7826 "2022-02-01T14:37:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![314rch](https://forum.mustachianpost.com/letter_avatar_proxy/v4/letter/3/9f8e36/32.png) [@314rch](https://forum.mustachianpost.com/u/314rch)\
**Post date:** [February 1, 2022, 2:37pm UTC](https://forum.mustachianpost.com/t/portfolio-analysis-with-diy-tool-in-python/7826/1 "2022-02-01T14:37:09Z")

</div>

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](https://github.com/pierrebressy/dynamic-portfolio-analyser) to view the files (still in development 🕶). The `transaction.yaml` contains data for testing.

Example of outputs:

 ![image](https://forum.mustachianpost.com/uploads/default/original/2X/0/087611f846627fab4c569dbca439e675ea1f467d.png)  
 ![image](https://forum.mustachianpost.com/uploads/default/original/2X/6/64f4674207b734073a931ebc190a6b7750cc8ba3.jpeg)

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

---

<div class="post-metadata">

**Author:** ![Burningstone](https://forum.mustachianpost.com/user_avatar/forum.mustachianpost.com/burningstone/32/12334_2.png) [@Burningstone](https://forum.mustachianpost.com/u/Burningstone)\
**Post date:** [February 1, 2022, 2:39pm UTC](https://forum.mustachianpost.com/t/portfolio-analysis-with-diy-tool-in-python/7826/2 "2022-02-01T14:39:51Z")

</div>

I use [Portfolio Performance](https://www.portfolio-performance.info/), it’s free and satisfies all my needs.

---

<div class="post-metadata">

**Author:** ![MrCheese](https://forum.mustachianpost.com/user_avatar/forum.mustachianpost.com/mrcheese/32/2500_2.png) [@MrCheese](https://forum.mustachianpost.com/u/MrCheese)\
**Post date:** [February 1, 2022, 2:56pm UTC](https://forum.mustachianpost.com/t/portfolio-analysis-with-diy-tool-in-python/7826/3 "2022-02-01T14:56:18Z")

</div>

I use [beancount](https://github.com/beancount/beancount). Use the search function to find the various threads about it.

---

<div class="post-metadata">

**Author:** ![Burningstone](https://forum.mustachianpost.com/user_avatar/forum.mustachianpost.com/burningstone/32/12334_2.png) [@Burningstone](https://forum.mustachianpost.com/u/Burningstone)\
**Post date:** [February 1, 2022, 4:16pm UTC](https://forum.mustachianpost.com/t/portfolio-analysis-with-diy-tool-in-python/7826/4 "2022-02-01T16:16:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tarioch](https://forum.mustachianpost.com/letter_avatar_proxy/v4/letter/t/22d042/32.png) [@tarioch](https://forum.mustachianpost.com/u/tarioch)\
**Post date:** [February 1, 2022, 5:52pm UTC](https://forum.mustachianpost.com/t/portfolio-analysis-with-diy-tool-in-python/7826/5 "2022-02-01T17:52:29Z")

</div>

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](https://xirr.readthedocs.io/en/latest/)

---

<div class="post-metadata">

**Author:** ![svenaki](https://forum.mustachianpost.com/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@svenaki](https://forum.mustachianpost.com/u/svenaki)\
**Post date:** [February 2, 2022, 8:02am UTC](https://forum.mustachianpost.com/t/portfolio-analysis-with-diy-tool-in-python/7826/6 "2022-02-02T08:02:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Burningstone](https://forum.mustachianpost.com/user_avatar/forum.mustachianpost.com/burningstone/32/12334_2.png) [@Burningstone](https://forum.mustachianpost.com/u/Burningstone)\
**Post date:** [February 2, 2022, 11:08am UTC](https://forum.mustachianpost.com/t/portfolio-analysis-with-diy-tool-in-python/7826/7 "2022-02-02T11:08:16Z")

</div>

> [@svenaki](#):
>
> Do FTSE/MSCI offer good APIs to enable building such a product?

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.

---

<div class="post-metadata">

**Author:** ![Alex](https://forum.mustachianpost.com/user_avatar/forum.mustachianpost.com/alex/32/276_2.png) [@Alex](https://forum.mustachianpost.com/u/Alex)\
**Post date:** [February 3, 2022, 9:31am UTC](https://forum.mustachianpost.com/t/portfolio-analysis-with-diy-tool-in-python/7826/9 "2022-02-03T09:31:33Z")

</div>

> [@tarioch](#):
>
> 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](https://xirr.readthedocs.io/en/latest/)

Nice! This isn’t an actual beancount plugin, though, is it? I’ve been hoping to see some progress to [Investment tools for Fava: Help me develop! · Issue #1082 · beancount/fava · GitHub](https://github.com/beancount/fava/issues/1082), but it’s moving very slowly.
