[R-sig-finance] Using data from yahooImport (fBasics)

Gabor Grothendieck ggrothendieck at gmail.com
Fri Apr 7 14:47:35 CEST 2006


On 4/7/06, Dirk Eddelbuettel <edd at debian.org> wrote:
>
> On 7 April 2006 at 11:58, Diethelm Wuertz wrote:
> | Why you should definitely use Rmetrics to solve Owe Jessens problem:
> [...]
> | When you have downloaded the data,
> | you can do it with default settings in 6 lines !!!!
> |
> | Note you have several alternatives to align the data, and to
> | compute the returns. Check the arguments of the functions
> | alignDailySeries() and returnSeries().
>
> Ajay has point as zoo can really do this compactly:
>
>
> stopifnot(require(tseries), quiet=TRUE)         # also loads zoo these days
> simpleBeta <- function(ysymb="F", xsymb="^GSPC", startdate="2005-01-01") {
>  Y <- get.hist.quote(instrument=ysymb, start=startdate, quote="Close")
>  X <- get.hist.quote(instrument=xsymb, start=startdate, quote="Close")
>  rets <- diff(log(merge(Y,X,all=FALSE)))
>  fit <- lm(Close.Y ~ Close.X, data=rets)
>  return(coef(fit)[2])
> }
>
> and is there a way to not get the
> verbose output from downloading ?

The tseries function, get.hist.quote, uses download.file and that's where
its coming from.  If you want you can redefine download.file with quiet = TRUE.
The following creates a wrapper around get.hist.quote that first
defines a download.file wrapper with quiet = TRUE and then
places a copy of get.hist.quote in a proto object whose parent is
the environment within the redefined get.hist.quote so that the
redefined download.file is found.

library(tseries)
library(proto)

get.hist.quote <- function(...) {
	download.file <- function(url, destfile, method, quiet = TRUE,
	mode = "w", cacheOK = TRUE)
	   utils::download.file(url, destfile = destfile, method = method,
		quiet = quiet, mode = mode, cacheOK = cacheOK)
	with(proto(get.hist.quote = tseries::get.hist.quote),
		get.hist.quote(...))
}

ibm <- get.hist.quote("ibm")

The above does not display messages on the R console
although it still does have a popup that briefly appears.

I also tried using capture.output but this seems not to have
any effect on download.file.



More information about the R-sig-finance mailing list