

Maximizing Dividend Yields: A Stock Market Script Showcase
Dividends are awesome! They are a way to earn passive income, and an incentive to hold onto a stock long-term. Simply put, a dividend is money that the issuing company pays out every so often to stock owners. If you have enough money, and it would need to be a lot of money, you could use it to put your money in the bank and live off the interest.
So, you might be thinking "Sweet! I want stonks now! Dividends gimme gimme!"
Problem
Not every stock pays out dividends. Most don't in fact. To compound this further, trading apps are very slow to state if a given stock pays dividends in the first place. When you pull the stock information on a given stock on your favourite trading app, you likely see a screen that looks like this:

That is courtesy of Wealthsimple. They recommended that for novices to trade. Clicking the link and signing up will help support me.
So, you want information on dividends, so next is Googling "Stocks with High Dividends!" Ok, dividends are paid on a schedule, usually, the last business day of the month, and the payout is so many cents per share. Not per dollar invested, per share. So $0.30 per share might be all well and good, but the stock is also $70 per share. You must invest $210 to make about $1 per payout. So, with so many stocks, how can you get the biggest bang for your buck?
Enter my script
To put it simply, it's a Python script that grabs the needed information and makes the calculation to determine which stock has the highest dividend per dollar invested. The full script can be found on my GitHub.
To run it, you first need the following dependencies:
- python-dotenv
- pandas
Next, you need an api_key from Financial Modeling Prep. Their free plan is sufficient for what we need to do. Once you have the api_key, you need to create an .env file and write the following in it:
key=*your API key here*
What is this code doing?
After initializing the variables, it makes two API pulls: one on the available trade endpoint and one on the dividend schedule calendar, set to grab all payouts from the last 30 calendar days.
Next, the responses are placed inside two Pandas dataframes, one dataframe for each. The code then takes the dataframe with the dividend schedule, grouped by stock symbol, and adds up the dividends - this is to account for the fact that some stocks pay out more than once a month. Next the two dataframes are merged into the stock symbol as an inner join. Lastly, the ratio column is added, the formula being dividend_sum/current_stock_price. The resulting dataframe is saved as a CSV in the working directory, and the top five stocks with the highest ratio are shown in the console as a printed dataframe.
One note
This code as uploaded will only show stocks that are traded on the TSX (Toronto Stock Exchange). If you want to use this for all stocks, or another exchange, change/comment line 33, reading:
tsx_stocks = stocks[stocks['exchangeShortName']=='TSX']
At the time of writing, the winning stock was INO-UN with a ratio of 0.11 (floor-rounded) per dollar invested. The stock when the code ran was $1.18 per share and paid out $0.10 per share. Based on this I bought 800 shares of this stock. On November 30th, I should get a payout of $80. Will keep you all posted!
Also, thank you for getting this far. This is my first-ever note on notd.io. Expect great things to come!
Who am I?
I am Shannon Frances Smith. I am the founder of Space Whale Dreams. I have a degree in Computer Science and certifications in Data Science. I also stream to Twitch.tv, write speculative fiction, and run an e-commerce art store.
