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.
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. >
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 neededi 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.