On Tue, Jul 13, 2010 at 9:54 AM, Aaditya Nanduri
<aaditya.nanduri at gmail.com> wrote:> Guys, I wrote to the finance mailing list earlier with my questions but was
> directed here.
>
> Sorry for the repeat.
>
> ---------------
> library(quantmod)
> ....
> now <- Sys.time()
>
> midnight <- strptime() ? ? ? ?# <---- I want to make this a static
variable
> that will be equal to 12:00:00 am but I dont know what to put here. I keep
> getting NA for everything I do
The key to what I did was format(). I am turning the output of
Sys.time() to something that can be compared to the character vector
'midnight'. Also, I would use 24 hour time.
#assign midnight and now
midnight <- "00:00:00"
now <- format(Sys.time(), format = "%H:%M:%S")
#Look at the structure for midnight and now
str(midnight)
str(now)
#print to screen
midnight
now
>
> if(now == midnight) {
This test seems prone to failure. There is a one second period when
'now' must be assigned or it will fail.
> getFX("EUR/USD", from = Sys.Date() -1, to = Sys.Date() - 1)
> write.table(EURUSD, "~Documents/stat arb/project/eurusd.csv",
append = TRUE,
> row.names = FALSE, col.names = FALSE)
> ? ? ? ?....
> }
>
> ....
> ---------------
>
> Also, append is ignored when I use "write.csv". I had to resort
to using
> "write.table". Is this always the case?
write.csv() is a convenience wrapper for write.table(). It is also
clearly stated in the documentation for ?write.csv
"These [write.csv, write.csv2] wrappers are deliberately inflexible:
they are designed to ensure that the correct conventions are used to
write a valid file. Attempts to change 'append', 'col.names',
'sep',
'dec' or 'qmethod' are ignored, with a warning."
So yes, it is always the case. If you want to use write.table() to
make a comma separated file, you might consider adding the argument
sep = "," to your write.table() call.
>
> As for the historical interest rates, thank you all very much for providing
> me with the information (Finance mailing list).
> I used the fImport package and called the method "fredSeries" to
download
> "DPRIME" data for the same time frame as currency data I have
(Thank you,
> Mr. Gallon).
>
> But that is only data for US. What about other countries?
>
> I was talking to a professor and he said that there was a way to read data
> from a website into R if you know the url. Would this help in getting the
> interest rates of other countries? (I believe the function is aptly named
> "url"). Could someone provide an example, please?
I imagine it would help if websites provide different countries
interest rates in a convenient file. In fact, in general you would
not even have to use url(). Here is an example. On my website I have
a tab delimited data file. I can access it from R by:
read.table(
file = "http://www.joshuawiley.com/psyc211/Psyc211-hw1-part1.txt",
header = TRUE, sep = "\t")
It is also possible to enter user names and passwords into the URL.
This general pattern also works for ftp sites. For secure http
(https) I only know how to access them through R in Windows.
Cheers,
Josh
>
> All help is very much appreciated.
>
> Sincerely,
> Aaditya Nanduri
>
> ? ? ? ?[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/