This is Nasdaq Data Link’s R package. The NasdaqDataLink R package uses the Nasdaq Data Link API. The official Nasdaq Data Link R package manual can be found here.
License provided by MIT.
For more information please contact connect@data.nasdaq.com
To install the devtools package:
install.packages("devtools")
library(devtools)
install_github("nasdaq/data-link-r")
To install the most recent package from CRAN type:
install.packages("NasdaqDataLink")
library(NasdaqDataLink)
Note that the version on CRAN might not reflect the most recent changes made to this package.
To make full use of the package we recommend you set your api key. To do this create or sign into your account and go to your account api key page. Then input your API key (with quotes):
NasdaqDataLink.api_key("tEsTkEy123456789")
The NasdaqDataLink package functions use the NasdaqDataLink API. Optional Nasdaq Data Link API query parameters can be passed into each function. For more information on supported query parameters, please see the Nasdaq Data Link API documentation page. Once you find the data you would like to load into R on Nasdaq Data Link, copy the Nasdaq Data Link code from the description box and paste it into the function.
<- NasdaqDataLink("NSE/OIL") data
To create a graph of Google’s performance month-over-month:
plot(stl(NasdaqDataLink("WIKI/GOOG",type="ts",collapse="monthly")[,11],s.window="per"))
Note: collapse
is a Nasdaq Data Link API query
parameter. Click here for a full
list of query parameter options.
The supported return types for the NasdaqDataLink(code)
function are: * raw (which returns a data.frame) * ts
* zoo * xts * timeSeries
To request a specific type, assign the type
argument the
return type:
<- NasdaqDataLink('NSE/OIL', type = "xts") data
zoo, xts, and ts have their own time series date formats. For example:
<- NasdaqDataLink('NSE/OIL', collapse = "quarterly", type = "zoo", limit = 3) data
data
will have indexes 2015 Q1
,
2015 Q2
, and 2015 Q3
:
Turnover (Lacs)
Open High Low Last Close Total Trade Quantity 2015 Q1 459.8 462.8 452.45 454.45 454.95 277225 1265.84
2015 Q2 448.0 451.7 445.10 447.80 446.80 352514 1576.93
2015 Q3 456.0 465.0 454.15 456.80 456.75 174154 797.79
If you want the time series index to be displayed as dates, you will
need to set force_irregular = TRUE
:
<- NasdaqDataLink('NSE/OIL', collapse = "quarterly", type = "zoo", limit = 3, force_irregular = TRUE) data
data
will now have indexes 2015-03-31
,
2015-06-30
, and 2015-09-30
:
Turnover (Lacs)
Open High Low Last Close Total Trade Quantity 2015-03-31 459.8 462.8 452.45 454.45 454.95 277225 1265.84
2015-06-30 448.0 451.7 445.10 447.80 446.80 352514 1576.93
2015-09-30 456.0 465.0 454.15 456.80 456.75 174154 797.79
If you want to get multiple codes at once, delimit the codes with ‘,’, and put them into an array. This will return a multiset.
<- NasdaqDataLink(c('GOOG/NASDAQ_AAPL', 'GOOG/NASDAQ_MSFT')) merged_data
You can also specify specific columns to retrieve. For example, if
you only want column 1 from GOOG/NASDAQ_AAPL
and column 2
from GOOG/NASDAQ_MSFT
:
<- NasdaqDataLink(c('GOOG/NASDAQ_AAPL.1', 'GOOG/NASDAQ_MSFT.2')) merged_data
An entire database’s data can be downloaded. For example, to download
the database ZEA
:
NasdaqDataLink.database.bulk_download_to_file("ZEA", "./ZEA.zip")
Note you must set your api key to download premium databases to which you are subscribed.
For a full list of optional query parameters for downloading an entire database, click here.
To retrieve Datatable data, provide a Datatable code to the NasdaqDataLink datatables function:
= NasdaqDataLink.datatable('ZACKS/FC') data
The output format is data.frame
. Given the volume of
data stored in datatables, this call will retrieve the first page of the
ZACKS/FC datatable. You may turn on pagination to return more data by
using:
= NasdaqDataLink.datatable('ZACKS/FC', paginate=TRUE) data
This will retrieve multiple pages of data and merge them together as if they were one large page. In some cases, however, you will still exceed the request limit. In this case we recommend you filter your data using the available query parameters, as in the following example:
NasdaqDataLink.datatable('ZACKS/FC', ticker=c('AAPL', 'MSFT'), per_end_date.gt='2015-01-01', qopts.columns=c('ticker', 'per_end_date', 'tot_revnu'))
In this query we are asking for more pages of data, ticker values of either AAPL or MSFT and a per_end_date that is greater than or equal to 2015-01-01. We are also filtering the returned columns on ticker, per_end_date and tot_revnu rather than all available columns.
Searching Nasdaq Data Link from within the R console is now supported. The search function is:
NasdaqDataLink.search(query = "Search Term", page = n, database_code = "Specific database to search", silent = TRUE|FALSE)
Which outputs to console a list containing the following information for every item returned by the search:
A search for Oil, searching only the National Stock Exchange of India (NSE).
NasdaqDataLink.search("Oil", database_code = "NSE", per_page = 3)
prints:
Oil India Limited: NSE/OIL
Code: Historical prices for Oil India Limited<br><br>National Stock Exchange of India<br><br>Ticker: OIL<br><br>ISIN: INE274J01014
Desc: daily
Freq: Date | Open | High | Low | Last | Close | Total Trade Quantity | Turnover (Lacs)
Cols
Oil Country Tubular Limited: NSE/OILCOUNTUB
Code: Historical prices for Oil Country Tubular Limited<br><br>National Stock Exchange of India<br><br>Ticker: OILCOUNTUB<br><br>ISIN: INE591A01010
Desc: daily
Freq: Date | Open | High | Low | Last | Close | Total Trade Quantity | Turnover (Lacs)
Cols
Gulf Oil Corporation Limited: NSE/GULFOILCOR
Code: Historical prices for Gulf Oil Corporation Limited (GULFOILCOR), (ISIN: INE077F01027), National Stock Exchange of India.
Desc: daily
Freq: Date | Open | High | Low | Last | Close | Total Trade Quantity | Turnover (Lacs) Cols
PointInTime works similarly to datatables but filtering the data based on dates. For example, a simple way to retrieve datatable information for a specific date would be:
NasdaqDataLink.pit.asofdate('DATABASE/CODE', '2020-01-01')
Dates passed to NasdaqDataLink.pit
calls must be a valid
ISO 8601
datetime. For example, the follow values are valid
dates:
2021-03-02
2021-03-02T13:45:00
2021-03-02T12:55:00-05:00
While the following are invalid:
2021-03-02 13:45:00
(missing T
between
date and time)March 2nd, 2021
(not ISO 8601
compliant)Interval | Explanation | Required params | Example |
---|---|---|---|
asofdate | Returns data as of a specific date | date | NasdaqDataLink.pit.asofdate('DATABASE/CODE', 'yyyy-mm-dd', ...) |
fromto | Returns data from start up to but excluding
end ; [start, end) |
start_date, end_date | NasdaqDataLink.pit.fromto('DATABASE/CODE', '2020-01-01', '2020-02-01', ...) |
between | Returns data inclusively between dates; [start, end] | start_end, end_date | NasdaqDataLink.pit.between('DATABASE/CODE', '2019-01-01', '2020-01-31', ...) |
Filter Point in Time records for specific columns:
NasdaqDataLink.pit.asofdate('DATABASE/CODE', '2020-01-01', qopts.columns=c('x', 'y', 'z'))
NasdaqDataLink.pit.fromto('DATABASE/CODE', '2020-01-01', '2020-02-01', qopts.columns=c('x', 'y', 'z'))
NasdaqDataLink.pit.between('DATABASE/CODE', '2020-01-01', '2020-01-31', qopts.columns=c('x', 'y', 'z'))
More help can be found at Nasdaq Data Link in our R and API pages.