initialize(
dsws.serverURL = "",
getTokenFunction = NULL,
token = NULL,
username = "",
password = "",
connect = TRUE
)
initialises the class.
Unless noConnect is TRUE also connects to the
Datastream dsws server.
Authentication can be set in three ways:
1) If getTokenFunction is not null then that function is called. It is expected to
return a list with items 'TokenValue' and 'TokenExpiry'.
2) An access token can also be passed into the class on initialisation, so that it can be shared between sessions.
'token' is expected to be a list with items 'TokenValue' and 'TokenExpiry'.
3) A username and password that are used to fetch a token from the DSWS server. If the username and password are not
provided, then they are sourced from system enviroment variables (ie Sys.getenv)
'DatastreamUsername' and 'DatastreamPassword'
or alternatively (not preferred) then from
options()$Datastream.Username
and
options()$Datastream.Password
This allows the password to be stored in .Renviron or .RProfile rather
than in the source code.
There different accounts have different limits according to their licence. Most users are limited to 50 items while
enterprise users have a limit of 2000L. The chunk limit
can be controlled by setting the chunkLimit parameter of the dsws object. If options()$Datastream.ChunkLimit
is
set then the value is taken from there.
listRequest(instrument, datatype = "", expression = "", requestDate)
Make a listRequest from Datastream DSWS.
This is the equivalent to
the Excel static request for a list.
Parameters are:
- instrument
should contain a list mnemonic, such as 'LFTSE100'
Can be a user created list or index. The UCL can contain
expressions
datatype
array of datatypes eg NAME, MNEM, P, PE etc
expression
if datatype is null or '' then an expression
eg PCH#(XXXX,3M)
requestDate
either a Date or a string with a datastream
relative date eg '-3M'
Returns a data.frame with the requested data.
Examples:
mydsws$listRequest(instrument = "LFTSE100",
datatype = c("NAME","P"),
requestDate = "-0D")
mydsws$listRequest(instrument = "LFTSE100",
expression = "PCH#(XXXX,3M)", requestDate = Sys.Date())
snapshotRequest(instrument, datatype = "", expression = "", requestDate)
Make a snapshotRequest from Datastream DSWS.
This is the equivalent
to the Excel static request for an array of instruments.
Parameters are:
- instrument
should one or more instruments eg "MKS" or
c("MKS","@AAPL"). The array can contain
Economics codes and Expressions.
datatype
array of datatypes eg NAME, MNEM, P, PE etc
expression
if datatype is null or '' then an expression
eg PCH#(XXXX,3M)
requestDate
either a Date or a string with a datastream relative
date eg '-3M'
Returns a data.frame with the requested data.
Examples:
mydsws$snapshotRequest(instrument = c("MKS","@AAPL"), datatype = c("NAME","P"), requestDate = "-0D")
mydsws$snapshotRequest(instrument = c("MKS","@AAPL"), expression = "PCH#(XXXX,3M)", requestDate = "-0D")
timeSeriesListRequest(
instrument,
datatype = "",
expression = "",
startDate,
endDate,
frequency = "D",
format = "ByInstrument"
)
Make a timeSeriesListRequest from Datastream DSWS.
This is the
equivalent to the Excel timeseries request for an array of instruments.
Should request either a datatype or an expression not both. If a
datatype is provided then anything in Expression will be ignored.
Parameters are:
- instrument
should contain a list mnemonic, such as "LFTSE100"
.
Can be a user created list or index. The UCL can contain expressions.
datatype
array of datatypes eg P, PE etc
expression
if datatype is null or '' then an expression
eg PCH#(XXXX,3M)
startDate
either a Date or a string with a datastream relative date
eg '-3M'
endDate
either a Date or a string with a datastream relative date
eg '-0D'
frequency
one of the standard Datastream frequencies - D, W, M, Q, or Y
format
can be either "ByInstrument" or "ByDatatype".
Returns either a single xts or a list of xts a data.frame with
the requested data. If "ByInstrument" then the data is returned as
one or more (ie a list) wide xts with one column per instrument.
If "ByDatatype" then the data is returned as one or more (ie a list)
of wide xts with one column per Datatype. This format is more compatible
with the quantmod package.
Examples:
mydsws$timeSeriesListRequest(instrument = "LFTSE100", datatype = "P", startDate = "-30D",
endDate = "-0D", frequency = "D")
mydsws$timeSeriesListRequest(instrument = "LFTSE100",
expression = "PCH#(XXXX,3M)",
startDate = "-30D",
endDate = "-0D",
frequency = "D")
mydsws$timeSeriesListRequest(instrument = "LFTSE100", datatype = ("P","UP"), startDate = "-30D",
endDate = "-0D",
frequency = "D", format = "ByDatatype")
timeSeriesRequest(
instrument,
datatype = "",
expression = "",
startDate,
endDate,
frequency = "D",
format = "ByInstrument"
)
Return a timeSeriesRequest from Datastream dsws.
Should request either
a datatype or an expression
not both. If a datatype is provided then anythink in Expression
will be ignored
Make a timeSeriesRequest from Datastream DSWS. This is the equivalent
to the Excel timeseries request for an array of instruments.
Parameters are:
- instrument
should one or more instruments eg "MKS" or
c("MKS","@AAPL"). The array can contain Economics codes and
Expressions.
datatype
array of datatypes eg P, PE etc
expression
if datatype is null or '' then an expression
eg PCH#(XXXX,3M)
startDate
either a Date or a string with a datastream relative
date eg '-3M'
endDate
either a Date or a string with a datastream relative
date eg '-0D'
frequency
one of the standard Datastream
frequencies - D, W, M, Q, or Y
format
can be either "ByInstrument" or "ByDatatype".
Returns either a single xts or a list of xts a data.frame with
the requested data. If "ByInstrument" then
the data is returned as one or more (ie a list) wide xts with one
column per instrument. If "ByDatatype"
then the data is returned as one or more (ie a list) of wide xts with
one column per Datatype. This format
is more compatible with the quantmod package.
Examples:
mydsws$timeSeriesRequest(instrument = c("MKS","@AAPL"), datatype = "P", startDate = "-30D",
endDate = "-0D", frequency = "D")
mydsws$timeSeriesRequest(instrument = c("MKS"),
expression = "PCH#(XXXX,3M)", startDate = "-30D",
endDate = "-0D", frequency = "D")
mydsws$timeSeriesRequest(instrument = c("MKS","@AAPL"), datatype = ("P","UP"), startDate = "-30D",
endDate = "-0D", frequency = "D", format = "ByDatatype")