Learn R Programming

TSmisc (version 2016.8-1)

TSmiscMethods: TSdbi Extensions to Wrap Several Data Sources

Description

Get a time series (matrix) from a variety of source URLs

Usage

histQuote(...) getSymbol(...) xls(...) zip(...)
"TSconnect"(q, dbname, ...) "TSget"( serIDs, con, TSrepresentation = options()$TSrepresentation, tf = NULL, start = tfstart(tf), end = tfend(tf), names=serIDs, quote = "Close", quiet = TRUE, repeat.try=3, ...) "TSdates"( serIDs, con, vintage=NULL, panel=NULL, ... ) "TSdescription"(x, con, ... ) "TSdoc"(x, con, ... ) "TSlabel"(x, con, ... ) "TSsource"(x, con, ... )
"TSconnect"( q, dbname, ...) "TSget"( serIDs, con, TSrepresentation = options()$TSrepresentation, tf = NULL, start = tfstart(tf), end = tfend(tf), names=serIDs, quote = NULL, quiet = TRUE, repeat.try=3, ...) "TSdates"( serIDs, con, vintage=NULL, panel=NULL, ... ) "TSdescription"(x, con, ... ) "TSdoc"(x, con, ... ) "TSlabel"(x, con, ... ) "TSsource"(x, con, ... )
"TSconnect"(q, dbname, map=list(ids, data, dates, names=NULL, description=NULL, sheet=1, tsrepresentation = function(data,dates){ zoo::zoo(data, as.Date(dates))}), ...) "TSget"( serIDs, con, TSrepresentation = options()$TSrepresentation, tf = NULL, start = tfstart(tf), end = tfend(tf), names=serIDs, ...) "TSdates"( serIDs, con, vintage=NULL, panel=NULL, ... ) "TSdescription"(x, con, ... ) "TSdoc"(x, con, ... ) "TSlabel"(x, con, ... ) "TSsource"(x, con, ... )
"TSconnect"(q, dbname, suffix=c("Open","High","Low","Close","Volume","OI"), ...) "TSget"( serIDs, con, TSrepresentation=options()$TSrepresentation, tf=NULL, start=tfstart(tf), end=tfend(tf), names=NULL, quote=con@suffix, ...) "TSdates"( serIDs, con, vintage=NULL, panel=NULL, ... ) "TSdescription"(x, con, ... ) "TSdoc"(x, con, ... ) "TSlabel"(x, con, ... ) "TSsource"(x, con, ... )

Arguments

q
a string indicating a query interface to use, or a database connection object.
dbname
a string indicating a database or omitted if q ia a connection object.
con
a database connection object.
serIDs
identifiers for series on the database.
vintage
character string indicating vintage of the series on the database (not supported by this database).
panel
character string indicating panel of the series on the database (not supported by this database).
x
time series data(TSput), or identifiers for series on the database (TSdoc and TSdescription).
names
optional character vector to use for series names in the R object.
tf
time frame for trimming data, passed to tfwindow.
start
time frame for trimming data, passed to tfwindow.
end
time frame for trimming data, passed to tfwindow.
TSrepresentation
time representation for returned series. (See TSget in package TSdbi.)
quote
reference time (e.g. ''Close'') passed to get.hist.quote. For zip method, a vector of strings, as in suffix, indicating series that should be returned in the result(see Details).
quiet
logical to suppress progress report, passed to get.hist.quote.
repeat.try
integer number of times to attempt retrieval before giving up.
sheet
optional integer to indicate the sheet of the workbook to use default=1).
map
A list with elements indicating the location of data, serIDs, dates, and optional metadata (see Details).
suffix
A vector of strings indicating names of the columns if the zipped file has more than one series (see Details).
...
Arguments passed to other methods, or by histQuote to get.hist.quote.

Value

Details

These functions interface to a stock quote URL using get.hist.quote from the tseries package. Only URLs ''yahoo'' and ''oanda'' are supported. TShistQuote is a wrapper to get.hist.quote. No extra functionality is provided, only an interface that is consistent with TSdbi. The TSdbi function argument dbname is mapped to get.hist.quote argument provider, and serId to instrument. Argument quote (ignored for provider 'oanda') is set to ''Close'' by default, but can be specified. get.hist.quote argument retclass is replaced by TSdbi argument TSrepresentation. (See TSget in TSdbi for more details on how this works.)

TShistQuote does not support writing data to the source URL.

The classes histQuoteDriver and TShistQuoteConnection extend classes DBIDriver and DBIConnection in the DBI package.

See the package vignette for additional examples.

See Also

TSconnect, TSdates, TSget, get.hist.quote tfwindow

Examples

Run this code
 require("tfplot")
    
 ## Not run: 
#     con <- try(TSconnect("histQuote", dbname="yahoo") )
#     x <- TSget("^gspc", con)
#     tfplot(x)
# 
#     con <- TSconnect("getSymbol", dbname="FRED")
#     x <- TSget("CPIAUCNS", con)
#     tfplot(x)
# 
#     # data from http://pitrading.com/
#     # par(ask=TRUE) # to pause between pages
#     con <- TSconnect("zip", dbname="http://pitrading.com/free_eod_data")
#     x <- TSget("EURUSD", con)
#     tfplot(x, graphs.per.page=3)
# 
#     z <- TSget(c("AD", "CD"), con, quote="Close")
#     tfplot(z, start="2007-01-01", Title=
#      "Futures, Australian and Canadian Dollar Continuous Contract at Close",
#       graphs.per.page=3)
#     ## End(Not run)

  ####  Australian Money ####
  #  test file copied Nov. 29, 2010 from 
  #  http://www.rba.gov.au/statistics/tables/xls/d03hist.xls  

    testfile <- system.file("xlsExampleData/d03hist.xls", package = "TSmisc")
 
    con1 <- TSconnect("xls", dbname=testfile,
          map=list(ids  =list(i=11,     j="B:Q"), 
	           data =list(i=12:627, j="B:Q"), 
	           dates=list(i=12:627, j="A"),
                   names=list(i=4:7,    j="B:Q"), 
		   description = NULL,
		   tsrepresentation = function(data,dates){
		       ts(data,start=c(1959,7), frequency=12)}))

    z <- TSget("DMACN", con1)
    tfplot(z)

Run the code above in your browser using DataLab