So essentially I have the free API key for Alpha Vantage in which I am using to obtain fundamental data on random stocks. To be clear I have connected to and used the API successfully and I am not in need of pulling stock price data older than 5 years.
Summed up, does anyone know if there is a way you can obtain income, balance sheet, and cash flow data on selected Tickers older than 5 years? Is this a premium feature? I couldn't find anything anywhere.
https://www.alphavantage.co/documentation/ <-- Documentation also shows only 5 years' worth of data in the 'fundamental data' examples.
import requests
import pandas as pd
from pandasgui import show
from alpha_vantage.alphavantage import AlphaVantage
from alpha_vantage.timeseries import TimeSeries
# ///////////////////////////////////////////////////////////
# FUNCTIONS FOR ALPHA VANTAGE
# ///////////////////////////////////////////////////////////
TIME_SERIES_INTRADAY = 'TIME_SERIES_INTRADAY'
TIME_SERIES_INTRADAY_EXTENDED = 'TIME_SERIES_INTRADAY_EXTENDED'
TIME_SERIES_DAILY = 'TIME_SERIES_DAILY'
TIME_SERIES_DAILY_ADJUSTED = 'TIME_SERIES_DAILY_ADJUSTED'
TIME_SERIES_WEEKLY = 'TIME_SERIES_WEEKLY'
TIME_SERIES_WEEKLY_ADJUSTED = 'TIME_SERIES_WEEKLY_ADJUSTED'
TIME_SERIES_MONTHLY = 'TIME_SERIES_MONTHLY'
TIME_SERIES_MONTHLY_ADJUSTED = 'TIME_SERIES_MONTHLY_ADJUSTED'
GLOBAL_QUOTE = 'GLOBAL_QUOTE'
SYMBOL_SEARCH = 'SYMBOL_SEARCH'
OVERVIEW = 'OVERVIEW'
EARNINGS = 'EARNINGS'
INCOME_STATEMENT = 'INCOME_STATEMENT'
BALANCE_SHEET = 'BALANCE_SHEET'
CASH_FLOW = 'CASH_FLOW'
LISTING_STATUS = 'LISTING_STATUS'
EARNINGS_CALENDAR = 'EARNINGS_CALENDAR'
IPO_CALENDAR = 'IPO_CALENDAR'
CURRENCY_EXCHANGE_RATE = 'CURRENCY_EXCHANGE_RATE'
FX_INTRADAY = 'FX_INTRADAY'
FX_DAILY = 'FX_DAILY'
FX_WEEKLY = 'FX_WEEKLY'
FX_MONTHLY = 'FX_MONTHLY'
CURRENCY_EXCHANGE_RATE = 'CURRENCY_EXCHANGE_RATE'
CRYPTO_RATING = 'CRYPTO_RATING'
CRYPTO_INTRADAY = 'CRYPTO_INTRADAY'
DIGITAL_CURRENCY_DAILY = 'DIGITAL_CURRENCY_DAILY'
DIGITAL_CURRENCY_WEEKLY = 'DIGITAL_CURRENCY_WEEKLY'
DIGITAL_CURRENCY_MONTHLY = 'DIGITAL_CURRENCY_MONTHLY'
# ///////////////////////////////////////////////////////////
# TIME SERIES FOR STOCK DATA
# ///////////////////////////////////////////////////////////
ONEMIN = 'Time Series (1min)'
FIVEMIN = 'Time Series (5min)'
FIVETEENMIN = 'Time Series (15min)'
THIRTYMIN = 'Time Series (30min)'
HOUR = 'Time Series (60min)'
FIVEMIN = 'Time Series (5min)'
DAILY = 'Time Series (Daily)'
WEEKLY = 'Weekly Time Series'
WEEKLY_ADJ = 'Weekly Adjusted Time Series'
MONTLY = 'Monthly Time Series'
MONTLY_ADJ = 'Monthly Adjusted Time Series'
# /////////////////////////////////////////////////////////
# query fundamental stock data of selected type ///////////
# /////////////////////////////////////////////////////////
def query_fundamental_data(func, symbol, outputsize='full', datatype='json', apikey='TUBY75I2F4D58X6M'):
data = {
"function": func,
"symbol": symbol,
"outputsize": outputsize, # (full) and (compact) are accepted
"datatype": datatype,
"apikey": apikey
}
return requests.get("https://www.alphavantage.co/query", data).json()
# /////////////////////////////////////////////////////////
# convert fund stock data of selected type to json ////////
# /////////////////////////////////////////////////////////
def get_fundamental_dataframe(json):
df = pd.DataFrame(json['annualReports'])
df.set_index('fiscalDateEnding', inplace=True)
return df
# /////////////////////////////////////////////////////////
# query timeseries stock data of selected type ////////////
# /////////////////////////////////////////////////////////
def query_timeseries_data(func, symbol, outputsize='full', datatype='json', apikey='TUBY75I2F4D58X6M'):
data = {
"function": func,
"symbol": symbol,
"outputsize": outputsize, # (full) and (compact) are accepted
"datatype": datatype,
"apikey": apikey
}
return requests.get("https://www.alphavantage.co/query", data).json()
# /////////////////////////////////////////////////////////
# convert time-series stock data of selected type to JSON//
# /////////////////////////////////////////////////////////
def get_timeseries_dataframe(json, type):
df = pd.DataFrame.from_dict(json[type], orient= 'index')
df.index = pd.to_datetime(df.index, format='%Y-%m-%d')
df = df.rename(columns={ '1. open': 'Open', '2. high': 'High', '3. low': 'Low', '4. close': 'Close', '5. volume': 'Volume'})
df = df.astype({'Open': 'float64', 'High': 'float64', 'Low': 'float64','Close': 'float64','Volume': 'float64',})
df = df[[ 'Open', 'High', 'Low', 'Close', 'Volume']]
return df
# /////////////////////////////////////////////////////////
# how to create dataframes for matplotlib usage //////////
# /////////////////////////////////////////////////////////
response_json = query_fundamental_data(INCOME_STATEMENT, 'MSFT')
INCOME_DATA = get_fundamental_dataframe(response_json)
#response_json = query_fundamental_data(BALANCE_SHEET, 'MSFT')
#BALANCE_DATA = get_fundamental_dataframe(response_json)
#response_json = query_fundamental_data(CASH_FLOW, 'MSFT')
#CASHFLOW_DATA = get_fundamental_dataframe(response_json)
#response_json = query_timeseries_data(TIME_SERIES_DAILY, 'MSFT')
#STOCKPRICE_DATA = get_timeseries_dataframe(response_json, DAILY)
show(INCOME_DATA)
#show(BALANCE_DATA)
#show(CASHFLOW_DATA)
#show(STOCKPRICE_DATA)
You will notice that the results are only a mere 5 years.
Thanks in advance to anyone who can help or who can inform me if this is even possible currently or not. I have tried to find a way myself, I cannot seem to find one within the documentation or anywhere really.