How do I convert a daily time-series to a monthly download in Python?
Note that each data feed on Nasdaq Data Link is delivered through one of the following Nasdaq Data Link APIs:
- Streaming API for real-time data
- REST API for real-time or delayed data
- REST API for time-series
- REST API for tables
You can learn more about these APIs and data formats here.
The Nasdaq Data Link Python library may only be used with data delivered through the REST API for time-series or the REST API for tables. Please do not confuse the Nasdaq Data Link Python library with the Python SDK for the Streaming API.
If you are using daily time-series data and want to convert it to monthly in the Nasdaq Data Link Python package, see below:
To change the sample frequency of a daily time-series to monthly, please use the collapse= parameter, like so:
data = nasdaqdatalink.get("XNAS/ACIW", collapse="monthly")
Collapse can be "daily","weekly", "monthly", "quarterly" or "annual".
Note that the conversion process is very simple:
Nasdaq Data Link simply takes the last observation in the day/month/week/quarter/year and uses that as the daily/monthly/weekly/quarterly/annual datum.
This simple conversion process does not work well for time-series that contain percentage changes, period averages/totals (e.g. trading volume) or period extremes (e.g. high/low or OHLC for security prices). For such time-series, we recommend downloading the raw data and carrying out the required daily to monthly transformation using your own analytics tool.
Note also that you can only convert a time-series to a less granular frequency (e.g. daily to monthly) and never the other way around to a more granular frequency (e.g. annual to daily).
There is no collapse parameter for data in tables format. For tables, we recommend downloading the raw data and carrying out the required daily to monthly transformation using your own analytics tool.