'Python for GOOGLEFINANCE(): Is there any way to determine the first date since when stock data is available for a ticker?
Using the following formula in my python code, I have been able to get stock data for a ticker for a given date range. GOOGLEFINANCE("GOOG", "ALL", "1/1/2019", "5/1/2022" ,"DAILY")
Is there some way to know which was the first date since when the stock data is available?
I have a list of stock tickers which I query from python using code below. But, sometimes the ticker is too new and was not existent a few years back. This causes my code to crash. If I know the 'first data' available then could adjust my date range dynamically. Any ideas?
Ticker_List= ["AAPL", "GOOG", "AMZN"] <--- 100 more tickers
for Ticker in Ticker_List:
values = [['=GOOGLEFINANCE("' + str(Ticker) + '", "ALL", "1/1/2014", "2/6/2018" ,"DAILY")']]
cell_range_insert = 'B7'
body = {'values': values}
#Send formula to Google Sheet
service.spreadsheets().values().update(
spreadsheetId=spreadsheet_id,
valueInputOption='USER_ENTERED',
range=cell_range_insert,
body=body
).execute()
# Readback stock data from Google Sheets:
response = service.spreadsheets().values().get(
spreadsheetId=spreadsheet_id,
majorDimension='ROWS',
range='Sheet1'
).execute()
# Readback data from Google Sheets and assign it to dataframe df:
columns = response['values'][1]
data = response['values'][2:]
df = pd.DataFrame(data, columns=columns)
pythongoogle-apigoogle-financegoogle-finance-apisecurityauthenticationgoogle-authenticatormobile-security
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
