Greetings!
I've previously introduced my Python package in this post. Since then, I've significantly enhanced its performance and expanded its capabilities.
What My Project Does
A lightweight python package designed for the efficient retrieval of financial data from various sources like Yahoo Finance, Nasdaq, Digrin and JustETF websites (somewhat similar to yfinance). This tool provides functionality akin to yfinance but with broader data access.
Main benefits of stockdex over yfinance
-
Fresh data: Yahoo Finance often delays updates to financial data by several days while Nasdaq and other sources typically update on the day reports are released. Stockdex enables access to this fresher data, such as quarterly earnings.
-
Broader Data Sources: Unlike yfinance which relies solely on the Yahoo Finance API, Stockdex aggregates data from multiple platforms including Digrin, JustETF, Nasdaq, and Yahoo Finance. For specific examples of data retrieval, refer to this readme.
-
Access to Historical Data: Yahoo Finance limits access to the most recent five annual or four quarterly reports. Stockdex, however, taps into sources that maintain extensive historical archives not available through Yahoo Finance.
Target Audience
The package is targeted at people who are interested in financial analysis using python.
Explore more:
-
Github Repo Link
-
Pypi link
Videos
Where Can I Scrape Reliable Stock Market Data?
Reliable stock market data can be found on platforms like Yahoo Finance, Google Finance, Investing.com, and Bloomberg, all of which offer publicly accessible financial information.
Is It Legal to Scrape Stock and Other Investment Product Data?
In most cases, scraping stock market data is legal if the data is publicly accessible—meaning no login or paywall is required to view it. That said, it’s important to review the terms and conditions of each investment platform before scraping to avoid violating any rules or regulations. This guide covers the legal aspects of web scraping in more detail.
How Do I Make My Web Scraper Automatically Extract Stock Market Information?
To automate stock market data extraction, you can use ScraperAPI’s Data Pipeline. It lets you schedule your scraper to pull specific datasets—across up to 10,000 URLs—at set times, all without writing any code. Learn more about ScraperAPI’s Data Pipeline feature.
Yahoo Finance is one of the free sources to get stock data. You can get the data either using pandas datareader or can get using yfinance library. The method to get data from yfinance library is shown below.
import yfinance as yf
# Get the data of the stock AAPL
data = yf.download('AAPL','2016-01-01','2019-08-01')
Wiki is one of the free source available on quandl to get the data for the 3000+ US equities. This is a community maintained data. Recently it is stopped being maintained but however, it is a good free source to backtest your strategies. To get the data, you need to get the free API key from quandl and replace the in the below code with your API key.
# Import the quandl package
import quandl
# Get the data from quandl
data = quandl.get("WIKI/KO", start_date="2016-01-01", end_date="2018-01-01",
api_key=<Your_API_Key>)
Note: Quandl requires NumPy (v1.8 or above) and pandas (v0.14 or above) to work. To get your API key, sign up for a free Quandl account. Then, you can find your API key on Quandl account settings page.
See below. Code is written in Python 2.7, but should work in 3.5 when you replace the print function. Make sure when you copy the spacing is correct in your editor: a tab is 4 spaces etc.
# pip install datareader
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader.data as web
import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime, timedelta
#stock of interest
stock=['MSFT','SAP','V','JPM']
# period of analysis
end = datetime.now()
start = end - timedelta(days=500)
for i in range(len(stock)):
f = web.DataReader(stock[i], 'morningstar', start, end)
# nice looking timeseries (DataFrame to panda Series)
f = f.reset_index()
f = pd.Series(f.Close.values,f.Date)
print "Start: Year, Month, Day, Time"
print str(start)
f.plot(label=stock[i]);
plt.legend()
plt.ylabel('price in [USD]')
plt.show();