Yfinance

 https://analyzingalpha.com/yfinance-python


Yahoo Finance offers an excellent range of market data on stocks, bonds, currencies, and cryptocurrencies. It also provides news reports with various insights into different markets from around the world – all accessible through the yfinance python library.


https://pypi.org/project/yfinance/


most popular way to access Yahoo Data, and the API is open-source and free to use. There are other free and paid APIs to access Yahoo’s data, but yfinance is the best place to start, and here’s why.

  1. It’s simple to use

  2. It returns data as Pandas DataFrames

  3. One-minute bar granularity

pip install yfinance --upgrade --no-cache-dir


Import pandas and yfinance libraries


https://pandas.pydata.org/


>>> import pandas as pd

>>> import yfinance nas yf


Lists modules of tf


>>> dir(yf)

['Ticker', 'Tickers', '__all__', '__author__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'base', 'data', 'download', 'exceptions', 'multi', 'pdr_override', 'scrapers', 'set_tz_cache_location', 'shared', 'ticker', 'tickers', 'utils', 'version']

>>> 


Use the apple ticker and create an object aapl


>>> aapl = yf.Ticker('aapl')

>>> 


>> aapl

yfinance.Ticker object <AAPL>

>>> 



Leverage one of yfinance methods to pull history of apple opening price, high, low, closing price, volume traded and dividends date


>>> data = aapl.history()


Display top lines of history


>>> data.head()

                                 Open        High         Low       Close    Volume  Dividends  Stock Splits

Date                                                                                                        

2023-05-10 00:00:00-04:00  172.781019  173.789619  171.662556  173.320267  53724500       0.00           0.0

2023-05-11 00:00:00-04:00  173.609878  174.348846  171.932190  173.510010  49514700       0.00           0.0

2023-05-12 00:00:00-04:00  173.619995  174.059998  171.000000  172.570007  45497800       0.24           0.0

2023-05-15 00:00:00-04:00  173.160004  173.210007  171.470001  172.070007  37266700       0.00           0.0

2023-05-16 00:00:00-04:00  171.990005  173.139999  171.800003  172.070007  42110300       0.00           0.0

>>> 


Leverge different commands available



No comments:

Post a Comment

Notes 3-18-25

https://uconn-sa.blogspot.com/  We were able to launch an app engine program from our compute engine instance.   I'd like to get all wo...