WebDataImport {fBasics}R Documentation

Import Market Data from the Internet

Description

A collection and description of functions to import financial and economic market from the Internet.

The functions are:

economagicImport Economic series from Economagic's Web site,
yahooImport Daily stock market data from Yahoo's Web site,
keystatsImport Key Statistics from Yahoo's Web site,
fredImport Time series from St. Louis FRED Web site.

Usage

economagicImport(file = "tempfile", 
    source = "http://www.economagic.com/em-cgi/data.exe/", query, 
    frequency = c("quarterly", "monthly", "daily"), save = FALSE, 
    colname = "VALUE", try = TRUE)
    
yahooImport(file = "tempfile", 
    source = "http://chart.yahoo.com/table.csv?", query, save = FALSE,
    sep = ";", swap = 20, try = TRUE)
keystatsImport(file = "tempfile", 
    source = "http://finance.yahoo.com/q/ks?s=", query, save = FALSE, 
    try = TRUE) 
    
fredImport(file = "tempfile", 
    source = "http://research.stlouisfed.org/fred2/series/", 
    query, frequency = "daily", save = FALSE, sep = ";", try = TRUE) 

Arguments

colname a character string which defines the name of the value column. By default "VALUE".
file a character string with filename, usually having extension ".csv", where to save the downloaded data.
frequency a character string, one of "quarterly", "monthly", or "daily", defining the frequency of the data records.
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.
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.
swap [yahooImport] -
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.

Details

Import data from www.economagic.com

Frequently requested data files from Economagic for the US economy include:

[query] Description:
var/leading-ind-long Index of Leading Economic Indicators
beana/t102l01 Real Gross Domestic Product
fedstl/trsp500 SP 500 Total Return
fedstl/gnp Gross National Product in Current Dollars
var/cpiu-long Consumer Price Index - All Urban Consumers
feddal/ru Unemployment Rate
fedstl/indpro Total Industrial Production Index
fedstl/exjpus+2 FX Rate: Japanese Yen to one US Dollar
fedstl/fedfunds+2 Federal Funds Rate
fedstl/mdiscrt+2 Discount Rate
fedbog/tcm30y+2 30-Year Treasury Constant Maturity Rate
fedstl/mprime+2 Bank Prime Loan Rate
fedstl/tb3ms+2 3-Month Treasury Bills - Secondary Market
fedstl/tb6ms+2 6-Month Treasury Bills - Secondary Market
fedbog/cm+2 30 Year Federal Home Loan Mortgages
var/west-texas-crude-long Price of West Texas Intermediate Crude

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

Note, that month tokens range between 0 and 11 for January to December!

Key Statistics data from finance.yahoo.com:

The functions downloads the key statistics for the specified equity query and returns the result as a two column data frame. The key names included are: "Market Cap", "Enterprise Value", "Trailing P/E", "Forward P/E", "PEG Ratio", "Price/Sales", "Price/Book", "Enterprise Value/Revenue", "Enterprise Value/EBITDA", "Annual Dividend", "Dividend Yield", "Beta", "52-Week Change", "52-Week High", and "52-Week Low".

Value

A data frame with the downloaded data records or key statistics.

Note

Note, that 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.

Author(s)

Diethelm Wuertz for the Rmetrics R-port.

Examples

## Not run: 
## economagicImport -
   xmpBasics("\nStart: Daily Foreign Exchange Rates > ")
   USDEUR = economagicImport(query = "fedny/day-fxus2eu", 
     frequency = "daily", colname = "USDEUR", try = TRUE)
   # Print if Internet Download was Successful:
   if(!is.null(USDEUR)) print(USDEUR[1:20, ])

## economagicImport -
   xmpBasics("\nNext: USFEDFUNDS Monthly US FedFunds Rates > ")
   USFEDFUNDS = economagicImport(query = "fedstl/fedfunds+2", 
     frequency = "monthly", colname = "USFEDFUNDS", try = TRUE)
   if(!is.null(USFEDFUNDS)) print(USFEDFUNDS[1:20, ])
   
## economagicImport -
   xmpBasics("\nNext: USDGNP Quarterly GNP Data Records > ")
   USGNP = economagicImport(query = "fedstl/gnp", 
     frequency = "quarterly", colname = "USGNP", try = TRUE)
   if(!is.null(USGNP)) print(USGNP[1:20, ])  
     
## yahooImport -
   xmpBasics("\nNext: IBM Shares from Yahoo > ")
   # [test 19/20 century change 01-12-1999 -- 31-01-2000]
   IBM = yahooImport(
     query = "s=IBM&a=11&b=1&c=1999&d=0&q=31&f=2000&z=IBM&x=.csv", 
     try = TRUE)
   if (!is.null(IBM)) print(IBM[1:20, ])
   
## keystatsImport -
   xmpBasics("\nNext: Key Statistics IBM Shares from Yahoo > ")  
   keystatsImport(query = "IBM"  
   
## fredImport -
   xmpBasics("\nNext: DPRIME Daily Bank Prime Load Rate Records > ")
   DPRIME = fredImport(query = DPRIME)
   if (!is.null(DPRIME)) print(DPRIME[1:20, ])       
## End(Not run)

[Package fBasics version 200.10058 Index]