Introduction to the Dividend Chart Bot
How this project started and how are the charts generated.
TLDR: this post is about the process to go from raw data to the final charts. For details about how to use them, it’s coming soon, stay tuned 😉
How this project started?
This summer, my wife traveled abroad for a few weeks. With the time difference, she was already asleep when I reach home after work. I had in mind to create fancy looking charts about stock prices and dividends but never dedicated time for it. This was the opportunity.
This small side-project involved:
Manipulating stock data using yfinance (python library)
Advanced use of altair (python dataviz library)
Automated publications through the Twitter API
Serverless deployment using Google Cloud Run
After a first draft built using streamlit, it was quickly turned into an automated twitter account: @DividendChart
How are the charts generated?
Data is collected from yahoo finance using the yfinance library. If the selected period is 3 years, we extend it to 4 years to make sure we fully cover the starting year.
Dividend data is then processed to correct some inherent issues with yahoo finance data, as mentioned in the next section. Data is also trimmed to reflect full years only.
The output of this step is a table with the following details:
These dividends are then merged with the price history to calculate the dividend yield over time
We can then calculate the deciles of the dividend yield:
The calculation of these deciles is important: it will define the size of each colored band on the chart.
What does it mean in this context?
The 0th percentile (the lowest yield) was 0.66% during the 3-year period.
The 100th percentile (the highest yield) was 1.96%.
The 50th percentile (the median yield) was 1.05%.
We use these percentiles to ask the following questions:
If the stock were to yield as its 5-year median, what should the stock price be considering the current level of distribution?
We repeat the same question for each of the deciles.
For example here: on May 16th 2018, if the stock was yielding in-line with its median (50th percentile), its price should have been $160.40.
The final step is the generation of the graphs. The latest table contains all necessary information to draw the colored bands. The other charts are simpler: dividend yield and drawdown.
Some information is added to help reading the charts:
Upside/downside to median yield: how much should the stock gain or loose for the yield to be equal to its median?
Current percentile of dividend yield: how often has the stock yielded more/less?
Drawdown: how much has the stock lost since its latest all-time high?
How to make sense of this chart? How to screen for undervalued/overvalued stocks? Has the stock X ran to high recently? It will all be detailed in a future post 🙂
Important comments
Data from yahoo finance is not always accurate: there are missing distributions, erroneous amounts etc.
Exceptionnal distributions not considered.
Dividend raises/cuts that have just been anounced are not taken into account until the effective payment date.
None of these charts constitute financial advice. Do you own research.
Links
You can also get in touch with me on my personnal Twitter account @hugo_le_moine_.
This is the first issue on this substack, any comment or feedback would be highly appreciated!
Thanks for posting this. Looking forward to future articles.