Yahoo {fImport} | R Documentation |
A collection and description of functions to import
financial and economic market data from Yahoo's
web site.
The functions are:
yahooImport | daily stock market data from Yahoo's Web site, |
yahooSeries | easy to use download from Yahoo, |
keystatsImport | key statistics from Yahoo's Web site. |
yahooImport(query, file = "tempfile", source = "http://chart.yahoo.com/table.csv?", save = FALSE, sep = ";", swap = 20, try = TRUE) yahooSeries(symbols = c("^DJI", "IBM"), from = NULL, to = NULL, nDaysBack = 365, quote = c("Open", "High", "Low", "Close", "Volume"), aggregation = c("d", "w", "m"), returnClass = c("timeSeries", "ts", "matrix", "data.frame"), getReturns = FALSE, ...) keystatsImport(query, file = "tempfile", source = "http://finance.yahoo.com/q/ks?s=", save = FALSE, try = TRUE)
aggregation |
a character string denoting the aggregation level of the
downloaded data records, d for daily, w for
weekly and m for monthly data records.
|
file |
a character string with filename, usually having extension ".csv", where to save the downloaded data. |
from, to |
an ISO-8601 formatted character string of the starting (end) date, e.g. "2005-01-01". |
getReturns |
a logical flag. Should return values be computed using the
function returnSeries ?
|
nDaysBack |
an integer giving the length of the download period in number
of days starting n days back from today. Only in use if
from and to are not specified.
|
query |
a character string, denoting the location of the data at the web site. |
save |
a logical value, if set to TRUE the downloaded data file will
be stored under the path and file name specified by the
string file . By default FALSE.
|
quote |
[yahooSeries] - a character value or vector of strings giving the column name(s) of those instruments to be extracted from the download. |
returnClass |
a character string naming the class of the object to be
returned. By default the function returns
a "timeSeries" object, alternatives are: "ts" ,
"matrix" , or "data.frame" .
|
sep |
a character value, defining the field separator for the destination file which saves the downloaded data records. By default a semicolon. |
source |
a character string with the download URL. |
symbols |
a character string value or vector, the Yahoo symbol name(s). |
swap |
an integer value which determines when we swap from the 19th to 20th century, by default 20, i.e. we swap 1920. This is necessary since Yahoo does not list the century in its dates, e.g. "15-Aug-02". |
try |
a logical value, if set to TRUE the Internet access will be checked. |
... |
optional arguments to be passed. |
Import data from chart.yahoo.com:
The query string is given as
s=SYMBOL&a=DD&b=MM&c=CCYY&g=d&q=q&z=SYMBOL&x=.csv
where SYMBOL
has to replaced by the symbol name of the
instrument, and DD
, MM
, and CCYY
by the
day, month-1 and century/year when the time series should start.
Here are some examples of symbols:
[query] | Description: |
^DJI | Dow Jones 30 Industrial Averages |
^NYA | New York Stock Exchange Composite |
^NDX | Nasdaq 100 Index |
^IXIC | Nasdaq Composite Index |
^TYX | US 30Y Treasury Bond Index |
IBM | BM DJIA Stock |
KO | Coca-Cola DJIA Stock |
The meaning of the tokens in the query string are the following:
Token | Description |
s | Selected Ticker-Symbol |
a | First Quote starts with Month (mm) |
b | First Quote starts with Day (dd) |
c | First Quote starts with Year (ccyy) |
d | Last Quote ends with Month (mm) |
e | Last Quote ends with Day (dd) |
f | Last Quote ends with Year (ccyy) |
z | Selected Ticker-Symbol |
The function yahooImport
returns an S4 object of class
fWEBDATA
with the following slots:
@call |
the function call. |
@data |
the data as downloaded formatted as a data.frame. |
@param |
a character vector whose elements contain the values of selected parameters of the argument list. |
@title |
a character string with the name of the download. This can be overwritten specifying a user defined input argument. |
@description |
a character string with an optional user defined description. By default just the current date when the test was applied will be returned. |
The function yahooSeries
returns an S4 object of
class timeSeries
or alternatively an object specified by
the function argument returnClass
.
The function keystatsImport
returns a data frame with
key statistics downloaded from yahoo's web site.
Internet Download Functions:
IMPORTANT NOTE: If the service provider changes the data file format
it may become necessary to modify and update the functions.
The R package tseries
from Adrian Trapletti offers an
alternative function to download stock market data and indexes
from Yahoo's Internet site.
Diethelm Wuertz for the Rmetrics R-port.
## Not run: ## yahooImport - # [test 19/20 century change 01-12-1999 -- 31-01-2000] query = "s=IBM&a=11&b=1&c=1999&d=0&q=31&f=2000&z=IBM&x=.csv" IBM = yahooImport(query) if (!is.null(IBM)) print(IBM@data[1:20, ]) ## End(Not run)