Using Python for Financial Data/Analyses

Ongoing Notes

Yahoo Finance one maintained an API.
However, this one is where it is at:

Basic use of yfinance:

from pandas_datareader import data as pdr
import yfinance as yf

The library is pretty deep. However, for most things, IMO, the “ticker” class is probably all you need.

aaplObj = yf.Ticker(“AAPL”)
# get dividends for 2018


basic econometrics

I am not an economist, but I often want to quickly reference basic economic info for various countries. I either want to whip up a simple data science project for a student, teach my kids more about geopolitics, or I just want to factcheck an argument.

For example, I was listening to a news story the other day (from a reputable journalist) that made some pretty outlandish sounding claims about China’s GDP. The claim was that China’s GDP growth showed the largest increases in the last 8 years than in any other time in their history. While I am very enthusiastic and impressed by China’s growth over the last eight years, I was certain they had bigger eight year spans of growth.

For simple problems like this I will often check the CIA fact-book (which is an amazing resource, one of the best public facing things the CIA does):

However, as great as the CIA may be, this is still a US government website. I am a Patriot through-and-through, so I am not disparaging the accuracy. But, I am disparaging our government’s ability to make user friendly websites.

So, if you want to get up to date on some part of the world, the fact-book is amazing. But, if you want to simply scrape basic ¬†GDP data to then make an 8-year moving average, well get the spreadsheet out. For situations like this “Trading Economics” is perfect. The site is very well laid out and for most simple economic fact questions it has, or can easily display, the answers you seek.


It took me about 2 seconds to plot all available GDP growth data from China, with what appears to be a three year moving average (used its default). The site easily exports raw data, and has a great API. Now, I haven’t dug deep into economic databases, so there might be better ones (let me know!), but this seems like a one-stop shop for most people.