DEV Community

Cover image for Automating personal investment reports with Gitlab Pages and CI/CD pipelines
Sagar Chakravarthy
Sagar Chakravarthy

Posted on • Originally published at bpsagar.substack.com

Automating personal investment reports with Gitlab Pages and CI/CD pipelines

πŸ‘‹ Introduction

I’ve been investing in stocks and mutual funds in the Indian stock market for a couple of years. The reports available on the trading platforms are not sufficient. Moreover, I use multiple platforms making it impossible to look at the health of my portfolio as a whole. So I set out to create my personal investment report. These were my expectations:

  • Reports should be available at my fingertips
  • Minimal cost and maintenance

You can read about my investment strategy here.

πŸ’Έ Data collection

To create reports I needed two datasets:

  1. Trades (buys and sells)
  2. Latest prices

1. Trades

The trading platform I use doesn’t provide APIs to fetch my trades automatically πŸ˜•. So I manually export the trade book (as CSV) end of every month and store them in a β€œdata” folder in the repository.

2. Latest prices

I wrote a python script that crawls the stock exchange sites. It collects the end of day prices which is good enough for my usecase. You can check out the code here.

πŸ“ˆ Report generation

With all my trades and their latest prices, I could calculate the metrics that I was interested in:

  • Total investment
  • Current value of the portfolio
  • Returns (absolute and percentage)
  • XIRR (code to calculate XIRR)

I segregated my trades into equity and debt and calculated the same metrics for the two categories as well. With these metrics, I used Jinja templating engine to display these numbers in a simple cards design πŸ‘‡

Screenshot of investment report

Finally, I set up Gitlab’s pipeline schedule to generate the above HTML file every day after the markets closed. And with Gitlab pages, served the same HTML by placing it inside the public folder. For private repositories, only members can access the Gitlab pages thus making it my personal investment report πŸ‘»


Are you an investor looking to create a personal investment report just like this one? Feel free to drop your comments (or reach out to me on Twitter), I can share more details.


If you liked this article, you can subscribe to my newsletter to get new articles directly in your inbox πŸ™

Top comments (0)