Automated Stock Diagrams with Python

Automated stock diagrams with Python is actually a rather useful idea, if you want to see how your portfolio is distributed. Just by using 2 columnes – “Ticker” and “Shares” in a CSV file, you can obtain a lot of additional information about it. E.g., how it is diversified amongst different sectors and how much are your different shares worth. Once you obain the basic idea, you can go and create further useful analytical insides.

This is how a sample input file looks like:

This is a simple input file. It means that we are having 50 shares from 3 companies – F, GOOG and AAPL.

Then we start creating the tasks by importing the libraries and reading the csv files:

Then we fetch data with yfinance into a dataframe and write the dataframe into a csv file:

The next step is to generate a pie chart for industries:

50 shares from 3 companies look like this into USD.

As a last step, we go with the treemap. The library squarify helps there:

50 shares from 3 companies look like this into rectangulars (size of the rectangular is based on USD value of these 50 shares).

The GitHub code is here:

https://github.com/Vitosh/Python_personal/tree/master/YouTube/021_Python-And-Automated-Portfolio-Analysis

Enjoy it! 🙂

Tagged with: , , , ,