1

How do I specify a start date and end date? For example, I want to extract daily close price for AAPL from 01-01-2020 to 30-06-2021?

enter code here
from alpha.vantage.timeseries import TimeSeries
import pandas as pd

api_key = ''
ts = TimeSeries(key = api_key, output_format = 'pandas')
data - ts.get_daily('AAPL', outputsize = 'full')
print(data)
Chris
  • 11
  • 1

1 Answers1

1

Based on their documentation, it doesn't seem to have an option to filter by date directly in the API call.

Once you retrieve the data you can filter it within the dataframe.

from alpha_vantage.timeseries import TimeSeries
import pandas as pd

api_key = ''
ts = TimeSeries(key = api_key, output_format = 'pandas')
data = ts.get_daily('AAPL', outputsize = 'full')
data[0][(data[0].index >= '2020-01-01') & (data[0].index <= '2021-06-30')]

output:

enter image description here


You can also use .loc when filtering the data since date is the index, but this is deprecated and it will throw an error in a future version of pandas.

data[0].loc['2020-01-01':'2021-06-30']
drake10k
  • 415
  • 1
  • 5
  • 21