Available Free Stock Data Sources


Available Stock Data Sources






In [11]:
import pandas as pd
#import pandas_datareader.data as pdr
from datetime import datetime, timedelta
import requests as re
import json
import urllib as ur
In [21]:
start=datetime.now()-timedelta(days =256)
end = datetime.now()

Historical Data

1. Quandl

In [5]:
pdr.DataReader("AAPL","quandl",start,end).head()
Out[5]:
Open High Low Close Volume ExDividend SplitRatio AdjOpen AdjHigh AdjLow AdjClose AdjVolume
Date
2018-03-27 173.68 175.15 166.92 168.340 38962839.0 0.0 1.0 173.68 175.15 166.92 168.340 38962839.0
2018-03-26 168.07 173.10 166.44 172.770 36272617.0 0.0 1.0 168.07 173.10 166.44 172.770 36272617.0
2018-03-23 168.39 169.92 164.94 164.940 40248954.0 0.0 1.0 168.39 169.92 164.94 164.940 40248954.0
2018-03-22 170.00 172.68 168.60 168.845 41051076.0 0.0 1.0 170.00 172.68 168.60 168.845 41051076.0
2018-03-21 175.04 175.09 171.26 171.270 35247358.0 0.0 1.0 175.04 175.09 171.26 171.270 35247358.0

2. ALPHA VANTAGE

The historical data here are all adjusted price

In [19]:
api = "R9KJYWUBMIDAXNW7"
function ="TIME_SERIES_DAILY_ADJUSTED" #daily
#function="TIME_SERIES_INTRADAY" #intraday
#function="TIME_SERIES_WEEKLY_ADJUSTED" #weekly  
data_size = "compact"

ticker = "AAPL"

api_url = 'https://www.alphavantage.co/query?' + 'function={}&symbol={}&apikey={}&outputsize={}&datatype=csv'\
                                     .format(function, ticker, api,data_size)

In this case, the API returns CSV file

In [20]:
pd.read_csv(api_url).head()
Out[20]:
timestamp open high low close adjusted_close volume dividend_amount split_coefficient
0 2018-09-21 220.78 221.36 217.29 217.66 217.66 96246748 0.0 1.0
1 2018-09-20 220.24 222.28 219.15 220.03 220.03 26608794 0.0 1.0
2 2018-09-19 218.50 219.62 215.30 218.37 218.37 27123833 0.0 1.0
3 2018-09-18 217.79 221.85 217.12 218.24 218.24 31571712 0.0 1.0
4 2018-09-17 222.15 222.95 217.27 217.88 217.88 37195133 0.0 1.0

3.Barchart OnDemand Database

In [22]:
api_key = '95b5894daf3abced33fe48e7f265315e'
#you need to phrase the date format
start=start.strftime("%Y%m%d%H%M%S")
end=end.strftime("%Y%m%d%H%M%S")
# This is the required format for datetimes to access the API

api_url = 'http://marketdata.websol.barchart.com/getHistory.csv?' + \
                        'key={}&symbol={}&type={}&startDate={}&endDate={}&interval={}'\
                         .format(api_key, "AAPL", "daily", start,end,1)
#list of available frequency: minutes, nearbyMinutes, formTMinutes, daily, dailyNearest, dailyContinue, weekly,
#                           weeklyNearest, weeklyContinue, monthly, monthlyNearest, monthlyContinue, quarterly, 
#                             quarterlyNearest, quarterlyContinue, yearly, yearlyNearest, yearlyContinue

temp = pd.read_csv(api_url, parse_dates=['timestamp'])
temp.set_index('timestamp', inplace=True)
temp
Out[22]:
symbol tradingDay open high low close volume openInterest
timestamp
2018-04-23 04:00:00 AAPL 2018-04-23 165.6084 165.6977 162.8884 164.0300 36784764 NaN
2018-04-24 04:00:00 AAPL 2018-04-24 164.4568 165.1120 160.0394 161.7468 33940536 NaN
2018-04-25 04:00:00 AAPL 2018-04-25 161.4292 164.2087 161.2207 162.4516 28591366 NaN
2018-04-26 04:00:00 AAPL 2018-04-26 162.9182 164.5164 162.1737 163.0175 28169276 NaN
2018-04-27 04:00:00 AAPL 2018-04-27 162.7991 163.1267 159.4538 161.1314 35918824 NaN
2018-04-30 04:00:00 AAPL 2018-04-30 160.9428 166.0352 160.6549 164.0498 42740376 NaN
2018-05-01 04:00:00 AAPL 2018-05-01 165.1914 167.9610 164.0598 167.8617 53964468 NaN
2018-05-02 04:00:00 AAPL 2018-05-02 173.9468 176.4484 172.5273 175.2770 67030144 NaN
2018-05-03 04:00:00 AAPL 2018-05-03 174.5921 176.2002 173.1626 175.5947 34319412 NaN
2018-05-04 04:00:00 AAPL 2018-05-04 176.9447 182.9008 176.8653 182.4839 56615884 NaN
2018-05-07 04:00:00 AAPL 2018-05-07 183.8240 186.2957 183.3971 183.8041 42764552 NaN
2018-05-08 04:00:00 AAPL 2018-05-08 183.6354 184.8564 182.3201 184.6876 28612220 NaN
2018-05-09 04:00:00 AAPL 2018-05-09 185.1839 186.0277 183.8637 185.9880 23382424 NaN
2018-05-10 04:00:00 AAPL 2018-05-10 186.3652 188.9760 186.2759 188.6484 28195670 NaN
2018-05-11 04:00:00 AAPL 2018-05-11 188.8278 189.3958 186.7949 187.9309 26304130 NaN
2018-05-14 04:00:00 AAPL 2018-05-14 188.3494 188.8676 187.2035 187.4924 20851574 NaN
2018-05-15 04:00:00 AAPL 2018-05-15 186.1272 186.4162 184.4531 185.7884 23778202 NaN
2018-05-16 04:00:00 AAPL 2018-05-16 185.4197 187.8014 185.3500 187.5223 19250276 NaN
2018-05-17 04:00:00 AAPL 2018-05-17 187.3430 188.2498 185.7087 186.3365 17354652 NaN
2018-05-18 04:00:00 AAPL 2018-05-18 186.5358 187.1536 185.4795 185.6589 18361872 NaN
2018-05-21 04:00:00 AAPL 2018-05-21 187.3430 188.6085 186.2568 186.9743 18465234 NaN
2018-05-22 04:00:00 AAPL 2018-05-22 187.7216 188.2199 186.1272 186.5059 15294151 NaN
2018-05-23 04:00:00 AAPL 2018-05-23 185.6987 187.8412 185.1108 187.7017 20128748 NaN
2018-05-24 04:00:00 AAPL 2018-05-24 188.1103 188.1800 185.5592 187.4924 23315384 NaN
2018-05-25 04:00:00 AAPL 2018-05-25 187.5722 188.9872 186.9942 187.9209 17522138 NaN
2018-05-29 04:00:00 AAPL 2018-05-29 186.9444 188.0903 186.2169 187.2433 22592960 NaN
2018-05-30 04:00:00 AAPL 2018-05-30 187.0639 187.3430 186.1272 186.8447 18756050 NaN
2018-05-31 04:00:00 AAPL 2018-05-31 186.5657 187.5722 185.4895 186.2169 27579086 NaN
2018-06-01 04:00:00 AAPL 2018-06-01 187.3330 189.5951 187.0938 189.5751 23524716 NaN
2018-06-04 04:00:00 AAPL 2018-06-04 190.9603 192.7440 190.6813 191.1596 26358218 NaN
2018-09-10 04:00:00 AAPL 2018-09-10 220.9500 221.8500 216.4700 218.3300 39516400 NaN
2018-09-11 04:00:00 AAPL 2018-09-11 218.0100 224.3000 216.5600 223.8500 35749000 NaN
2018-09-12 04:00:00 AAPL 2018-09-12 224.9400 225.0000 219.8400 221.0700 49278700 NaN
2018-09-13 04:00:00 AAPL 2018-09-13 223.5200 228.3500 222.5700 226.4100 41706300 NaN
2018-09-14 04:00:00 AAPL 2018-09-14 225.7500 226.8400 222.5200 223.8400 31999200 NaN
2018-09-17 04:00:00 AAPL 2018-09-17 222.1500 222.9500 217.2700 217.8800 37195100 NaN
2018-09-18 04:00:00 AAPL 2018-09-18 217.7900 221.8500 217.1200 218.2400 31571700 NaN
2018-09-19 04:00:00 AAPL 2018-09-19 218.5000 219.6200 215.3000 218.3700 27123800 NaN
2018-09-20 04:00:00 AAPL 2018-09-20 220.2400 222.2800 219.1500 220.0300 26608700 NaN
2018-09-21 04:00:00 AAPL 2018-09-21 220.7800 221.3600 217.2900 217.6600 96246704 NaN
2018-09-24 04:00:00 AAPL 2018-09-24 216.8200 221.2600 216.6300 220.7900 27693300 NaN
2018-09-25 04:00:00 AAPL 2018-09-25 219.7500 222.8200 219.7000 222.1900 24554300 NaN
2018-09-26 04:00:00 AAPL 2018-09-26 221.0000 223.7500 219.7600 220.4200 23984700 NaN
2018-09-27 04:00:00 AAPL 2018-09-27 223.8200 226.4400 223.5400 224.9500 30181200 NaN
2018-09-28 04:00:00 AAPL 2018-09-28 224.7900 225.8400 224.0200 225.7400 22929300 NaN
2018-10-01 04:00:00 AAPL 2018-10-01 227.9500 229.4200 226.3500 227.2600 23600800 NaN
2018-10-02 04:00:00 AAPL 2018-10-02 227.2500 230.0000 226.6300 229.2800 24788100 NaN
2018-10-03 04:00:00 AAPL 2018-10-03 230.0500 233.4700 229.7800 232.0700 28654800 NaN
2018-10-04 04:00:00 AAPL 2018-10-04 230.7800 232.3500 226.7300 227.9900 32042000 NaN
2018-10-05 04:00:00 AAPL 2018-10-05 227.9600 228.4100 220.5800 224.2900 33580400 NaN
2018-10-08 04:00:00 AAPL 2018-10-08 222.2100 224.8000 220.2000 223.7700 29663900 NaN
2018-10-09 04:00:00 AAPL 2018-10-09 223.6400 227.2700 222.2500 226.8700 26891000 NaN
2018-10-10 04:00:00 AAPL 2018-10-10 225.4600 226.3500 216.0500 216.3600 41990500 NaN
2018-10-11 04:00:00 AAPL 2018-10-11 214.5200 219.5000 212.3200 214.4500 53124300 NaN
2018-10-12 04:00:00 AAPL 2018-10-12 220.4200 222.8800 216.8400 222.1100 40337800 NaN
2018-10-15 04:00:00 AAPL 2018-10-15 221.1600 221.8300 217.2700 217.3600 30791000 NaN
2018-10-16 04:00:00 AAPL 2018-10-16 218.9300 222.9900 216.7600 222.1500 29183900 NaN
2018-10-17 04:00:00 AAPL 2018-10-17 222.3000 222.6400 219.3400 221.1900 22885300 NaN
2018-10-18 04:00:00 AAPL 2018-10-18 217.8600 219.7400 213.0000 216.0200 32581300 NaN
2018-10-19 04:00:00 AAPL 2018-10-19 218.0600 221.2600 217.4300 219.3100 33078700 NaN

127 rows × 8 columns

The only drawback for Alpha Vantage is that you can not set a date range for the data

Stock Quote

In [4]:
ticker_1="AAPL"
In [95]:
quote = "https://financialmodelingprep.com/api/company/price/{}".format(ticker_1)
In [108]:
result = re.get(quote).text

result=result.replace("\n","")

result = result.replace("<pre>","")

result= json.loads(result)[ticker_1]["price"]
In [110]:
result
Out[110]:
217.66

Stock Profile

In [92]:
profile="https://financialmodelingprep.com/api/financials/income-statement/{}".format(ticker_1)
In [112]:
result = re.get(profile).text

result=result.replace("\n","")

result = result.replace("<pre>","")

result= json.loads(result)

result = DataFrame(result["AAPL"])
result
Out[112]:
Basic Cost of revenue Diluted EBITDA Gross profit Income before taxes Interest Expense Net income Net income available to common shareholders Net income from continuing operations Operating income Other income (expense) Provision for income taxes Research and development Revenue Sales, General and administrative Total operating expenses
2013-09 6477 106606 6522 57048 64304 50155 136 37037 37037 37037 48999 1292 13118 4475 170910 10830 15305
2014-09 6086 112258 6123 61813 70537 53483 384 39510 39510 39510 52503 1364 13973 6041 182795 11993 18034
2015-09 5753 140089 5793 84505 93626 72515 733 53394 53394 53394 71230 2018 19121 8067 233715 14329 22396
2016-09 5471 131376 5500 73333 84263 61372 1456 45687 45687 45687 60024 2804 15685 10045 215639 14194 24239
2017-09 5217 141048 5252 76569 88186 64089 2323 48351 48351 48351 61344 5068 15738 11581 229234 15261 26842
TTM 5171 147254 5209 79386 91922 66939 2532 50525 50525 50525 64259 5212 16414 12117 239176 15546 27663

Write a Comment