Yahoo Finance

If you are interested in knowing about the trends of the business world and have a thirst to get updates about stocks and bonds, or if you are the one who has invested in them, then you may crave an update that occurs every minute. Google Finance is a financial website that was developed by Google that's made this straightforward by providing the required information and also letting us customize our needs according to our interests.

Google's API became less reliable during 2017 and has become highly deprecated because of the unavailability of a stable replacement due to large breaks in the API.

An alternative to it is Yahoo Finance, which is similar to Google Finance, and is popular among users for its robust data and consistency.

Now let's use pandas-datareader to get information related to stocks, mutual funds, and anything related to finance using the Google Finance API.

    import pandas as pd
    from pandas_datareader import data
    symbols=['AAPL','GOOGL','FB','TWTR']
    # initializing a dataframe
    get_data = pd.DataFrame()
    stock = pd.DataFrame()
    
    
    for ticker in symbols:
       get_data = get_data.append(data.DataReader(ticker, 
                           start='2015-1-1', 
                           end='2019-6-23', data_source='yahoo'))
    
       for line in get_data:
            get_data['symbol'] = ticker
    
       stock = stock.append(get_data)
       get_data = pd.DataFrame()
    
    stock.head()
  

The preceding code results in the following output:

Date filtered stock data for Apple, Google, Facebook, and Twitter
stock.describe() 

This results in the following output:

Summary statistics of the stock data

Take a look at the following code:

 # get the list of column names
    cols = [ col for col in stock.columns]
    cols                      

This results in the following output:

Take a look at the following code:

 # returns the symbol of the highest traded value among the symbols
 stock.loc[stock['High']==stock['High'].max(), 'High']

This results in the following output:

The preceding code will return a DataFrame that gives you full details about the stock prices for each and every day between the two dates for Apple[AAPL], Google[GOOGL], FB[FB], and Twitter[TWTR].

It is important to get to know your data before performing any kind of analysis. Please take the following things into account:

  • High is the highest price that the stock was traded for on that particular date.
  • Low is the lowest price that the stock was traded for on that particular date.
  • Open is the price that the stock was when the date started.
  • Close is the price that the stock was when the market closed for that date.
  • Volume is the number of physical shares that were traded for that particular stock.
  • Adj Close is the price that the stock was after the market closed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset