Learn R Programming

quantmod (version 0.2-5)

getSymbols.MySQL: Retrieve Data from MySQL Database

Description

Fetch data from MySQL database. As with other methods extending the getSymbols function, this should NOT be called directly. Its documentation is meant to highlight the formal arguments, as well as provide a reference for further user contributed data tools.

Usage

getSymbols.MySQL(Symbols,
                 env, 
                 return.class = c("quantmod.OHLC", "zoo"), 
                 db.fields = c("date", "o", "h", "l", "c", "v", "a"), 
                 field.names = NULL,
                 user = NULL, 
                 password = NULL, 
                 dbname = NULL, 
                 ...)

Arguments

Symbols
a character vector specifying the names of each symbol to be loaded
env
where to create objects. (.GlobalEnv)
return.class
desired class of returned object. Can be quantmod.OHLC (default for yahoo OHLC data), zoo, data.frame, ts, or its. (zoo)
db.fields
character vector indicating names of fields to retrieve
field.names
names to assign to returned columns
user
username to access database
password
password to access database
dbname
database name
...
currently not used

Value

  • A call to getSymbols.MySQL will load into the specified environment one object for each Symbol specified, with class defined by return.class.

Details

Meant to be called internally by getSymbols (see also)

One of a few currently defined methods for loading data for use with quantmod. Its use requires the packages DBI and RMySQL, along with a running MySQL database with tables corresponding to the Symbol name.

The purpose of this abstraction is to make transparent the source of the data, allowing instead the user to concentrate on the data itself.

References

    MySQL AB http://www.mysql.comDavid A. James and Saikat DebRoy (2006). R Interface to the MySQL databse. www.omegahat.orgR-SIG-DB. DBI: R Database Interface

See Also

getSymbols, setSymbolLookup

Examples

Run this code
# All 3 getSymbols calls return the same
# MSFT to the global environment
# The last example is what NOT to do!

setDefaults(getSymbols.MySQL,user='jdoe',password='secret',
            dbname='tradedata')

## Method #1
getSymbols('MSFT',src='MySQL')


## Method #2
setDefaults(getSymbols,src='MySQL')
  # OR
setSymbolLookup(MSFT='MySQL')

getSymbols('MSFT')

#########################################
##  NOT RECOMMENDED!!!
#########################################
## Method #3
getSymbols.MySQL('MSFT',env=globalenv())

Run the code above in your browser using DataLab