i am new to the quantmod package . so if the answer is trivial please excuse me. i want to study stock values within a day. i get current stock updates using getQuotes and then want to produce usual quantmod graphs with that values. also the graph should be able of adding technical indicators. please help. in addition it will be helpful if anyone suggests how to run that code continuously to get constantly updated charts. thanks in advance for any suggestion. -- View this message in context: http://r.789695.n4.nabble.com/quantmod-package-tp3921071p3921071.html Sent from the R help mailing list archive at Nabble.com.
quantmod package
7 messages · ATANU, R. Michael Weylandt
Generally getting intraday/real-time data requires some sort of (paid)
source, but if you are willing to just strip free quotes off the
internet non-stop, perhaps something like this:
while(TRUE) {
cat( file = "FileName.txt", c(getQuote(YHOO), recursive = T), "\n",
append = T)
}
# You could get better performance from a textConnection depending on
how often you intend to do this
You'll have to read.table() the .txt file into an xts before being
able to apply most of the quantmod bells and whistles to it.
Look at chartSeries() for the graphical stuff. As far as combining
them, you could put a chartSeries() command in the loop, but that's
going to slow things down since it will require recharting each time.
Michael
On Thu, Oct 20, 2011 at 3:03 AM, ATANU <ata.sonu at gmail.com> wrote:
i am new to the quantmod package . so if the answer is trivial please excuse me. i want to study stock values within a day. i get current stock updates using getQuotes and then want to ?produce usual quantmod graphs with that values. also the graph should be able of adding technical indicators. please help. in addition it will be helpful if anyone suggests how to run that code continuously to get constantly updated charts. thanks in advance for any suggestion. -- View this message in context: http://r.789695.n4.nabble.com/quantmod-package-tp3921071p3921071.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.
thanks for the help. but with that code it is possible to save the current quotes in a text file(only the date-time in the first columnis not preserved). when i used read.table and tried to convert it into an xts object it shows error as it cannot take the indices as time object. same case happens if i only save the quotes in a dataframe using rbind.( i guess in the latter case that happens because the symbol ,say TCS.NS gets attached with the date). please suggest a solution to this problem. -- View this message in context: http://r.789695.n4.nabble.com/quantmod-package-tp3921071p3925863.html Sent from the R help mailing list archive at Nabble.com.
You have to convert the long numbers to time objects; they are kept as
POSIXct values so just apply as.POSIXct() to them. However, you may
just want to store the time data as a string containing the same info:
try this,
library(quantmod)
tck = "YHOO"
filename = paste(tck, ".txt", sep="")
while(TRUE){
temp <- getQuote(tck)
temp <- paste(temp[[1]], temp[[2]], "\n", sep = ",")
cat(file = filename, temp, append = TRUE)
Sys.sleep(1/10)
}
P = read.table(filename, stringsAsFactors = FALSE, sep=",")
P = xts(P[,2], as.POSIXct(P[,1])); names(P) <- tck
Michael
On Fri, Oct 21, 2011 at 11:30 AM, ATANU <ata.sonu at gmail.com> wrote:
thanks for the help. but with that code it is possible to save the current quotes in a text file(only the date-time in the first columnis not preserved). when i used read.table and tried to convert it into an xts object it shows error as it cannot take the indices as time object. same case happens if i only save the quotes in a dataframe using rbind.( i guess in the latter case that happens because the symbol ,say TCS.NS gets attached with the date). please suggest a solution to this problem. -- View this message in context: http://r.789695.n4.nabble.com/quantmod-package-tp3921071p3925863.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.
6 days later
the code you posted works well except that when i am using chartSeries() it does not give any graphical stuff:
chartSeries(P,type="auto")
Error in if (on == "years") { : missing value where TRUE/FALSE needed
i also tried to store the entire getQuote output (OHLC object) by the above manner but it then reads the number in a format (i guess character) unsupported by the chartSeries(). -- View this message in context: http://r.789695.n4.nabble.com/quantmod-package-tp3921071p3947026.html Sent from the R help mailing list archive at Nabble.com.
3 days later
Dear Ata, I just tested it and it worked just fine for me. Perhaps you need to test it during US market hours rather than when they are closed. (I'm not sure what the yahoo finance website does then). If you want to keep the whole getQuote object, you will probably have to do a little work on the output before saving it to the text file since getQuote returns a data frame, which has multiple data types inside of it. My recommendation would be to isolate those columns you want, unlist, convert to double if necessary/possible, and then store that. You'll also need to slightly modify the read-back-in code to take into account whatever you decide to do. If you can show me what you've tried, I can help fix it up. Michael
On Fri, Oct 28, 2011 at 2:21 AM, ATANU <ata.sonu at gmail.com> wrote:
the code you posted works well except that when i am using chartSeries() it does not give any graphical stuff:
chartSeries(P,type="auto")
Error in if (on == "years") { : missing value where TRUE/FALSE needed
i also tried to store the entire getQuote output (OHLC object) by the above manner but it then reads the number in a format (i guess character) unsupported by the chartSeries(). -- View this message in context: http://r.789695.n4.nabble.com/quantmod-package-tp3921071p3947026.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.
Dear Michael , Thanks for your help. I figured out the fault. Actually i was running the code for a very short time(less than one minute) and was then trying to make chart out of that. The code works well if I run it for more than one minute. Thanks again for your help. Atanu -- View this message in context: http://r.789695.n4.nabble.com/quantmod-package-tp3921071p3962665.html Sent from the R help mailing list archive at Nabble.com.