[R] currency conversion function?

Henrique Dallazuanna wwwhsd at gmail.com
Wed Oct 14 14:05:11 CEST 2009


You can try something about like this:

foo <- function(from, to, date){
	url <- "http://www.oanda.com/convert/classic?script=..%2Fconvert%2Fclassic&language=en&value=1"
      params <-
sprintf("%s&date=%s&exch=%s&exch2=&margin_fixed=0&expr=%s&expr2=&SUBMIT=Convert+Now&lang=en&date_fmt=us",
url, format(as.Date(date), "%m/%d/%y"), from, to)
	Lines <- readLines(params)
	value <- gsub(".*([0-9]\\.+[0-9]+).*", "\\1", grep("nl", grep(from,
grep(to, Lines, value = TRUE), value = TRUE), value = TRUE))
	as.numeric(value)
}

foo('BRL', 'USD', '2009-10-14')


On Wed, Oct 14, 2009 at 6:40 AM, Liviu Andronic <landronimirc at gmail.com> wrote:
> Dear all
> Is there any R function that would perform currency conversion using
> up-to-date exchange rates? I would be looking for a function that
> allows to download recent exchange rates (say, from Yahoo!) and then
> use these in converting currencies (say, USD to EUR).
>
> I am not sure whether r-sig-finance would be more appropriate, but the
> (off-)topic feels general enough to me. Thank you
> Liviu
>
>
>
> --
> Do you know how to read?
> http://www.alienetworks.com/srtest.cfm
> Do you know how to write?
> http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O




More information about the R-help mailing list