Before you run this notebook, please download the yahooFinance.py module and save it in the same directory as this notebook.
Then you can import it by using the import
command.
Note: we are using import as
command, which allowes us to use a shorthand notation of the library name. This way you only need to type yf
instead of yahooFinance
in further code. Another advantage is that the module can be reloaded (handy if you change the module code) without restarting the interpreter.
In [1]:
import yahooFinance as yf # import
Now let's take a look at the module documentation
In [2]:
help(yf)
Show a list of all names defined in the package
In [3]:
dir(yf)
Out[3]:
Let's run some functions from the module
In [4]:
yf.getQuote(['SPY','QQQ','AAPL']) # get last available quote from Yahoo
Out[4]:
In [5]:
df = yf.getHistoricData('SPY',(2012,1,1)) # get daily historic data from Yahoo
print df.tail(20) # print last 20 days of data table
By importing the yahooFinance
module you can access functions for working with yahoo finance. The good thing about modules is that you don't even have to know how they work or what is inside them. The only thing you need is a little bit of documentation about the contained functionality.
We will be taking a closer look inside the yahooFinance.py
next week.