TimeSeriesImport {fBasics} | R Documentation |
A collection and description of functions to import
financial and economic market from the Internet.
Download functions are available for economic and
financial market data form Economagic's, from
Yahoo's, and from the Federal Reserve's Internet
sites.
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, |
forecastsImport | monthly data from the Financial Forecast Center. |
economagicImport(query, file = "tempfile", source = "http://www.economagic.com/em-cgi/data.exe/", frequency = c("quarterly", "monthly", "daily"), save = FALSE, colname = "VALUE", try = TRUE) yahooImport(query, file = "tempfile", source = "http://chart.yahoo.com/table.csv?", save = FALSE, sep = ";", swap = 20, try = TRUE) keystatsImport(query, file = "tempfile", source = "http://finance.yahoo.com/q/ks?s=", save = FALSE, try = TRUE) fredImport(query, file = "tempfile", source = "http://research.stlouisfed.org/fred2/series/", frequency = "daily", save = FALSE, sep = ";", try = TRUE) forecastsImport(query, file = "tempfile", source = "http://www.forecasts.org/data/data/", save = FALSE, try = TRUE) show.fWEBDATA(object) ## S3 method for class 'keystats': print(x, ...)
colname |
[economagicImport] - 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. |
object |
an S4 object of class "fWEBDATA" .
|
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. |
x |
[print.keystats] - an object of class keystats as returned by the function
keystatsImport .
|
... |
optional arguments passed to the print.keystats function.
|
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".
The functions economagicImport
, fredImport
, and
yahooImport
return 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 keystatsImport
returns an S3 object of class
keystsats
with two entries: $query
holds the query
name, and keystats
holds the dataframe with the statistical
values.
Internet Download:
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.
Diethelm Wuertz for the Rmetrics R-port.
## Not run: ## SOURCE("fBasics.12A-TimeSeriesData") ## economagicImport - xmpBasics("\nStart: Daily Foreign Exchange Rates > ") USDEUR = economagicImport(query = "fedny/day-fxus2eu", frequency = "daily", colname = "USDEUR") # Print Data Slot if Internet Download was Successful: if (!is.null(USDEUR)) print(USDEUR@data[1:20, ]) ## economagicImport - xmpBasics("\nNext: USFEDFUNDS Monthly US FedFunds Rates > ") USFEDFUNDS = economagicImport(query = "fedstl/fedfunds+2", frequency = "monthly", colname = "USFEDFUNDS") if (!is.null(USFEDFUNDS)) print(USFEDFUNDS@data[1:20, ]) ## economagicImport - xmpBasics("\nNext: USDGNP Quarterly GNP Data Records > ") USGNP = economagicImport(query = "fedstl/gnp", frequency = "quarterly", colname = "USGNP") if(!is.null(USGNP)) print(USGNP@data[1:20, ]) ## yahooImport - xmpBasics("\nNext: IBM Shares from Yahoo > ") # [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, ]) ## keystatsImport - xmpBasics("\nNext: Key Statistics IBM Shares from Yahoo > ") keystatsImport("IBM") ## fredImport - xmpBasics("\nNext: DPRIME Daily Bank Prime Load Rate Records > ") DPRIME = fredImport("DPRIME") if (!is.null(DPRIME)) print(DPRIME@data[1:20, ]) ## End(Not run)