Skip to content
andrea-dm edited this page Sep 12, 2018 · 29 revisions

Welcome to the yahoo-finance-pynterface wiki!


A brief review

It is really easy to use the Yahoo Finance Python Interface!
We may use yahoo-finance-pynterface to retrieve the timeseries of stock prices (anything between open, high, low, and close) and volumes as well as the timeseries of dividends and stock splits.
The package provides the following three methods to interact with the Yahoo Finance API:

  • yahoo.Get.Prices
  • yahoo.Get.Dividends
  • yahoo.Get.Splits

As a matter of fact, the Yahoo Finance Python Interface provides also the method

  • yahoo.Get.Info

which is designed to expose basic info about the financial instrument we are interested in.


yahoo.Get.Prices

This method has just one mandatory argument: the ticker!
As an example, the following three lines of code will print on screen the timeseries of AAPL close prices:


    In[1]: import yahoo_finance_pynterface as yahoo
    
    In[2]: data = yahoo.Get.Prices("AAPL")
    In[3]: print(data.Close)

Notice that the object data returned by the method yahoo.Get.Prices is an instance of the class pandas.DataFrame


Since data is a pandas.DataFrame, we can plot the result in a line chart as follows:


    In[4]: import matplotlib.pyplot as plt
    In[5]: data.plot(y='Close')
    In[6]: plt.show()

Check the script getting_price.py for a complete example!


The first argument of yahoo.Get.Prices is not restricted to only one ticker at the time!
As the function annotations suggest, it is ready to accept a list of str as well:


    In[7]: of_these_tickers = ["AAPL", "GOOGL"]
    In[8]: data = yahoo.Get.Prices(of_these_tickers)

However, in such a case a dict of str, pandas.Dataframe pairs is returned:


    In[9]: type(data)
    Out[9]: <class 'dict'>

Advanced usage

work in progress


For the developers

If you are a developer, or just a very curious person, you might be interested in the following:

  • why the namespace Get?
  • what are the "access modes" (or "api")?
  • why concurrency?

Implementation

The following are the classes implemented in yahoo-finance-pynterface:

  • class Get
  • class api.Session
  • class api.Response
  • class api.Query
  • enumeration class api.EventsInQuery
  • enumeration class api.AccessModeInQuery
  • enumeration class core.ProcessingMode
  • enumeration class core.API
Clone this wiki locally