Python

Updates to yahoo_fin package

Package updates

First of all – thank you to everyone who has contacted me regarding the yahoo_fin package! Due to some changes in Yahoo Finance’s website, I’ve updated the source code of yahoo_fin. To upgrade to the latest version (0.8.4), you can use pip:


pip install yahoo_fin --upgrade

Get weekly and monthly stock prices

The most recent version includes all functionality from the previous version, but now also includes the ability to pull weekly and monthly historical stock prices in the get_data method.


from yahoo_fin import stock_info as si

# default daily data
daily_data = si.get_data("amzn") 

# get weekly data
weekly_data = si.get_data("amzn", interval = "1wk")

# get monthly data
monthly_data = si.get_data("amzn", interval = "1mo")


Speed-up in functions

The options module includes an update behind the get_expiration_dates function. The functionality is the same, but the code was slightly modified to make it run faster.


from yahoo_fin import options

# get expiration dates for AAPL option chain
options.get_expiration_dates("aapl")

Other functionality

As a reminder for anyone new to, or less familiar with, yahoo_fin, the package has two modules – stock_info for collecting stock price and fundamentals data, and options for extracting option prices. Here’s a few more examples.

Download balance sheets, cash flows, and income statements


# get AAPL balance sheet
si.get_balance_sheet("aapl")

# get AAPL cash flow info
si.get_cash_flow("aapl") 

# get AAPL income statement
si.get_income_statement("aapl")


Get company stats


si.get_stats("aapl")

Get top gainers and losers of the day


si.get_day_gainers()

si.get_day_losers()

For more details on the options functionality, check out this post, or here for getting real-time stock prices.

For full documentation, check out this link.

If you have any questions or find any issues regarding yahoo_fin, please feel free to contact me here.

Andrew Treadway

Recent Posts

Software Engineering for Data Scientists (New book!)

Very excited to announce the early-access preview (MEAP) of my upcoming book, Software Engineering for…

2 years ago

How to stop long-running code in Python

Ever had long-running code that you don't know when it's going to finish running? If…

3 years ago

Faster alternatives to pandas

Background If you've done any type of data analysis in Python, chances are you've probably…

3 years ago

Automated EDA with Python

In this post, we will investigate the pandas_profiling and sweetviz packages, which can be used…

3 years ago

How to plot XGBoost trees in R

In this post, we're going to cover how to plot XGBoost trees in R. XGBoost…

4 years ago

Python collections tutorial

In this post, we'll discuss the underrated Python collections package, which is part of the…

4 years ago