Using yfinance library to follow up spec ...

Using yfinance library to follow up specific stock values from Yahoo Finance site

Jul 09, 2022

Introduction


This a useful python program to read stock values from Yahoo Finance site, if you want to follow up any specific stock,  as a first step you need to identify the stock symbol (ticker), that means a unique series of letters assigned to a security for trading purposes, for example: 

NFLX: Netflix, Inc.

TWTR: Twitter, Inc.

AMZN: Amazon.com, Inc.

AAPL: Apple Inc.

GOOG: Alphabet Inc.

TSLA: Tesla, Inc.

The stock values and the financial information that will be obtained from the Yahoo Finance site, could compare with the information published in the Netflix official site for investors:

https://ir.netflix.net/financials/quarterly-earnings/default.aspx

Python Code

Import libraries

import pandas as pd

import yfinance as yf

import matplotlib.pyplot as plt

Create a yfinance object

  • stock

  • start date

  • end date

stocks = yf.download(stock, start ="2010-01-01", end="2022-07-08")

Get the values from Yahoo Finance site into a pandas dataframe

 df = pd.DataFrame(stocks)

Show the obtained stock values by date

df.head()

df.tail()

Get additional information about a specific stock, using the ticker module.

  • nflx = yf.Ticker(stock)

  • nflx.info

  • nflx.financials

  • nflx.quarterly_financials

  • nflx.balance_sheet

  • nflx.quarterlybalancesheet

  • nflx.quarterly_earnings

  • nflx.recommendations

  • nflx.news


Graphic the “closing” stock values.

  • data = stocks.loc[:,"Close"].copy()

  • data.plot(figsize = (17, 8),fontsize =18)

  • plt.style.use("seaborn")

  • plt.title('Netflix',fontsize=18, color='blue')

  • plt.xlabel('Years',fontsize=14, color='blue')

  • plt.ylabel('Price',fontsize=14, color='blue')

  • plt.show()

The complete python code is available in Google Colab & Github.

Google Colab link:

https://colab.research.google.com/drive/1bYfhKjknYjtm6eBb2ODqPY4ZvKSb8SbI?usp=sharing

Github link:

https://github.com/pmraulgarcia/codexicans/blob/master/yfinance_nflx.ipynb


Contact:

Raúl García

Electronic Systems Engineer

#DataScience #BusinessAnalytics #BusinessAnalysis #DataAnalysis #DataAnalytics #BusinessIntelligence #MachineLearning #ArtificialIntelligence #WorldClassFinance #GeeksAlfa #VisualCapitalist #Finance4.0

https://www.linkedin.com/in/raulgarciamx/

http://www.raulgarciamx.com/

https://linktr.ee/raulgarciamx

Enjoy this post?

Buy GeeksAlfa a book

More from GeeksAlfa