Re: [R-SIG-Finance] Remove first two weeks of data in half hourly resolution
Brian's example is good if you want to remove the first 14 calendar days. If you want to remove the first 14 dates that appear in your data, it's even simpler #create sample data x <- .xts(1:1000, .POSIXct(1:1000*60*30)) # remove 1st 14 days by using a negative with first() first(x, "-14 days") Garrett On Thu, Mar 31, 2016 at 6:24 AM, Brian G. Petersonwrote: > Peter, > > You haven't published a reproducible example, and I'm not going to take > the time to write a complete example from scratch. > > We use xts subsetting for this type of thing, so I suggest using xts for > your time series (this is always good advice for time series in R). > > Here's a partial example to get you started. > > ### > > #load some data from the PerformanceAnalytics package > data(edhec) > > #check the range > range(index(edhec)) > > #add 14 days from the start > first(index(edhec))+14 > > #now assume that you have an object 'z' with intraday data > range(z) > > #check the range of Dates by forcing the index to Date type > range(as.Date(index(z))) > > #add 114 days, as before > first(as.Date(index(z)))+14 > > # now subset by cutting off the first 14 calendar days > # from the start of the series > zs <- z[paste0(first(as.Date(index(z)))+14,'/')] > > #check the range > range(as.Date(index(zs))) > > ## > > Regards, > > Brian > > -- > Brian G. Peterson > http://braverock.com/brian/ > Ph: 773-459-4973 > IM: bgpbraverock > > > On Thu, 2016-03-31 at 11:50 +0100, Peter Neumaier wrote: >> Hi all, >> >> I am doing some analysis on monthly futures contracts from 2011-2016. >> Each monthly contract goes for eight weeks, in half hourly resolution. >> >> I'd like to remove first two weeks of eight weeks history for each monthly >> contract. >> My approach was to work out the start and end date and cut the 1st two weeks >> data off, but problem is that the half hourly resolution is sometimes >> incomplete( >> i.e. a trading day goes from 7:00am - 4:00pm but sometimes starts at >> 7:30am). >> >> Any suggestion on how to resolve this? Below a sample trading day in half >> hourly: >> >> NGFH6.Open NGFH6.High NGFH6.Low NGFH6.Close >> NGFH6.Volume NGFH6.WAP NGFH6.hasGaps NGFH6.Count >> 2016-01-06 07:30:00 0.3395 0.33950.3375 0.3380 >> 45 0.33811 0 5 >> 2016-01-06 08:00:00 0.3400 0.34000.3387 0.3395 >> 140 0.33928 0 12 >> 2016-01-06 08:30:00 0.3395 0.33950.3379 0.3379 >> 70 0.33884 0 5 >> 2016-01-06 09:00:00 0.3379 0.33790.3379 0.3379 >> 0 0.33790 0 0 >> 2016-01-06 09:30:00 0.3379 0.33790.3379 0.3379 >> 0 0.33790 0 0 >> 2016-01-06 10:00:00 0.3375 0.33800.3373 0.3373 >> 230 0.33738 0 14 >> 2016-01-06 10:30:00 0.3376 0.33790.3376 0.3379 >> 20 0.33775 0 2 >> 2016-01-06 11:00:00 0.3370 0.33700.3370 0.3370 >> 105 0.33700 0 5 >> 2016-01-06 11:30:00 0.3366 0.33660.3365 0.3365 >> 65 0.33658 0 4 >> 2016-01-06 12:00:00 0.3370 0.33700.3370 0.3370 >> 10 0.33700 0 1 >> 2016-01-06 12:30:00 0.3372 0.33720.3361 0.3361 >> 125 0.33686 0 9 >> 2016-01-06 13:00:00 0.3360 0.33600.3357 0.3360 >> 225 0.33585 0 17 >> 2016-01-06 13:30:00 0.3357 0.33570.3355 0.3355 >> 50 0.33560 0 5 >> 2016-01-06 14:00:00 0.3350 0.33590.3350 0.3359 >> 25 0.33554 0 2 >> 2016-01-06 14:30:00 0.3359 0.33590.3359 0.3359 >> 0 0.33590 0 0 >> 2016-01-06 15:00:00 0.3352 0.33520.3348 0.3352 >> 150 0.33492 0 15 >> 2016-01-06 15:30:00 0.3352 0.33520.3334 0.3341 >> 280 0.33364 0 24 >> 2016-01-06 16:00:00 0.3341 0.33750.3341 0.3370 >> 145 0.33543 0 17 >> 2016-01-06 16:30:00 0.3380 0.33850.3380 0.3385 >> 25 0.33830 0 3 >> >> Many Thanks >> Peter >> >> [[alternative HTML version deleted]] >> >> ___ >> R-SIG-Finance@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-sig-finance >> -- Subscriber-posting only. If you want to post, subscribe first. >> -- Also note that this is not the r-help list where general R questions >> should go. > > ___ > R-SIG-Finance@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > -- Subscriber-posting only. If you want to post, subscribe first. > -- Also note that this is not the
Re: [R-SIG-Finance] Reading the GSW spot rates from fed 2006 website
It might be easier to work with the .xls file that you can download from a link on this page: http://www.federalreserve.gov/pubs/feds/2006/200628/200628abs.html hope it helps, Garrett On Sun, Oct 11, 2015 at 5:02 PM, Mahmoud Shammaawrote: > Hello, > Does anyone have any tips or suggestions regarding reading the rates that > Gurkaynak, Sack and Wright are updating on this website: > http://www.federalreserve.gov/econresdata/researchdata/feds200628_1.html > While I know how to scrape an html page the issue is that they have the > pages going from oldest to newest so It is not easily apparent where the > latest data is: > As of right now it is on page 29... > http://www.federalreserve.gov/econresdata/researchdata/feds200628_29.html > . > > the problem is that this will change > What is even more frustrating that if you go to > http://www.federalreserve.gov/econresdata/researchdata/feds200628_30.html > data exists but it is not clear in what sequence ... it seems to be draft > data.. > > So I am not sure if anyone on this list has recommendations regarding > unruly webpages .. > > Thanks, > Mido Shammaa > > [[alternative HTML version deleted]] > > ___ > R-SIG-Finance@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > -- Subscriber-posting only. If you want to post, subscribe first. > -- Also note that this is not the r-help list where general R questions > should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Constant maturity Futures
I don't really remember how it works, to be honest. :-P I wish I had time to look into it. 2015-08-19 is 20 days ago, so I guess the 20 day CMF needs 20 days of data as it's currently implemented? Sorry I can't be of more help. Garrett On Tue, Sep 8, 2015 at 9:30 AM, Ilya Kipnis <ilya.kip...@gmail.com> wrote: > Hi Garrett, > > I just tested this code out and...it doesn't compute up to the most current > day. As of now, the term.structure function ends at 2015-08-19. AKA in the > last month. Is there a way to make it go up to the last day for which there > is data available? Thanks. > > -Ilya > > On Thu, Aug 13, 2015 at 5:56 PM, G See <gsee...@gmail.com> wrote: >> >> Hi Samuel, >> >> Here's some code (also attached) that creates constant maturity >> futures for VIX futures. I wrote this code 4 years ago. I'm not >> particularly proud of it. I don't know for sure that it works. It >> might not be elegant. etc. Take it for what it's worth. >> >> You should be able to source this code and get a time series plot of >> several different CMFs of varying maturities. You'll need my qmao >> package which you can install with >> devtools::install_github("gsee/qmao") >> >> >> #' @export >> #' @rdname primary2expiry >> suffix2expiry <- function(suffix, root='VX', ...) { >> if (exists(paste('suffix2expiry',root,sep="."))) { >> do.call(paste('suffix2expiry',root,sep='.'),list(suffix, ...)) >> } else { >> warning(paste(root, 'is not and available suffix2expiry >> method; using "VX" instead')) >> do.call('suffix2expiry.VX',list(suffix, ...)) >> } >> } >> >> #' Get the expiration date of an instrument given it's primary_id >> #' >> #' \code{primary2expiry} is basically a wrapper for >> \code{\link{suffix2expiry}}. It uses >> #' \code{\link[FinancialInstrument]{parse_id}} to split the >> \code{primary_id} into rood_id and suffix_id. >> #' then it calls the appropriate \code{\link{suffix2expiry}} method. >> #' >> #' \code{suffix2expiry} is a generic-like function. There should be a >> method defined >> #' the "root_id". Currently, written methods include "VX", "ES" (and >> aliases "YM", "NQ"). >> #' There are links to methods help pages in the seealso section. >> #' >> #' @param primary_id character string. Primary identifier of the >> instrument >> #' @param root character string. root symbol like "ES" or "VX" (NULL) >> #' @param silent silence warnings? (TRUE) >> #' @param suffix character string that indicates expiration month and >> year (and, for options, right and strike). >> #' See \code{\link[FinancialInstrument]{parse_suffix}} for examples of >> acceptable formats. >> #' @param ... any arguments to be passed to the \code{suffix2expiry} >> method >> #' @return expiration Date >> #' @seealso \code{\link{suffix2expiry.VX}}, \code{\link{suffix2expiry.ES}} >> #' @aliases primary2expiry, suffix2expiry >> #' @author gsee >> #' @examples >> #' primary2expiry("ESU1") >> #' suffix2expiry('V11', root='VX') >> #' @export >> #' @rdname primary2expiry >> primary2expiry <- function(primary_id, root=NULL, silent=TRUE) { >> idlist <- parse_id(primary_id, silent=silent) >> if (is.null(root)) root <- idlist$root >> do.call(paste("suffix2expiry",root,sep='.'), >> list(suffix=idlist$suffix, silent=silent)) >> } >> >> >> #' VIX future contract expiration date >> #' >> #' Calculate the expiration date of a VIX future contract given a >> suffix_id >> #' >> #' Per the contract specs, expiration will occur on \dQuote{the Wednesday >> that >> #' is thirty days prior to the third Friday of the calendar month >> #' immediately following the month in which the contract expires >> ("Final Settlement Date"). >> #' If the third Friday of the month subsequent to expiration of the >> applicable >> #' VIX futures contract is a CBOE holiday, the Final Settlement Date >> for the contract >> #' shall be thirty days prior to the CBOE business day immediately >> preceding that Friday.} >> #' @param suffix suffix_id that should be something like (\sQuote{U1}, >> \sQuote{U11}, or \sQuote{SEP11}) >> #' @param silent silence warnings? (TRUE) >> #' @return an expiration Date >> #' @author gsee >> #' @references \url{http://cfe.cboe.com/products/spec_vix.aspx} >> #' @examples >> #'
Re: [R-SIG-Finance] Constant maturity Futures
Hi Samuel, Here's some code (also attached) that creates constant maturity futures for VIX futures. I wrote this code 4 years ago. I'm not particularly proud of it. I don't know for sure that it works. It might not be elegant. etc. Take it for what it's worth. You should be able to source this code and get a time series plot of several different CMFs of varying maturities. You'll need my qmao package which you can install with devtools::install_github(gsee/qmao) #' @export #' @rdname primary2expiry suffix2expiry - function(suffix, root='VX', ...) { if (exists(paste('suffix2expiry',root,sep=.))) { do.call(paste('suffix2expiry',root,sep='.'),list(suffix, ...)) } else { warning(paste(root, 'is not and available suffix2expiry method; using VX instead')) do.call('suffix2expiry.VX',list(suffix, ...)) } } #' Get the expiration date of an instrument given it's primary_id #' #' \code{primary2expiry} is basically a wrapper for \code{\link{suffix2expiry}}. It uses #' \code{\link[FinancialInstrument]{parse_id}} to split the \code{primary_id} into rood_id and suffix_id. #' then it calls the appropriate \code{\link{suffix2expiry}} method. #' #' \code{suffix2expiry} is a generic-like function. There should be a method defined #' the root_id. Currently, written methods include VX, ES (and aliases YM, NQ). #' There are links to methods help pages in the seealso section. #' #' @param primary_id character string. Primary identifier of the instrument #' @param root character string. root symbol like ES or VX (NULL) #' @param silent silence warnings? (TRUE) #' @param suffix character string that indicates expiration month and year (and, for options, right and strike). #' See \code{\link[FinancialInstrument]{parse_suffix}} for examples of acceptable formats. #' @param ... any arguments to be passed to the \code{suffix2expiry} method #' @return expiration Date #' @seealso \code{\link{suffix2expiry.VX}}, \code{\link{suffix2expiry.ES}} #' @aliases primary2expiry, suffix2expiry #' @author gsee #' @examples #' primary2expiry(ESU1) #' suffix2expiry('V11', root='VX') #' @export #' @rdname primary2expiry primary2expiry - function(primary_id, root=NULL, silent=TRUE) { idlist - parse_id(primary_id, silent=silent) if (is.null(root)) root - idlist$root do.call(paste(suffix2expiry,root,sep='.'), list(suffix=idlist$suffix, silent=silent)) } #' VIX future contract expiration date #' #' Calculate the expiration date of a VIX future contract given a suffix_id #' #' Per the contract specs, expiration will occur on \dQuote{the Wednesday that #' is thirty days prior to the third Friday of the calendar month #' immediately following the month in which the contract expires (Final Settlement Date). #' If the third Friday of the month subsequent to expiration of the applicable #' VIX futures contract is a CBOE holiday, the Final Settlement Date for the contract #' shall be thirty days prior to the CBOE business day immediately preceding that Friday.} #' @param suffix suffix_id that should be something like (\sQuote{U1}, \sQuote{U11}, or \sQuote{SEP11}) #' @param silent silence warnings? (TRUE) #' @return an expiration Date #' @author gsee #' @references \url{http://cfe.cboe.com/products/spec_vix.aspx} #' @examples #' \dontrun{ #' suffix2expiry.VX('U11') #' suffix2expiry.VX(JUN09) #' } #' @export suffix2expiry.VX - suffix2expiry.VIX - function(suffix, silent=TRUE) { #require('timeDate') sl - parse_suffix(suffix,silent=silent) DT - as.Date(paste(15, sl$month, sl$year,sep='-'),format=%d-%b-%Y) Y - format(DT,%Y) M - format((DT + 30),%m) if (as.numeric(M) == 1) Y - paste(as.numeric(Y) + 1) DS - as.Date(paste(Y,M,01,sep='-'))+0:22 DS - DS[months(DS, abbreviate=TRUE) == C2M()[as.numeric(M)]] ds - which(weekdays(DS) == Friday)[3] if (DS[ds] %in% as.Date(holidayNYSE(as.numeric(Y))@Data)) { while (DS[ds] %in% as.Date(holidayNYSE(as.numeric(Y))@Data) || any(c('Saturday', 'Sunday') == weekdays(DS[ds]))) ds - ds-1 } #try(detach(package:timeDate), silent=TRUE); try(detach(package:timeSeries), silent=TRUE) DS[ds] - 30 } .interp.fut.VX - function(x1, x2, n=36, prefer='Close') { xs - c(x1,x2) # names of 2 instruments x1 - get(x1,pos=.GlobalEnv) x2 - get(x2,pos=.GlobalEnv) x1$DTE - primary2expiry(xs[1])-index(x1)#, index(x1)) #dlf(x1) x2$DTE - primary2expiry(xs[2])-index(x2)#, index(x2)) #dlf(x2) df - merge(x1$DTE,x2$DTE,all=FALSE) df - na.omit(df) if (length(df[,1]) length(df[,2])) { Pcmf - xts() if(all(df[,1] df[,2])) { col1 - 1 col2 - 2 } else if (all(df[,2] df[,1])) { col1 - 2 col2 - 1 } else stop(paste(ambiguous nearby contract,xs)) for (ns in n) { idx - index(df[(df[,col1] = ns) (df[,col2] ns)]) if (length(idx) == 0) return(NULL) w - 1/ns P1
Re: [R-SIG-Finance] getquote function
Works for me, but it's not that unusual for different yahoo servers to give different answers (which you don't have much control over). getQuote(SPY, src=yahoo) # Trade Time Last Change % Change Open HighLow Volume #SPY 2015-07-27 12:10:00 206.93 -1.07 -0.51% 206.94 207.55 206.26 54683280 #devtools::install_github(gsee/qmao) suppressPackageStartupMessages(library(qmao)) getQuote(SPY, src=google) # TradeTime Last Change PctChg Exchange GoogleID #SPY 2015-07-27 12:27:00 207.01 -0.99 -0.48 NYSEARCA 700145 getQuote(SPY, src=bats, what=bbo) # TradeTime BidSize BidPrice AskPrice AskSizeLast LastSize row.names #1 12:27:011965 207 207.013135 207.005 18 SPY Garrett On Mon, Jul 27, 2015 at 11:23 AM, Samuel Wilson samuelcoltwil...@gmail.com wrote: Quick question, Anyone else having trouble with getQuote function this morning (quantmod library)? Mine will not pull a current delayed quote, but is pulling last close. Worked on Friday, but today not. Before I spend time troubling shooting, I want to figure out if anyone else is having this problem. [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Monthly Midpoint return
Try this data(sample_matrix) # load sample data first x - as.xts(sample_matrix) do.call(rbind, lapply(split(x, months), function(xx) xx[ceiling(nrow(xx)/2)])) This code splits the object by months, then uses lapply() to loop over each month and apply a function which selects the row that is in the middle of the month. (you could replace ceiling() with floor() or round()). Once you have the subsetted data, you can calculate returns however you normally would (ROC(), Delt(), dailyReturn(), etc.) HTH, Garrett On Wed, Jun 17, 2015 at 9:30 AM, Mark Knecht markkne...@gmail.com wrote: On Wed, Jun 17, 2015 at 7:23 AM, Phil Steel steelstee...@outlook.com wrote: Hi Brian and everybody else, its downloaded stock prices I want to transform to middle of month stock price. endpoints give end of month doesn't it?if Im using endpoints I get a really strange result with a lot of NA:s My Data starts with the 15:th som my idea it transforming the data to.monthly somehow My function is (provided by Ulrich): monthly = function(x){ sym - sub(\\..*$, , names(x)[1]) Ad(to.monthly(x, indexAt = 'lastof', drop.time = TRUE, name = sym))} Possibly put the month in an array, determine the size of the array and then take the price/returns at the midpoint of the array? That way number of days in the month, holidays, etc. wouldn't matter much? - Mark ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Weird behavior of getSymbols for symbol PLL and PL
Not reproducible for me. I've got an older version of R and a newer version of quantmod $ R --vanilla -q suppressMessages(library(quantmod)) options(getSymbols.warning4.0=FALSE) getSymbols(c(PLL, PL)) [1] PLL PL head(PLL) PLL.Open PLL.High PLL.Low PLL.Close PLL.Volume PLL.Adjusted 2007-01-0335.0835.19 34.53 34.89 66810030.77 2007-01-0434.6934.74 34.32 34.69 52150030.60 2007-01-0534.0034.25 33.61 33.75117160029.77 2007-01-0833.7233.74 33.23 33.71 65670029.73 2007-01-0933.9034.27 33.67 34.21 76500030.17 2007-01-1034.0034.15 33.77 34.07 70800030.05 tail(PLL) PLL.Open PLL.High PLL.Low PLL.Close PLL.Volume PLL.Adjusted 2015-03-06 101.18 101.85 99.90100.17 510200 100.17 2015-03-09 100.10 100.42 100.00100.22 441700 100.22 2015-03-1098.7999.67 98.25 98.25 52960098.25 2015-03-1198.2598.37 97.54 97.91 44570097.91 2015-03-1298.5299.75 98.40 99.55 43860099.55 2015-03-1399.4599.79 98.54 99.61 43730099.61 head(PL) PL.Open PL.High PL.Low PL.Close PL.Volume PL.Adjusted 2007-01-03 47.79 48.56 47.5047.95380100 39.01 2007-01-04 47.93 48.30 47.8248.00370300 39.05 2007-01-05 48.25 50.45 48.2550.35 1108300 40.96 2007-01-08 50.17 50.45 49.6249.76656300 40.48 2007-01-09 49.74 49.74 49.2349.61473200 40.36 2007-01-10 49.48 50.06 49.4349.67467100 40.41 tail(PL) PL.Open PL.High PL.Low PL.Close PL.Volume PL.Adjusted 2015-01-23 69.94 69.96 69.9469.95 500 69.95 2015-01-26 69.95 69.95 69.9469.95630900 69.95 2015-01-27 69.95 69.98 69.9569.96643800 69.96 2015-01-28 69.98 69.98 69.9569.95975200 69.95 2015-01-29 69.98 69.98 69.9669.96915500 69.96 2015-01-30 69.99 70.01 69.9569.95 9516700 69.95 sessionInfo() R version 3.1.2 (2014-10-31) Platform: x86_64-apple-darwin13.4.0 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] quantmod_0.4-3 TTR_0.22-0 xts_0.9-7 zoo_1.7-11 loaded via a namespace (and not attached): [1] grid_3.1.2 lattice_0.20-29 Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] CUSIP Numbers
Since this is an R mailing list, I'll try to bring this thread back on topic. Unless you are willing to pay, the only free source that I am aware of to get CUSIPs via R is TradeKing. https://developers.tradeking.com/documentation/market-ext-quotes-get-post You must have an account, but you can create an account for free and you don't have to fund it in order to do this. library(ROAuth) #importFrom(ROAuth, OAuthFactory) library(RJSONIO) #importFrom(RJSONIO, fromJSON) #' ## This part could go in your .Rprofile #' # Set your application keys # https://developers.tradeking.com/applications #' cKey - '' #' cSecret - '#' #' oKey - '' #' oSecret - '' # Set the API endpoint tkURL - https://api.tradeking.com/v1/market/ext/quotes.json; # Create the OAuth connection - this is straight from the ROAuth documentation on CRAN credentials - OAuthFactory$new(consumerKey=cKey, consumerSecret=cSecret, oauthKey = oKey, oauthSecret = oSecret, needsVerifier=FALSE, signMethod='HMAC') # Update the connection so the handshake is TRUE credentials$handshakeComplete - TRUE Symbols - tolower(c(AAPL, MSFT)) ## Whatever symbols you want symbols - paste(Symbols, collapse=,) #what - datetime,bidsz,bid,ask,asksz,last,chg,pchg,opn,hi,lo,vl what - cusip what - gsub( , , tolower(paste(unlist(strsplit(what, ,)), collapse=,))) tkURL - https://api.tradeking.com/v1/market/ext/quotes.json; query - list(symbols=symbols, fids=what) response - credentials$OAuthRequest(tkURL, query) res - fromJSON(response) qt - res$response$quotes$quote qt #[[1]] # cusip exch symbol #59491810 NASD MSFT # #[[2]] # cusip exch symbol #03783310 NASD AAPL HTH, Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] RFC: quantmod::getSymbols.MySQL
Hi Josh, As you probably noticed, I updated getSymbols.FI() to use options a couple weeks ago, but instead of using a single option that is a list, I made a separate option for each function argument. This allows two things: 1) you can have different default values set for the from argument (for example) of different getSymbols.*() methods. 2) It doesn't change the old defaults. i.e. getOption(someOption, 2014-01-01) will return the value of the option if it is set, or 2014-01-01 if not. With your list structure, the default value has to be determined inside the function, I suppose. Here's the formal argument list for getSymbols.FI args(getSymbols.FI) function (Symbols, from = getOption(getSymbols.FI.from, 2010-01-01), to = getOption(getSymbols.FI.to, Sys.Date()), ..., dir = getOption(getSymbols.FI.dir, ), return.class = getOption(getSymbols.FI.return.class, xts), extension = getOption(getSymbols.FI.extension, rda), split_method = getOption(getSymbols.FI.split_method, c(days, common)), use_identifier = getOption(getSymbols.FI.use_identifier, NA), date_format = getOption(getSymbols.FI.date_format), verbose = getOption(getSymbols.FI.verbose, TRUE), days_to_omit = getOption(getSymbols.FI.days_to_omit, c(Saturday, Sunday)), indexTZ = getOption(getSymbols.FI.indexTZ, NA)) Garrett On Wed, Oct 29, 2014 at 7:25 AM, Joshua Ulrich josh.m.ulr...@gmail.com wrote: As many of you know, the Defaults package was removed from CRAN on 2014-10-03 at Jeff's request. This broke a fair bit of functionality in quantmod, most of which I have addressed in recent commits on R-Forge. One issue I have not resolved is how to adapt getSymbols.MySQL to the new no-Defaults paradigm. I will be taking over as maintainer of quantmod, so I am soliciting input from getSymbols.MySQL users. My proposed solution to getSymbols.MySQL is to look for specific option()s if certain arguments are missing. I think this is the cleanest and most obvious solution, but am open to alternatives. I would use the option structure below, with only the three arguments listed. options(quantmod.defaults = list( getSymbols.MySQL = list( user=josh, password=secret, dbname=stocks) ) ) Should I consider another option structure? Should additional arguments be supported? Anything else I'm missing? Thanks, -- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] How can I get Japanese Stock Daily Data in R?
You can get intraday data for the past few days from here: http://k-db.com/stocks Sorry, I don't use R to download that, but it should be trivial. Hope this helps, Garrett On Fri, Oct 17, 2014 at 8:18 AM, Qi Li qi.l...@gmail.com wrote: Hi, I am also very interested in this data. Please also let me know if you have a solution. Thanks. Qi On Fri, Oct 17, 2014 at 8:52 AM, Eric (YEN-LIN) CHIU ndc24...@gmail.com wrote: As I know, RFinanceYJ cannot work properly since the format of Yahoo in Japan change the format of data. Every time I try to fetch data, it shows Error in order(financial.data$date) : argument 1 is not a vector The current solution I found is in here: http://rstudio-pubs-static.s3.amazonaws.com/6475_3034596b267b4a7587cefd3b8ed4ba25.html But it is not convenient to choose date or change the data into xts object. I notice google finance has Japanese stock data, but getSymbols cannot access the data either. I tried getSymbols(TYO:4689), but it cannot open the URL. Could anyone please give me some advice for this? Thanks. Eric [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] 'Defaults' removed from CRAN? (2014-10-03)
Out of curiosity, did you try _not_ changing your current code, but instead adding library(Defaults) to the top of the script? It's not ideal, but Defaults _is_ still available (http://cran.r-project.org/src/contrib/Archive/Defaults/). That could buy you some time until you come up with something better. Just a (possibly bad) thought. Garrett On Wed, Oct 8, 2014 at 9:43 AM, Mark Knecht markkne...@gmail.com wrote: On Tue, Oct 7, 2014 at 7:14 PM, Joshua Ulrich josh.m.ulr...@gmail.com wrote: I just pushed an updated quantmod_0.4-2 to R-Forge. Most of the Defaults-related issues have been addressed, except for getSymbols.MySQL and setTA/unsetTA. Feedback would be much appreciated. -- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com On Tue, Oct 7, 2014 at 3:40 PM, Brian G. Peterson br...@braverock.com wrote: On 10/07/2014 03:26 PM, Daniel Cegiełka wrote: http://cran.r-project.org/web/packages/Defaults/index.html That's a pretty important package that is required by quantmod. Yes. Defaults makes use of unlockBindings to change loaded package namespaces. That's no longer allowed by CRAN. So, we'll need to modify getSymbols to not require it. The old chartSeries uses it too, but we'll be replacing that soon, so I'm not worried about that dependency. Regards, Brian -- Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. OK, it seems to work but requires me to modify long working code to remove setDefaults and then put the database stuff in the actual call. Is this the way this is intended to work in the future and I should modify my files? I'm pretty sure the data is coming from MySQL as AAPL is not in the ETF database and it fails if I add it to the symbol list: source('~/.active-rstudio-document') [1] From MySQL -- SPY [1] From MySQL -- IWM [1] From MySQL -- QQQ [1] From MySQL -- AAPL Error in Symbols[[i]] : subscript out of bounds In addition: Warning message: In getSymbols.MySQL(Symbols = AAPL, env = environment, verbose = FALSE, : could not load symbol(s): AAPL The code I ran is at the bottom. Thanks, Mark source('~/R/Test Cases/RMySQL-Test.R') Loading required package: xts Loading required package: zoo Attaching package: ‘zoo’ The following objects are masked from ‘package:base’: as.Date, as.Date.numeric Loading required package: TTR Version 0.4-0 included new data defaults. See ?getSymbols. Loading required package: DBI [1] From MySQL -- SPY As of 0.4-0, ‘getSymbols’ uses env=parent.frame() and auto.assign=TRUE by default. This behavior will be phased out in 0.5-0 when the call will default to use auto.assign=FALSE. getOption(getSymbols.env) and getOptions(getSymbols.auto.assign) are now checked for alternate defaults This message is shown once per session and may be disabled by setting options(getSymbols.warning4.0=FALSE). See ?getSymbol for more details [1] From MySQL -- IWM [1] From MySQL -- QQQ llibrary(quantmod) library(RMySQL) Sys.setenv(TZ = UTC) DataStart = 1990-01-01 DataEnd = format(Sys.time(), %Y-%m-%d) SymbolSrc = yahoo dbName = R_ETF MyAdjust = TRUE UseMySQL = TRUE SymbolList = c(SPY,IWM,QQQ) if (UseMySQL){ if (MyAdjust) { dbName = paste0(dbName, Adjust)} dbc = dbConnect(MySQL(), dbname=dbName) # setDefaults(getSymbols.MySQL, user=mark, password=MyTempPassword, dbname=dbName) } if (!UseMySQL){ for (i in 1:length(SymbolList)){ print(paste(From ,SymbolSrc, -- ,SymbolList[i])) getSymbolsCont(SymbolList[i], from = DataStart, to = DataEnd, adjust = MyAdjust, src=SymbolSrc) } } else { for (i in 1:length(SymbolList)){ print(paste(From MySQL -- ,SymbolList[i])) # getSymbols(SymbolList[i], src=MySQL) getSymbols(SymbolList[i], src=MySQL, user=mark, password=MyTempPassword, dbname=dbName) assign(SymbolList[i], get(SymbolList[i])[paste0(DataStart,/,DataEnd)]) } dbDisconnect(dbc) } ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list
Re: [R-SIG-Finance] How to download options data in R from a csv list of underlying stock symbols?
Please don't cross post: http://stackoverflow.com/questions/26091219/how-to-download-options-data-in-r-from-a-csv-list-of-underlying-stock-symbols On Sun, Sep 28, 2014 at 8:11 PM, Liu carloslew...@gmail.com wrote: Hello everyone, I've recently joined this mailing list for quantstrat. I hope not to ask repetitive question but I haven't googled any effective solutions yet. I have a csv file containing 100 stock symbols. I want to download the option chains of each underlying including price, volume, IV, HV etc. Hopefully with greeks too. EOD data from yahoo finance would be adequate for now. I’m using R 3.1.1 on Windows 8, 64 bit. At first, I tried “quantmod” using “getSymbols”, as a result I have got a vector of stock symbols. ticker-read.csv(C:/User/User/Documents/equity ticker.csv) getSymbols(ticker, from=”2014-09-01”, to=Sys.date()) But it is not numerical options data, but just character symbols. (I might understand it wrongly, please correct if I misuse getSymbols or other functions) Then I tried “yahoo_opt” http://page.math.tu-berlin.de/~mkeller/index.php?target=rcode, but this script requires “fCalander” which is no longer available in CRAN. I downloaded the achive from here http://cran.r-project.org/src/contrib/Archive/fCalendar/ But I couldn’t install it. The last version of “fCalander” seemed to be compatible with R 2.2, therefore I was unable to run the R file. Please help with using quantmod/quantstrat more effectively, or other available methods to download those options data. By the way how can I search the old posts in this mailing list? Thank you. Carlos [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] How to download options data in R from a csv list of underlying stock symbols?
getOptionChain() only provides the most recent quote, not historical time series data. That's why I didn't answer your question on SO. ;-) Sorry, Garrett On Sun, Sep 28, 2014 at 9:27 PM, Liu carloslew...@gmail.com wrote: Hello G See, May I ask about the usage of getOptionChain? If I want to download a whole month options EOD data, what do I do? I tried: AA-getOptionChain(tick[1],from=2014-09-01,to=2014-09-28) but it only returns 1 day option chain data, which is same as: AA-getOptionChain(tick[1]) Thank you Carlos On Sun, Sep 28, 2014 at 10:05 PM, G See gsee...@gmail.com wrote: Please don't cross post: http://stackoverflow.com/questions/26091219/how-to-download-options-data-in-r-from-a-csv-list-of-underlying-stock-symbols On Sun, Sep 28, 2014 at 8:11 PM, Liu carloslew...@gmail.com wrote: Hello everyone, I've recently joined this mailing list for quantstrat. I hope not to ask repetitive question but I haven't googled any effective solutions yet. I have a csv file containing 100 stock symbols. I want to download the option chains of each underlying including price, volume, IV, HV etc. Hopefully with greeks too. EOD data from yahoo finance would be adequate for now. I’m using R 3.1.1 on Windows 8, 64 bit. At first, I tried “quantmod” using “getSymbols”, as a result I have got a vector of stock symbols. ticker-read.csv(C:/User/User/Documents/equity ticker.csv) getSymbols(ticker, from=”2014-09-01”, to=Sys.date()) But it is not numerical options data, but just character symbols. (I might understand it wrongly, please correct if I misuse getSymbols or other functions) Then I tried “yahoo_opt” http://page.math.tu-berlin.de/~mkeller/index.php?target=rcode, but this script requires “fCalander” which is no longer available in CRAN. I downloaded the achive from here http://cran.r-project.org/src/contrib/Archive/fCalendar/ But I couldn’t install it. The last version of “fCalander” seemed to be compatible with R 2.2, therefore I was unable to run the R file. Please help with using quantmod/quantstrat more effectively, or other available methods to download those options data. By the way how can I search the old posts in this mailing list? Thank you. Carlos [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] How to download options data in R from a csv list of underlying stock symbols?
That's not really an R question, but you could get historical options prices with the IBrokers package if you have an Interactive Brokers account, or with the Rbbg package if you have a Bloomberg. Garrett On Sun, Sep 28, 2014 at 9:35 PM, Liu carloslew...@gmail.com wrote: That's a pity. Do you know any alternative tools/methods to get the historical data? Thanks On Sunday, September 28, 2014, G See gsee...@gmail.com wrote: getOptionChain() only provides the most recent quote, not historical time series data. That's why I didn't answer your question on SO. ;-) Sorry, Garrett On Sun, Sep 28, 2014 at 9:27 PM, Liu carloslew...@gmail.com wrote: Hello G See, May I ask about the usage of getOptionChain? If I want to download a whole month options EOD data, what do I do? I tried: AA-getOptionChain(tick[1],from=2014-09-01,to=2014-09-28) but it only returns 1 day option chain data, which is same as: AA-getOptionChain(tick[1]) Thank you Carlos On Sun, Sep 28, 2014 at 10:05 PM, G See gsee...@gmail.com wrote: Please don't cross post: http://stackoverflow.com/questions/26091219/how-to-download-options-data-in-r-from-a-csv-list-of-underlying-stock-symbols On Sun, Sep 28, 2014 at 8:11 PM, Liu carloslew...@gmail.com wrote: Hello everyone, I've recently joined this mailing list for quantstrat. I hope not to ask repetitive question but I haven't googled any effective solutions yet. I have a csv file containing 100 stock symbols. I want to download the option chains of each underlying including price, volume, IV, HV etc. Hopefully with greeks too. EOD data from yahoo finance would be adequate for now. I’m using R 3.1.1 on Windows 8, 64 bit. At first, I tried “quantmod” using “getSymbols”, as a result I have got a vector of stock symbols. ticker-read.csv(C:/User/User/Documents/equity ticker.csv) getSymbols(ticker, from=”2014-09-01”, to=Sys.date()) But it is not numerical options data, but just character symbols. (I might understand it wrongly, please correct if I misuse getSymbols or other functions) Then I tried “yahoo_opt” http://page.math.tu-berlin.de/~mkeller/index.php?target=rcode, but this script requires “fCalander” which is no longer available in CRAN. I downloaded the achive from here http://cran.r-project.org/src/contrib/Archive/fCalendar/ But I couldn’t install it. The last version of “fCalander” seemed to be compatible with R 2.2, therefore I was unable to run the R file. Please help with using quantmod/quantstrat more effectively, or other available methods to download those options data. By the way how can I search the old posts in this mailing list? Thank you. Carlos [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] IBrokers Problem
I don't know; it works for me. Does reqCurrentTime(tws) return the current time? Garrett tws - ibgConnect() reqCurrentTime(tws) [1] 2013-12-09 09:04:37 CST reqContractDetails(tws, twsEquity(QQQ)) [[1]] List of 18 $ version : chr 6 $ contract :List of 16 ..$ conId : chr 43661924 ..$ symbol : chr QQQ ..$ sectype: chr STK ..$ exch : chr SMART ..$ primary: chr NASDAQ ..$ expiry : chr ..$ strike : chr 0 ..$ currency : chr USD ..$ right : chr ..$ local : chr QQQ ..$ multiplier : chr ..$ combo_legs_desc: chr ..$ comboleg : chr ..$ include_expired: chr 0 ..$ secIdType : chr ..$ secId : chr ..- attr(*, class)= chr twsContract $ marketName: chr NMS $ tradingClass : chr NMS $ conId : chr 43661924 $ minTick : chr 0.01 $ orderTypes: chr [1:49] ACTIVETIM ADJUST ALERT ALGO ... $ validExchanges: chr [1:17] SMART ISE CHX ARCA ... $ priceMagnifier: chr 1 $ underConId: chr 0 $ longName : chr POWERSHARES QQQ NASDAQ 100 $ contractMonth : chr $ industry : chr Funds $ category : chr Equity Fund $ subcategory : chr Sector Fund-Technology $ timeZoneId: chr EST $ tradingHours : chr 20131209:0400-2000;20131210:0400-2000 $ liquidHours : chr 20131209:0930-1600;20131210:0930-1600 On Mon, Dec 9, 2013 at 7:47 AM, Michael Smith my.r.h...@gmail.com wrote: Thanks for the quick reply, but R still hangs after running this command with the new ticker. Best, Michael On 12/09/2013 09:29 PM, G See wrote: The ticker for that ETF changed to QQQ on March 23, 2011 Try reqContractDetails(tws, twsEquity(QQQ)) Best, Garrett On Mon, Dec 9, 2013 at 7:27 AM, Michael Smith my.r.h...@gmail.com wrote: All, I'm trying to better understand how to use the IBrokers package by going through the `IBrokers.pdf` vignette. I'm using the demo version of TWS (login `edemo`). TWS seems to be running fine. However, I get stuck at the following command from the vignette: reqContractDetails(tws, twsEquity()) R just seems to hang and I don't get any further response. My sessionInfo is below. I'm using the most current IBrokers from Google Code. Am I doing something wrong, or is this not supposed to work with the TWS demo version? Thanks, Michael sessionInfo() R version 3.0.2 (2013-09-25) Platform: x86_64-redhat-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C LC_TIME=en_US.utf8 [4] LC_COLLATE=en_US.utf8 LC_MONETARY=en_US.utf8 LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C LC_ADDRESS=C [10] LC_TELEPHONE=CLC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] IBrokers_0.9-11 xts_0.9-7 zoo_1.7-10 colorout_1.0-1 loaded via a namespace (and not attached): [1] grid_3.0.2 lattice_0.20-24 tools_3.0.2 ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] IBrokers Problem
Yup. Works fine for me with the demo account on Ubuntu. Have you tried restarting the TWS? (while you're at it, you might consider using IB Gateway instead since it doesn't log you out every day) sessionInfo() R version 3.0.2 (2013-09-25) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] IBrokers_0.9-11 xts_0.9-7 zoo_1.7-11 loaded via a namespace (and not attached): [1] grid_3.0.2 lattice_0.20-18 Sorry I can't be of more assistance, Garrett On Mon, Dec 9, 2013 at 5:25 PM, Michael Smith my.r.h...@gmail.com wrote: Does it work for you in the demo TWS version as well? For me, `reqCurrentTime` works fine in the demo TWS version, like all the other examples in the vignette, except for `twsFuture`. reqCurrentTime(tws) TWS Message: 2 -1 2104 Market data farm connection is OK:ibdemo TWS Message: 2 -1 2106 HMDS data farm connection is OK:demohmds [1] 2013-12-10 07:14:29 HKT Interestingly, when I run the following code, I get some feedback from the Unix shell that runs TWS. tws - twsConnect() reqContractDetails(tws, twsEquity(QQQ)) # R hangs here. ^C twsDisconnect(tws) So when I run `twsDisconnect` (only after running `reqContractDetails`) in the example above, I get the following output in the Unix shell from Java: 07:23:13:870 JTS-EServerSocket-157: [1:47:67:1:0:0:0:ERR] Message type 1. Attempted read beyond end of socket stream - 07:23:13:870 JTS-EServerSocket-157: Anticipated error jextend.c: Attempted read beyond end of socket stream - at jextend.tb.b(tb.java:307) at jextend.hf.eb(hf.java:1316) at jextend.hf.run(hf.java:1251) at java.lang.Thread.run(Thread.java:744) Caused by: java.io.EOFException at jextend.tb.c(tb.java:541) at jextend.tb.r(tb.java:183) at jextend.wd.a(wd.java:188) at jextend.tb.d(tb.java:613) at jextend.uc.a(uc.java:177) at jextend.tb.b(tb.java:304) ... 3 more 07:23:13:871 JTS-EServerSocket-157: [1:47:67:1:0:0:0:SYS] Client{1} terminated conversation. 07:23:13:871 JTS-EServerSocketNotifier-156: Terminating Thanks, Michael On 12/09/2013 11:06 PM, G See wrote: I don't know; it works for me. Does reqCurrentTime(tws) return the current time? Garrett tws - ibgConnect() reqCurrentTime(tws) [1] 2013-12-09 09:04:37 CST reqContractDetails(tws, twsEquity(QQQ)) [[1]] List of 18 $ version : chr 6 $ contract :List of 16 ..$ conId : chr 43661924 ..$ symbol : chr QQQ ..$ sectype: chr STK ..$ exch : chr SMART ..$ primary: chr NASDAQ ..$ expiry : chr ..$ strike : chr 0 ..$ currency : chr USD ..$ right : chr ..$ local : chr QQQ ..$ multiplier : chr ..$ combo_legs_desc: chr ..$ comboleg : chr ..$ include_expired: chr 0 ..$ secIdType : chr ..$ secId : chr ..- attr(*, class)= chr twsContract $ marketName: chr NMS $ tradingClass : chr NMS $ conId : chr 43661924 $ minTick : chr 0.01 $ orderTypes: chr [1:49] ACTIVETIM ADJUST ALERT ALGO ... $ validExchanges: chr [1:17] SMART ISE CHX ARCA ... $ priceMagnifier: chr 1 $ underConId: chr 0 $ longName : chr POWERSHARES QQQ NASDAQ 100 $ contractMonth : chr $ industry : chr Funds $ category : chr Equity Fund $ subcategory : chr Sector Fund-Technology $ timeZoneId: chr EST $ tradingHours : chr 20131209:0400-2000;20131210:0400-2000 $ liquidHours : chr 20131209:0930-1600;20131210:0930-1600 On Mon, Dec 9, 2013 at 7:47 AM, Michael Smith my.r.h...@gmail.com wrote: Thanks for the quick reply, but R still hangs after running this command with the new ticker. Best, Michael On 12/09/2013 09:29 PM, G See wrote: The ticker for that ETF changed to QQQ on March 23, 2011 Try reqContractDetails(tws, twsEquity(QQQ)) Best, Garrett On Mon, Dec 9, 2013 at 7:27 AM, Michael Smith my.r.h...@gmail.com wrote: All, I'm trying to better understand how to use the IBrokers package by going through the `IBrokers.pdf` vignette. I'm using the demo version of TWS (login `edemo`). TWS seems to be running fine. However, I get stuck at the following command from the vignette: reqContractDetails(tws, twsEquity()) R just seems to hang and I don't get any further response. My sessionInfo is below. I'm using the most current IBrokers from Google Code. Am I doing something wrong, or is this not supposed to work with the TWS demo version
Re: [R-SIG-Finance] Introducing TFX: An R Interface to the TrueFX Web API
Because you've pasted a right single quote unicode symbol instead of typing an apostrophe. When I copy/paste from the command you entered, I get R charToRaw(’) [1] e2 80 99 When I type an apostrophe using the keyboard, I get R charToRaw(') [1] 27 Try typing your command instead of copy/pasting it. Hope this helps, Garrett On Wed, Nov 27, 2013 at 10:37 PM, veepsirtt veepsi...@gmail.com wrote: Hello Gsee, Why I am getting this error?. unexpected input in QueryTrueFX(ConnectTrueFX(username=’ --- ## Cannot run these because there may not be an internet connection ## Not run: library(TFX) QueryTrueFX() #unauthenticated Symbol Bid.Price Ask.Price High Low TimeStamp 1 EUR/USD 1.35773 1.35781 1.35804 1.35634 2013-11-28 04:29:35 2 USD/JPY 102.05800 102.06400 102.29100 101.93300 2013-11-28 04:29:38 3 GBP/USD 1.63036 1.63055 1.63074 1.62763 2013-11-28 04:29:35 4 EUR/GBP 0.83265 0.83282 0.83436 0.83235 2013-11-28 04:29:35 5 USD/CHF 0.90768 0.90784 0.90874 0.90725 2013-11-28 04:29:40 6 EUR/JPY 138.56800 138.58300 138.84900 138.29900 2013-11-28 04:29:35 7 EUR/CHF 1.23241 1.23266 1.23308 1.23195 2013-11-28 04:29:35 8 USD/CAD 1.05844 1.05867 1.05987 1.05746 2013-11-28 04:29:34 9 AUD/USD 0.91259 0.91270 0.91411 0.90742 2013-11-28 04:29:34 10 GBP/JPY 166.38900 166.42000 166.61000 165.95600 2013-11-28 04:29:35 QueryTrueFX(pretty=FALSE) $Symbol [1] EUR/USD USD/JPY GBP/USD EUR/GBP USD/CHF EUR/JPY EUR/CHF USD/CAD AUD/USD GBP/JPY $BidBigNumber [1] 1.35 102. 1.63 0.83 0.90 138. 1.23 1.05 0.91 166. $BidPip [1] 773 058 036 265 768 568 241 844 259 389 $OfferBigNumber [1] 1.35 102. 1.63 0.83 0.90 138. 1.23 1.05 0.91 166. $OfferPip [1] 781 064 055 282 784 583 266 867 270 420 $High [1] 1.35804 102.291 1.63074 0.83436 0.90874 138.849 1.23308 1.05987 0.91411 166.610 $Low [1] 1.35634 101.933 1.62763 0.83235 0.90725 138.299 1.23195 1.05746 0.90742 165.956 $TimeStamp [1] 1385612975232 1385612978277 1385612975780 1385612975128 1385612980409 1385612975181 [7] 1385612975905 1385612974630 1385612974758 1385612975675 QueryTrueFX(parse=FALSE) [1] EUR/USDUSD/JPYGBP/USDEUR/GBPUSD/CHFEUR/JPYEUR/CHFUSD/CADAUD/USDGBP/JPY1.35102.1.630.830.90138.1.231.050.91166.7690580362627735672398442593891.35102.1.630.830.90138.1.231.050.91166.7770640552787875812638672704201.35804102.2911.630740.834360.90874138.8491.233081.059870.91411166.6101.35634101.9331.627630.832350.90725138.2991.231951.057460.90742165.9561385612981970138561297827713856129820241385612981995138561298220413856129818141385612981814138561297463013856129747581385612975675 ## For authenticated session, you must have a username and password (it’s free). ## Use your username and passward instead of JSTrader and Ou812 id - ConnectTrueFX(’EUR/USD,GBP/USD’, username=’veepsirtt’,password=’veeps203’) Error: unexpected input in id - ConnectTrueFX(’ QueryTrueFX(id) Symbol Bid.Price Ask.PriceHigh Low TimeStamp 1 EUR/USD 1.35769 1.35777 1.35804 1.35634 2013-11-28 04:29:52 2 GBP/USD 1.63031 1.63048 1.63074 1.62763 2013-11-28 04:29:52 id environment: 0x10459290 attr(,class) [1] TFXsession environment QueryTrueFX(ConnectTrueFX(username=’veepsirtt’, password=’veeps203’,format=’csv’), arse=FALSE) Error: unexpected input in QueryTrueFX(ConnectTrueFX(username=’ QueryTrueFX(ConnectTrueFX(username=’veepsirtt’, password=’veeps203’,format=’html’), arse=FALSE) Error: unexpected input in QueryTrueFX(ConnectTrueFX(username=’ -- View this message in context: http://r.789695.n4.nabble.com/Introducing-TFX-An-R-Interface-to-the-TrueFX-Web-API-tp4651827p4681300.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Introducing TFX: An R Interface to the TrueFX Web API
you entered a less than sign instead of an assignment operator. instead of id ConnectTrueFX(... it should be id - ConnectTrueFX(... On Wed, Nov 27, 2013 at 11:10 PM, veepsirtt veepsi...@gmail.com wrote: id ConnectTrueFX(EUR/USD,username=veepsirtt,password=veeps203) Error in id ConnectTrueFX(EUR/USD, username = veepsirtt, password = veeps203) : comparison (3) is possible only for atomic and list types -- View this message in context: http://r.789695.n4.nabble.com/Introducing-TFX-An-R-Interface-to-the-TrueFX-Web-API-tp4651827p4681302.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Introducing TFX: An R Interface to the TrueFX Web API
Try typing that command. Your single quote is a weird character. Try this: id - ConnectTrueFX('EUR/USD,GBP/USD', username='veepsirtt', password='veeps203') On Tue, Nov 26, 2013 at 3:47 AM, veepsirtt veepsi...@gmail.com wrote: Hello gsee, I tryied the examples given in your documentation. But I am getting errors. what is the problem? With regards veepsirtt. ## Cannot run these because there may not be an internet connection ## Not run: library(TFX) QueryTrueFX() #unauthenticated QueryTrueFX(pretty=FALSE) QueryTrueFX(parse=FALSE) ## For authenticated session, you must have a username and password (it’s free). ## Use your username and passward instead of JSTrader and Ou812 id - ConnectTrueFX(’EUR/USD,GBP/USD’, username=’veepsirtt’, password=’veeps203’) QueryTrueFX(id) QueryTrueFX(ConnectTrueFX(username=’veepsirtt’, password=’veeps203’,format=’csv’), parse=FALSE) QueryTrueFX(ConnectTrueFX(username=’veepsirtt’, password=’veeps203’,format=’html’), parse=FALSE) ## If you have shiny installed ## install.packages(shiny, repos=http://rstudio.org/_packages;) library(shiny) runGist(4122626) ## view the code for this shiny app at #browseURL(https://gist.github.com/4122626;) ## End(Not run)-- RESULTS*** source('~/.active-rstudio-document', echo=TRUE) Error in source(~/.active-rstudio-document, echo = TRUE) : ~/.active-rstudio-document:11:21: unexpected input 10: 11: id - ConnectTrueFX(� ^ sessionInfo() R version 2.15.3 (2013-03-01) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] shiny_0.8.0 TFX_0.1.0 ggplot2_0.9.3.1 xtsExtra_0.0-1 tseries_0.10-32 quantmod_0.4-0 [7] TTR_0.21-1 xts_0.9-3 zoo_1.7-9 Defaults_1.1-1 loaded via a namespace (and not attached): [1] bitops_1.0-4.1 caTools_1.13 colorspace_1.2-0 dichromat_1.2-4digest_0.5.2 [6] grid_2.15.3gtable_0.1.1 httpuv_1.2.0 labeling_0.1 lattice_0.20-13 [11] MASS_7.3-23munsell_0.4plyr_1.7.1 proto_0.3-9.2 quadprog_1.5-5 [16] RColorBrewer_1.0-5 Rcpp_0.10.2reshape2_1.2.1 RJSONIO_1.0-1 scales_0.2.3 [21] stringr_0.6.1 tools_2.15.3 XML_3.98-1.1 xtable_1.7-0 -- View this message in context: http://r.789695.n4.nabble.com/Introducing-TFX-An-R-Interface-to-the-TrueFX-Web-API-tp4651827p4681163.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Do the blotter demos work?
Looks like it's built on r-forge. You should be able to install it with install.packages(blotter, repos=http://r-forge.r-project.org;) Regards, Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] day/month/year functions?
I'd guess they come from lubridate. Although, they exist is a few packages. findFn() from the sos package is really good for finding out where a function comes from. library(sos) findFn(day) # it works better for functions with more obscure names. Garrett On Mon, Jul 22, 2013 at 7:15 PM, Mark Knecht markkne...@gmail.com wrote: Hi, I've got a piece of old code I'm trying to resurrect which contains this function to convert R dates to TradeStation dates: function (MyDate) { ThisDay = day(MyDate) ThisMonth = month(MyDate) ThisYear = year(MyDate) TSDate = (ThisYear - 1900)*1 + ThisMonth*100 + ThisDay return(TSDate) } However I don't have the day/month/year functions and so far haven't found them searching using ??day, etc. Does anyone recognize these as coming from a package that for some reason might not be showing up using ??-type searching? Thanks, Mark ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] qmao and earnings.com problem
That's very disappointing. Thanks for the heads up. Garrett On Sun, Jul 7, 2013 at 6:34 PM, TheTerrible ivan...@bit-of-light.com wrote: Hi All, It looks Earnings.com does not exist anymore - redirected to reuters. So qmao package doesn't work. Is there still a way to get earnings info from any free source? Thanks in advance, Ivan -- View this message in context: http://r.789695.n4.nabble.com/qmao-and-earnings-com-problem-tp4671061.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Delete bad dividend row
Hi Frank, There are a few ways to do it. library(quantmod) div - getDividends(PM, from=2010-01-01) # find the row(s) you want to remove and use negative indexing div[-12] div[-which(div == 0.039)] div[-div[2012-12-20, which.i=TRUE]] # exclude specific date by passing logical vector to [.xts div[!index(div) %in% as.Date(2012-12-20)] # exclude specific weekdays div[weekdays(index(div)) != Thursday] div[as.POSIXlt(index(div))$wday != 4] # exclude amounts smaller than some arbitrary number div[div 0.1] # exclude specific amount div[div != 0.039] HTH, Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] cut range from time objects
Hi Dominykas I would try the below as my first attempt. library(xts) library(timeSeries) Sys.setenv(TZ=GMT) temp - xts(1:84, timeCalendar(m=1, d=rep(1:7,each=12),h = seq(0,23,2))) # Monday through Thursday mt - temp[.indexwday(temp) %in% 1:4] # Friday 00:00:00/20:00:00 f - temp[.indexwday(temp) == 5L][T00:00:00/T20:00:00] # Sunday 20:00:00/24:00:00 s - temp[.indexwday(temp) == 0L][T20:00:00.000/T23:59:59.999] out - rbind(mt, f, s) # check answer by adding a column with weekday (0-6 starting on Sunday) colnames(out) - temp # have to have a column name to do the next step out$wday - .indexwday(out) # Now you can look at the output and see that the only times where wday is 0 # are 20:00 or later, and the only times where wday is 5 are 20:00 or earlier out Hope this helps, Garrett On Sun, Jun 23, 2013 at 10:02 AM, Dominykas Grigonis dominykasgrigo...@gmail.com wrote: Dear all, I have come across the issue and I hope you will be able to help me. I have minute data and unfortunately it has weekends in it and unfortunately the values on weekend are not 0s and not NAs, but rather last trading price of friday. I want to cut the ranges out as it slows down strategy testing. Say we have xts object with timeDate index temp - xts(1:84, timeCalendar(m=1, d=rep(1:7,each=12),h = seq(0,23,2))) I want to cut rows from friday 20:00 to sunday 20:00. I started writing function, but it just does not seem right… filtertime - function(x, rwd - 5/2, rt - 0800/1400){ is.within - function(x){ value - hour(x)*60+minute(x) (value range[1] value range[2])} rwd - as.numeric(strsplit(rwd,/)[[1]]) rt - as.numeric(strsplit(rt,/)[[1]]) rt - (rt%/%100)*60+(rt%%100) time- index(x) if(rwd[1]rwd[2]){ wsq - c((rwd[1]:7), (1:rwd[2])) }else{wsq - rwd[1]:rwd[2]} wweek - sapply(time, function(x){x[all(dayOfWeek(x) != wsq)]}) wweek - x[all(dayOfWeek(x) != wsq)] } I am not looking for help on this function, I hope someone could suggest some efficient way to solve my problem as I am working on 1 year 1minute data. Thank you in advance. Kind regards,-- Dominykas Grigonis [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] create new columns xts
It might be nice if `[[-` worked on zoo/xts objects like it does on a data.frame. For example, X - as.data.frame(temp) n - 1 X[[paste0(sma., n)]] - SMA(X[[1]]) tail(X) But, with zoo/xts objects, temp[[1]] refers to the 1st row of the 1st column. I _think_ the closest you can get is to pass dimnames= through a new xts call like this: merge(temp, xts(SMA(temp), dimnames=list(NULL, paste0(sma., n It's a shame that the availability of dimnames= is so hidden (and that it has to be specified as a list, which is a little weird.) You probably also wanted your `temp` object to have colnames; otherwise, temp$sma - SMA(temp) wouldn't work. Instead of doing that with colnames(temp) - temp you could do it when you create the object which can sometimes be more convenient. temp - xts(1:84, timeCalendar(m=1, d=rep(1:7,each=12),h = seq(0,23,2)), dimnames=list(NULL, temp)) Garrett On Sun, Jun 23, 2013 at 11:34 AM, Dominykas Grigonis dominykasgrigo...@gmail.com wrote: One more question, that will get me going. temp - xts(1:84, timeCalendar(m=1, d=rep(1:7,each=12),h = seq(0,23,2))) I need to add named column, say SMA(temp) nice way to do this is temp$sma - SMA(temp) however it is inside a function and it might have different SMAs, so I want to adda column named paste0(sma.,n) temp$paste0(sma.,n) - SMA(temp) temp[,paste0(sma.,n)] - SMA(temp) does not work it is an option to use merge merge(temp,SMA(temp)) and then colnames However my question is whether it is possible to use temp$paste0(sma.,n) - SMA(temp) in some way. I tried temp$as.name(paste0(sma.,n)) and similar options... Thank you. Kind regards,-- Dominykas Grigonis [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] qmao installation failure
BTW, this Warning (as opposed to error) in getEPS() Warning message: In readLines(tmp) : incomplete final line found on 'C:\Users\BAM\AppData\Local\Temp\RtmpC0laFg\file111060ec69e2' actually comes from getFinancials(). It's harmless, but could be avoided if getFinancials() were patched to use warn=FALSE in the readLines() call. Josh, Jeff, Line 13 of getFinancials.R could be changed from Symbol - readLines(tmp) to Symbols - readLines(tmp, warn=FALSE) Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] qmao installation failure
They're on CRAN http://cran.r-project.org/package=gdata http://cran.r-project.org/package=pander Garrett On Fri, Mar 15, 2013 at 7:43 PM, rex r...@nosyntax.net wrote: Tried: install.packages(qmao, repos=http://R-Forge.R-project.org;) package ‘qmao’ is not available (for R version 2.15.3) SVN: svn checkout svn://scm.r-forge.r-project.org/svnroot/twsinstrument/ Atwsinstrument/pkg Atwsinstrument/pkg/twsInstrument [...] Atwsinstrument/www Atwsinstrument/www/index.php Atwsinstrument/README U twsinstrument Checked out revision 407. cd twsinstrument R CMD INSTALL ./pkg/qmao cd .. * installing to library ‘/home/rex/R/x86_64-pc-linux-gnu-library/2.15’ ERROR: dependencies ‘gdata’, ‘pander’ are not available for package ‘qmao’ * removing ‘/home/rex/R/x86_64-pc-linux-gnu-library/2.15/qmao’ I was unable to find gdata or pander. Any suggestions appreciated. Thanks, -rex -- ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] intraday historical data
This is extremely broad. You just want intraday data? Whose day? The SGX provides free intraday data: http://www.sgx.com/wps/portal/sgxweb/home/marketinfo/historical_data/derivatives/time_sales What asset class? TrueFX provides historical tick data for FX (http://truefx.com/?page=downloads). There's a script called download.TrueFX.R in the inst/parser directory of FinancialInstrument that will download and parse that data. (http://r-forge.r-project.org/scm/viewvc.php/pkg/FinancialInstrument/inst/parser/?root=blotter) Maybe you want stocks? Did you search the internet? I found this via google: http://www.quantshare.com/sa-426-6-ways-to-download-free-intraday-and-tick-data-for-the-us-stock-market That link gives 6 sources. One of them is stooq. They provide 5 days of 5 minute OHLC data for thousands of stocks around the world. I once wrote a script to download and parse that data. I ran it on a crontab for a couple weeks, then they put up a captcha. So, I guess they don't want you downloading the data systematically -- I don't know, I can't read Polish. If you're willing to manually download the data at least once every 5 days, I'd be happy share my code that parses it. Also, the methods that page gives for getting historical intraday data from Google and Yahoo look promising if you're up to parsing it. I think I have some scraps of code laying around somewhere where I started working on that. Let me know if you'd like me to look. I use Interactive Brokers for my personal intraday data needs. They're really hard to beat since they provide a year's worth of data for stocks, bonds, FX, options, futures, etc. for products all over the world. I use (a small adaptation of) twsInstrument:::update.data() to download minutely OHLC data for BID, ASK, and TRADES, data for over 2000 stocks. Since you can only make 6 requests every minute, it takes almost a full day to download 5 days of data. So, it runs 24 hours a day. (it's also helpful to get more than one log-in). There is a cost for Interactive Brokers. It's about 10 or 20 bucks a month, but if you spend that much money on commissions, they waive the fee. I just get minutely data, because I want a lot of history for a lot of symbols, but they also provide 1 second frequency historical data if you are patient. Here's the reference for how much data you can get per request (remember: 6 requests a minute) http://www.interactivebrokers.com/php/apiUsersGuide/apiguide/api/historical_data_limitations.htm If you're interested in realtime/near-realtime intraday data, you have a few options. This will give you a 15 minute delayed quote: getQuote(SPY, src=yahoo) These will give you a real-time quote: library(qmao) getQuote(SPY, src=google) getQuote(SPY, src=IB) # if you have an Interactive Brokers account getQuote(SPY, src=bats) getQuote(SPY, src=bats, what=bbo) getQuote(SPY, src=bats, what=ladder) getQuote(SPY, src=bats, what=depth) getQuote(SPY, src=bats, what=trades) # These come with plot methods too plot(getQuote(SPY, src=bats)) plot(getQuote(SPY, src=ladder)) plot(getQuote(SPY, src=depth)) I created a shiny app using the getQuote.bats stuff. If you run qmao::shinyBATS() it will launch this shiny app: http://glimmer.rstudio.com/gsee/BATS/ You can wrap one of these getQuote calls in a while loop to retrieve a stream of data dat - NULL while(TRUE){ dat - rbind(dat, getQuote(SPY, src=yahoo)) Sys.sleep(1) } (If you like shiny, here's a crude way to plot intraday data as it comes in -- just replace the rnorm call with a getQuote call: https://gist.github.com/gsee/4384158) If you want real-time intraday fx quotes, see the TFX package (http://rpubs.com/gsee/TFX) Recently, I've been excited about this new free API (requires a free account): https://developers.tradeking.com/documentation/r According to their forums, they're planning on rolling out historical intraday data soon. Currently, you can get snapshots, or streaming data. twsInstrument and qmao can be obtained via svn checkout from https://r-forge.r-project.org/R/?group_id=1113 I hope this helps, and I hope that if you write code to parse some intraday historical data, that you share it with the list. Best, Garrett On Mon, Mar 11, 2013 at 6:15 PM, Bill Blount b...@easterngrain.com wrote: i just mean intraday historical quotes. any ideas where? On Mon, Mar 11, 2013 at 6:36 PM, Michael Weylandt michael.weyla...@gmail.com wrote: What exactly do you mean by end of day intraday? Regardless, I assume the answer is 'yes, many by subscription: some cheap: few free.' MW On Mar 11, 2013, at 22:26, Bill Blount b...@easterngrain.com wrote: is there a source for end of day intraday data (i am assuming that yahoo is daily only)? Thanks. Bill [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting
Re: [R-SIG-Finance] IBrokers Risk Management Backend Solution Help with twsPortfolioValue
I don't think the socket connection is shut down. R invisible(reqAccountUpdates(con)) 2 -1 2100 API client has been unsubscribed from account data. R isConnected(con) [1] TRUE Why does your loop break? Do you get an error in R? The 2100 message is a warning http://www.interactivebrokers.com/php/apiUsersGuide/apiguide/tables/api_message_codes.htm Garrett On Sun, Feb 10, 2013 at 12:33 PM, JohnnyPaper brad.saterf...@gmail.com wrote: Hi Everyone, I have a couple of questions to ask, and I absolutely don't mind if this gets resubmitted anywhere else. It seems as though this may be helpful for many people trying to manage portfolio risk with IBrokers, which as I may add is an excellent addition to R. Very nice work on Jeff's part, and many many thanks. I am just trying to keep a loop monitoring my position and shutting them down if they hit a stop or profit target based on my position value. Mind you I am submitting these orders after my offline analysis is done at the EOD. So they are market orders executed at the open, hence the reason for management of the portfolio in this sense through the twsPortfolioValue updates in the data.frame . Here is the code I am using and the results: con - twsConnect() while (TRUE){ Offset-50 Val-twsPortfolioValue(reqAccountUpdates(con),zero.pos=FALSE) for (i in 1:nrow(Val)){ if ( 0.01 * -abs(Val[i,4]) Val[i,8] ){ if (Val[i,6] 0){ IBrokers:::.placeOrder( con, twsSTK(toString(Val[i,1])), twsOrder((i+Offset),BUY,abs(Val[i,6]),MKT) ) Offset- Offset +1 } else if (Val[i,6] 0){ IBrokers:::.placeOrder( con, twsSTK(toString(Val[i,1])), twsOrder((i+Offset),SELL,abs(Val[i,6]),MKT) ) Offset- Offset +1 } } else if (0.03 * abs(Val[i,4]) Val[i,8] ){ if (Val[i,6] 0){ IBrokers:::.placeOrder( con, twsSTK(toString(Val[i,1])), twsOrder((i+Offset),BUY,abs(Val[i,6]),MKT) ) Offset- Offset +1 } else if (Val[i,6] 0){ IBrokers:::.placeOrder( con, twsSTK(toString(Val[i,1])), twsOrder((i+Offset),SELL,abs(Val[i,6]),MKT) ) Offset- Offset +1 } } } print(Val) Sys.sleep(5) } 2 -1 2104 Market data farm connection is OK:usfarm 2 -1 2106 HMDS data farm connection is OK:ushmds local sectype marketValue averageCostreturn position realizedPNL unrealizedPNL 2 AKAM STK-8022.18 -8011.965 -0.0012749681 -227 0 -10.22 6 ETFC STK-7964.32 -7987.240 0.0028695755 -728 0 22.92 8 FISV STK-8048.00 -7994.000 -0.0067550663 -100 0 -54.00 9 GS STK-8006.97 -7985.040 -0.0027463856 -53 0 -21.93 10 HAR STK-8066.78 -8015.330 -0.0064189493 -177 0 -51.45 11 HNZ STK-7987.07 -7990.070 0.0003754658 -131 0 3.00 12 ICE STK 8047.898042.140 0.0007149839 54 0 5.75 14 MOLX STK-8024.33 -8004.405 -0.0024892541 -291 0 -19.92 15 MRK STK-8017.43 -8007.650 -0.0012213320 -195 0 -9.78 16 MWV STK 8053.078009.890 0.0053908356 254 0 43.18 19 OXY STK-8041.22 -8027.020 -0.0017690250 -91 0 -14.20 21 SIAL STK 8081.328013.160 0.0085060074 104 0 68.16 23 VFC STK-7962.50 -8028.320 0.0081984775 -52 0 65.82 25 ZMH STK-8115.41 -8060.680 -0.0067897497 -107 0 -54.73 2 -1 2100 API client has been unsubscribed from account data. local sectype marketValue averageCostreturn position realizedPNL unrealizedPNL 2 AKAM STK-8022.18 -8011.965 -0.0012749681 -227 0 -10.22 6 ETFC STK-7964.32 -7987.240 0.0028695755 -728 0 22.92 8 FISV STK-8048.00 -7994.000 -0.0067550663 -100 0 -54.00 9 GS STK-8006.97 -7985.040 -0.0027463856 -53 0 -21.93 10 HAR STK-8066.78 -8015.330 -0.0064189493 -177 0 -51.45 11 HNZ STK-7987.07 -7990.070 0.0003754658 -131 0 3.00 12 ICE STK 8047.898042.140 0.0007149839 54 0 5.75 14 MOLX STK-8024.33 -8004.405 -0.0024892541 -291 0 -19.92 15 MRK STK-8017.43 -8007.650 -0.0012213320 -195 0 -9.78 16 MWV STK 8053.078009.890 0.0053908356 254 0 43.18 19 OXY STK-8041.22 -8027.020 -0.0017690250 -91 0 -14.20 21 SIAL STK 8081.328013.160 0.0085060074 104 0 68.16 23 VFC STK-7962.50 -8028.320 0.0081984775
Re: [R-SIG-Finance] 4-digit SIC codes
There are actually non-break spaces in the source code of the page. If you look at it, you will see things like this: BA/D nbsp;BR Whether or not XML::trim gets rid of them for you may be OS specific. See and answer to an old question of mine on R-help for example https://stat.ethz.ch/pipermail/r-help/2012-February/302417.html Best, Garrett On Tue, Feb 5, 2013 at 8:20 AM, David Reiner david.rei...@xrtrading.com wrote: Very nice, Garrett! More curious than anything, but does anyone know why I get the extraneous characters when I do it? They are present in x as well. I believe they are non-breaking spaces. head(SIC) SICCode A/D  Office  Industry Title 4 1005 ÂAGRICULTURAL PRODUCTION-CROPS 5 2005  AGRICULTURAL PROD-LIVESTOCK ANIMAL SPECIALTIES 6 7005 ÂAGRICULTURAL SERVICES 7 8005  FORESTRY 8 9005 ÂFISHING, HUNTING AND TRAPPING 910009  METAL MINING sessionInfo() R version 2.15.2 (2012-10-26) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] XML_3.95-0.1 loaded via a namespace (and not attached): [1] tools_2.15.2 Thanks, -- David Reiner -Original Message- From: r-sig-finance-boun...@r-project.org [mailto:r-sig-finance-boun...@r-project.org] On Behalf Of G See Sent: Monday, February 04, 2013 9:30 PM To: Bastian Offermann Cc: r-sig-finance@r-project.org Subject: Re: [R-SIG-Finance] 4-digit SIC codes I'm not sure, but here's a really quick and dirty way to get it library(XML) x - readHTMLTable(http://www.sec.gov/info/edgar/siccodes.htm;, stringsAsFactors=FALSE)[[4]] colnames(x) - x[2, ] SIC - x[-c(1:3), ] head(SIC) SICCode A/D OfficeIndustry Title 4 100 5 AGRICULTURAL PRODUCTION-CROPS 5 200 5 AGRICULTURAL PROD-LIVESTOCK ANIMAL SPECIALTIES 6 700 5 AGRICULTURAL SERVICES 7 800 5 FORESTRY 8 900 5 FISHING, HUNTING AND TRAPPING 91000 9 METAL MINING SIC[SIC$SICCode == 2834, ] SICCode A/D Office Industry Title 912834 1 PHARMACEUTICAL PREPARATIONS HTH, Garrett On Mon, Feb 4, 2013 at 9:19 PM, Bastian Offermann bastian250...@yahoo.co.uk wrote: Hi, does anybody know whether 4-digit SIC codes are available in R? Something along the lines 2834 Pharmaceutical Preparations Thank you. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. This e-mail and any materials attached hereto, including, without limitation, all content hereof and thereof (collectively, XR Content) are confidential and proprietary to XR Trading, LLC (XR) and/or its affiliates, and are protected by intellectual property laws. Without the prior written consent of XR, the XR Content may not (i) be disclosed to any third party or (ii) be reproduced or otherwise used by anyone other than current employees of XR or its affiliates, on behalf of XR or its affiliates. THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY KIND. TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE. On Tue, Feb 5, 2013 at 8:20 AM, David Reiner david.rei...@xrtrading.com wrote
Re: [R-SIG-Finance] 4-digit SIC codes
I'm not sure, but here's a really quick and dirty way to get it library(XML) x - readHTMLTable(http://www.sec.gov/info/edgar/siccodes.htm;, stringsAsFactors=FALSE)[[4]] colnames(x) - x[2, ] SIC - x[-c(1:3), ] head(SIC) SICCode A/D OfficeIndustry Title 4 100 5 AGRICULTURAL PRODUCTION-CROPS 5 200 5 AGRICULTURAL PROD-LIVESTOCK ANIMAL SPECIALTIES 6 700 5 AGRICULTURAL SERVICES 7 800 5 FORESTRY 8 900 5 FISHING, HUNTING AND TRAPPING 91000 9 METAL MINING SIC[SIC$SICCode == 2834, ] SICCode A/D Office Industry Title 912834 1 PHARMACEUTICAL PREPARATIONS HTH, Garrett On Mon, Feb 4, 2013 at 9:19 PM, Bastian Offermann bastian250...@yahoo.co.uk wrote: Hi, does anybody know whether 4-digit SIC codes are available in R? Something along the lines 2834 Pharmaceutical Preparations Thank you. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Fitting RSLN models
Looks like the code has been removed in Rev. 8. You can still get Rev. 7, but since the author removed the code, maybe you don't want it afterall? svn checkout svn://svn.r-forge.r-project.org/svnroot/rsln/@7 If the above line doesn't make sense, see http://stackoverflow.com/questions/11105131/cannot-install-r-forge-package-using-install-packages/11105132#11105132 Garrett On Fri, Jan 11, 2013 at 1:50 PM, jaimie villanueva jaimie.villanu...@gmail.com wrote: Fitting RSLN [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Fitting RSLN models
Sorry for the html, I'm having a hell of a time getting gmail to consistently send plain text. Looks like the code has been removed in Rev. 8. You can still get Rev. 7, but since the author removed the code, maybe you don't want it afterall? svn checkout svn://svn.r-forge.r-project.org/svnroot/rsln/@7 If the above line doesn't make sense, see http://stackoverflow.com/questions/11105131/cannot-install-r-forge-package-using-install-packages/11105132#11105132 Garrett On Fri, Jan 11, 2013 at 1:56 PM, G See gsee...@gmail.com wrote: Looks like the code has been removed in Rev. 8. You can still get Rev. 7, but since the author removed the code, maybe you don't want it afterall? svn checkout svn://svn.r-forge.r-project.org/svnroot/rsln/@7 If the above line doesn't make sense, see http://stackoverflow.com/questions/11105131/cannot-install-r-forge-package-using-install-packages/11105132#11105132 Garrett On Fri, Jan 11, 2013 at 1:50 PM, jaimie villanueva jaimie.villanu...@gmail.com wrote: Fitting RSLN ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Installed quantstrat along with blotter and FinancialInstrument but seems I'm missing .instrument
The .instrument environment is now stored in the FinancialInstrument NAMESPACE. .instrument is now FinancialInstrument:::.instrument I don't know what the rest of the pdf does, so I'm not sure what's keeping you from following through. I suppose you could do this assignment .instrument - FinancialInstrument:::.instrument I'd guess that will make things work for you since environments are by reference, but it's probably necessary. What specifically is holding you back? Garrett On Wed, Jan 2, 2013 at 7:50 PM, rquantnoob kpomichow...@gmail.com wrote: I'm following quantstrat-I.pdf by Guy Yollin to learn the language. But it seems the .instrument does not load for me as it does in the .pdf. Installing quanstrat, installed 3 packages, blotter,financialinstrument and quantstrat. .PDF example R Code: ls(all=T) [1] .blotter .instrument ___ Mine. ls(all=T) [1] .blotter Since I'm missing .instrument it isn't allowing me to follow through with the next step. The installation seemed to have gone through fine, please help. Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Installed-quantstrat-along-with-blotter-and-FinancialInstrument-but-seems-I-m-missing-instrument-tp4654469.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Installed quantstrat along with blotter and FinancialInstrument but seems I'm missing .instrument
I mean it's probably NOT necessary to assign it to your workspace. On Wed, Jan 2, 2013 at 8:04 PM, G See gsee...@gmail.com wrote: The .instrument environment is now stored in the FinancialInstrument NAMESPACE. .instrument is now FinancialInstrument:::.instrument I don't know what the rest of the pdf does, so I'm not sure what's keeping you from following through. I suppose you could do this assignment .instrument - FinancialInstrument:::.instrument I'd guess that will make things work for you since environments are by reference, but it's probably necessary. What specifically is holding you back? Garrett On Wed, Jan 2, 2013 at 7:50 PM, rquantnoob kpomichow...@gmail.com wrote: I'm following quantstrat-I.pdf by Guy Yollin to learn the language. But it seems the .instrument does not load for me as it does in the .pdf. Installing quanstrat, installed 3 packages, blotter,financialinstrument and quantstrat. .PDF example R Code: ls(all=T) [1] .blotter .instrument ___ Mine. ls(all=T) [1] .blotter Since I'm missing .instrument it isn't allowing me to follow through with the next step. The installation seemed to have gone through fine, please help. Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Installed-quantstrat-along-with-blotter-and-FinancialInstrument-but-seems-I-m-missing-instrument-tp4654469.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Installed quantstrat along with blotter and FinancialInstrument but seems I'm missing .instrument
getInstrument(USD) primary_id :USD currency :USD multiplier :1 tick_size :0.01 identifiers: list() type :currency Please have a look at the demo directory of the package. Best, Garrett On Wed, Jan 2, 2013 at 8:08 PM, rquantnoob kpomichow...@gmail.com wrote: First, thank you for taking your time to reply to my message. Here is the next step that perhaps will shed light on what's happening. currency(USD) [1] USD get(USD,envir=.instrument) Error in get(USD, envir = .instrument) : object '.instrument' not found -- View this message in context: http://r.789695.n4.nabble.com/Installed-quantstrat-along-with-blotter-and-FinancialInstrument-but-seems-I-m-missing-instrument-tp4654469p4654475.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Installed quantstrat along with blotter and FinancialInstrument but seems I'm missing .instrument
If you specifically want to use get get(USD, envir=FinancialInstrument:::.instrument) primary_id :USD currency :USD multiplier :1 tick_size :0.01 identifiers: list() type :currency or, I think this works too .instrument - FinancialInstrument:::.instrument get(USD, envir=.instrument) primary_id :USD currency :USD multiplier :1 tick_size :0.01 identifiers: list() type :currency Garrett On Wed, Jan 2, 2013 at 8:11 PM, G See gsee...@gmail.com wrote: getInstrument(USD) primary_id :USD currency :USD multiplier :1 tick_size :0.01 identifiers: list() type :currency Please have a look at the demo directory of the package. Best, Garrett On Wed, Jan 2, 2013 at 8:08 PM, rquantnoob kpomichow...@gmail.com wrote: First, thank you for taking your time to reply to my message. Here is the next step that perhaps will shed light on what's happening. currency(USD) [1] USD get(USD,envir=.instrument) Error in get(USD, envir = .instrument) : object '.instrument' not found -- View this message in context: http://r.789695.n4.nabble.com/Installed-quantstrat-along-with-blotter-and-FinancialInstrument-but-seems-I-m-missing-instrument-tp4654469p4654475.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Futures data
If you just want daily data, there is a script in the parser directory of FinancialInstrument (http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/FinancialInstrument/inst/parser/download.tblox.R?root=blotter) that will download free data since 1995 from tradingblox. Try this, library(FinancialInstrument) source(paste0(http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/;, FinancialInstrument/inst/parser/download.tblox.R?root=blotter)) define_futures.tblox() # define meta data for available futures -- not required to get data buildHierarchy(ls_futures(), description) # show the descriptions of available futures find.instrument(Eurodollar) getInstrument(ED) # this getSymbols.tblox method will download all data from tblox, but will only # assign the symbols you give it. getSymbols(ED, src='tblox') tail(ED) # this will download all tblox futures data and assign in your globalenv() get_tblox() tail(TY) head(CL) HTH, Garrett On Sat, Dec 15, 2012 at 9:39 PM, Robert A'gata rhelp...@gmail.com wrote: Eurodollar, treasury, SP500 e-mini, crude oil, natural gas, agricultural ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Futures data
Also, for daily VIX futures data, there's a getSymbols.cfe method in my qmao package on R-Forge # install.packages(qmao, repos=http://r-forge.r-project.org;) library(qmao) getSymbols(VX, src='cfe', Months=1:12, Years=2011:2012) Garrett On Sat, Dec 15, 2012 at 10:03 PM, G See gsee...@gmail.com wrote: If you just want daily data, there is a script in the parser directory of FinancialInstrument (http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/FinancialInstrument/inst/parser/download.tblox.R?root=blotter) that will download free data since 1995 from tradingblox. Try this, library(FinancialInstrument) source(paste0(http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/;, FinancialInstrument/inst/parser/download.tblox.R?root=blotter)) define_futures.tblox() # define meta data for available futures -- not required to get data buildHierarchy(ls_futures(), description) # show the descriptions of available futures find.instrument(Eurodollar) getInstrument(ED) # this getSymbols.tblox method will download all data from tblox, but will only # assign the symbols you give it. getSymbols(ED, src='tblox') tail(ED) # this will download all tblox futures data and assign in your globalenv() get_tblox() tail(TY) head(CL) HTH, Garrett On Sat, Dec 15, 2012 at 9:39 PM, Robert A'gata rhelp...@gmail.com wrote: Eurodollar, treasury, SP500 e-mini, crude oil, natural gas, agricultural ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Futures data
Chinmay, The trading blox data has a column called Unadjusted close. The user is free to use that column. Also, it is trivial to un-adjust the Open, High, and Low as well. And, there is a column showing which contract is being used for each row which makes it trivial to re-adjust prices however you see fit, or not at all. Garrett On Sat, Dec 15, 2012 at 10:13 PM, Chinmay Patil chinmay.pa...@gmail.com wrote: Hi Garret, Although a good solution, I would insist user to be careful with downloading data from TradingBlox. Any futures strategy backtesting especially on higher timeframes like daily and above will be very sensitive to method of construction of continous contract and if user is not aware of how such a continuos contract is created, they may lead themselves to reaching overly optimistic conclusions from that backtesting. TradingBlox data while good (they source the data CSIdata as well) is a continuous contract based on their rolling methodology and may not suite every user. Best Regards, Chinmay Patil On Sun, Dec 16, 2012 at 12:03 PM, G See gsee...@gmail.com wrote: If you just want daily data, there is a script in the parser directory of FinancialInstrument (http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/FinancialInstrument/inst/parser/download.tblox.R?root=blotter) that will download free data since 1995 from tradingblox. Try this, library(FinancialInstrument) source(paste0(http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/;, FinancialInstrument/inst/parser/download.tblox.R?root=blotter)) define_futures.tblox() # define meta data for available futures -- not required to get data buildHierarchy(ls_futures(), description) # show the descriptions of available futures find.instrument(Eurodollar) getInstrument(ED) # this getSymbols.tblox method will download all data from tblox, but will only # assign the symbols you give it. getSymbols(ED, src='tblox') tail(ED) # this will download all tblox futures data and assign in your globalenv() get_tblox() tail(TY) head(CL) HTH, Garrett On Sat, Dec 15, 2012 at 9:39 PM, Robert A'gata rhelp...@gmail.com wrote: Eurodollar, treasury, SP500 e-mini, crude oil, natural gas, agricultural ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Futures data
Robert, If you have an Interactive Brokers account -- which isn't free, but pretty close to it -- you can get a year's worth of intraday data for most futures with the IBrokers package (on CRAN). See ?reqHistoricalData. I also have some wrappers for IBrokers functions for getting lots of data from Interactive Brokers in my twsInstrument package on R-Forge. https://r-forge.r-project.org/R/?group_id=1113 (see ?reqTBBOhistory) IB offers 1 second bars, but if you want to get a meaningful amount of history, you're best off getting 1 minute bars because of their historical data request pacing rules. HTH, Garrett On Sat, Dec 15, 2012 at 9:39 PM, Robert A'gata rhelp...@gmail.com wrote: Hi, I am wondering if there is any source that one can download futures data such as Eurodollar, treasury, SP500 e-mini, crude oil, natural gas, agricultural, etc? Especially downloading from R. Of course, not bloomberg. Thank you. Robert [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Combining instrument data into one xts
A common way to do this is to store your data in its own environment. Then, use eapply to get a list of close prices. Finally, construct a merge call with do.call s - c(SPY, AAPL) myEnv - new.env() getSymbols(s, src='yahoo', env=myEnv) p - do.call(merge, eapply(myEnv, Cl)) this is like calling merge(Cl(SPY), Cl(AAPL)), but it will work for any number of symbols. Similarly, if your data are stored in your globalenv(), you can create a list of Close prices and merge them together using do.call. s - c(SPY, AAPL) getSymbols(s, src=yahoo) p - do.call(merge, lapply(s, function(x) Cl(get(x, pos=globalenv() I also happen to have a function that does this for you in one line in my qmao package on R-Forge. https://r-forge.r-project.org/R/?group_id=1113 library(qmao) p - PF(getSymbols(c(SPY, AAPL)), silent=TRUE) HTH, Garrett On Sat, Dec 15, 2012 at 11:06 PM, Robert A'gata rhelp...@gmail.com wrote: Hi, 1) When I call getSymbols with multiple symbols, is there any way I can obtain everything into one xts. Says, I want only close data from google for c(SPY,AAPL). Is there anyway I can get an xts with 2 columns corresponding to SPY and AAPL close prices? 2) Similar to #1, if I have all symbols loaded from files (.RData), is there any better way to combiing them than merging them one-by-one using xts? Thank you. Robert [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
[R-SIG-Finance] Introducing TFX: An R Interface to the TrueFX Web API
Hello all, I'd like to introduce the TFX package which I recently published to CRAN. It is a simple R interface to the free TrueFX Web API. You can use it to get real-time quotes with millisecond resolution and fractional-pip bid/ask spreads for 26 currency pairs. There is an RPub overview of the TFX package available here: http://rpubs.com/gsee/TFX The shiny package (http://www.rstudio.com/shiny/) has made the TFX package more relevant (at least to me). You can see a demo of using TFX with shiny by running the following code which will open a browser window and display FX quotes that update every 750 milliseconds: # install.packages('shiny', repos=c('http://rstudio.org/_packages', # getOption('repos')) library(shiny) runGist(4122626) #-- The code for the above shiny app can be viewed or downloaded from https://gist.github.com/4122626 I've also had a little bit of success creating real-time streaming charts using svSockets, following the video ( http://www.youtube.com/watch?v=rvT8XThGA8o) on the data.table homepage ( http://datatable.r-forge.r-project.org/) as a template and using TFX as the data source. Finally, TrueFX provides historical tick data for 15 currency pairs going back to May 2009 (http://truefx.com/?page=downloads). There is a script in the inst/parser directory of the FinancialInstrument package ( www.tinyurl.com/DownloadTrueFX) that can be used to download all of that data to disk in a format that FinancialInstrument::getSymbols.FI can easily read. This script is not intended to be used on Windows. I have no affiliation with TrueFX. Hope it's useful, Garrett P.S. The RPub (http://rpubs.com/gsee/TFX) is also included as a vignette in the R-Forge version (installable with install.packages(TFX, repos= http://r-forge.r-project.org;). As outlined in the NEWS file, the only updates in the R-Forge version are aesthetic: there are better error messages, a print.TFXsession method, and Reconnect and Disconnect no longer print the returned TFXsession object. [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Introducing TFX: An R Interface to the TrueFX Web API
Aw. That's a shame. What version of shiny and websockets are you using? Maybe try: devtools::install_github('shiny', 'rstudio') It works for me on linux with the following sessionInfo sessionInfo() R version 2.15.2 (2012-10-26) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] bitops_1.0-4.1 TFX_0.1.1 shiny_0.1.12 loaded via a namespace (and not attached): [1] caTools_1.13 digest_0.6.0 RJSONIO_1.0-1tools_2.15.2 [5] websockets_1.1.6 XML_3.95-0.1 xtable_1.7-0 Garrett On Mon, Dec 3, 2012 at 10:33 AM, Dennis Lee dennis...@yahoo.com.au wrote: I copied and pasted the code for Shiny app, but it doesn't update the FX quotes every 750 ms. I tried it on Firefox and Chrome. From: G See gsee...@gmail.com To: r-sig-finance r-sig-finance@r-project.org Sent: Monday, 3 December 2012 8:57 PM Subject: [R-SIG-Finance] Introducing TFX: An R Interface to the TrueFX Web API [sorry for the previous HTML e-mail. Gmail seems to think that's what I meant to do] Hello all, I'd like to introduce the TFX package which I recently published to CRAN. It is a simple R interface to the free TrueFX Web API. You can use it to get real-time quotes with millisecond resolution and fractional-pip bid/ask spreads for 26 currency pairs. There is an RPub overview of the TFX package available here: http://rpubs.com/gsee/TFX The shiny package (http://www.rstudio.com/shiny/) has made the TFX package more relevant (at least to me). You can see a demo of using TFX with shiny by running the following code which will open a browser window and display FX quotes that update every 750 milliseconds: # install.packages('shiny', repos=c('http://rstudio.org/_packages', # getOption('repos')) library(shiny) runGist(4122626) #-- The code for the above shiny app can be viewed or downloaded from https://gist.github.com/4122626 I've also had a little bit of success creating real-time streaming charts using svSockets, following the video (http://www.youtube.com/watch?v=rvT8XThGA8o) on the data.table homepage (http://datatable.r-forge.r-project.org/) as a template and using TFX as the data source. Finally, TrueFX provides historical tick data for 15 currency pairs going back to May 2009 (http://truefx.com/?page=downloads). There is a script in the inst/parser directory of the FinancialInstrument package (www.tinyurl.com/DownloadTrueFX) that can be used to download all of that data to disk in a format that FinancialInstrument::getSymbols.FI can easily read. This script is not intended to be used on Windows. I have no affiliation with TrueFX. Hope it's useful, Garrett P.S. The RPub (http://rpubs.com/gsee/TFX) is also included as a vignette in the R-Forge version (installable with install.packages(TFX, repos=http://r-forge.r-project.org;). As outlined in the NEWS file, the only updates in the R-Forge version are aesthetic: there are better error messages, a print.TFXsession method, and Reconnect and Disconnect no longer print the returned TFXsession object. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Introducing TFX: An R Interface to the TrueFX Web API
I just tried it on Windows and it works for me with the sessionInfo below. Are you sure you have at least version 1.1.6 of websockets? sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252LC_MONETARY=English_United States.1252 LC_NUMERIC=C LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] bitops_1.0-5 TFX_0.1.0shiny_0.2.3 loaded via a namespace (and not attached): [1] caTools_1.13 digest_0.5.2 RJSONIO_1.0-1tools_2.15.1 websockets_1.1.6 XML_3.9-4.1 xtable_1.7-0 Garrett On Mon, Dec 3, 2012 at 11:09 AM, Jeff Ryan jeff.a.r...@gmail.com wrote: If the backend is using websockets, that is very new ground in the land of HTML. M$ prides itself typically on being off by a decade w.r.t. adoption of such 'shiny' things. So... that may indeed be your issue. Jeff On Mon, Dec 3, 2012 at 11:05 AM, Dennis Lee dennis...@yahoo.com.au wrote: I am running it on Windows, maybe you didn't understand what I said. I did get the first quote displayed correctly, so it is not because of the library. My problem is that it doesn't update periodically. I will try to figure it out when I have time, just too late now (its past midnight here) to solve this. sessionInfo() R version 2.15.1 (2012-06-22) Platform: i386-pc-mingw32/i386 (32-bit) It could be because of my R version (maybe not), but then again I have installed the CRAN version of shiny (and not the dev version on Github). From: Dirk Eddelbuettel e...@debian.org Cc: r-sig-finance r-sig-finance@r-project.org Sent: Tuesday, 4 December 2012 12:56 AM Subject: Re: [R-SIG-Finance] Introducing TFX: An R Interface to the TrueFX Web API On 3 December 2012 at 08:33, Dennis Lee wrote: | I copied and pasted the code for Shiny app, but it doesn't update the FX quotes | every 750 ms. I tried it on Firefox and Chrome. I copied and paste ? Maybe you did that the wrong way? What happens when you install the shiny and TFX packages, and execute library(shiny) runGist(4122626) which has been very reliable for me on different machine (home/work/netbook/...) ? Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. -- Jeffrey Ryan jeffrey.r...@lemnica.com www.lemnica.com [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Introducing TFX: An R Interface to the TrueFX Web API
On Mon, Dec 3, 2012 at 11:28 AM, Dennis Lee dennis...@yahoo.com.au wrote: I did get this warning when I ran the code: runGist(4122626) Loading required package: TFX Warning: package ‘TFX’ was built under R version 2.15.2 I have checked websockets: loaded via a namespace (and not attached): [1] bitops_1.0-5 caTools_1.13 devtools_0.8 [4] digest_0.6.0 evaluate_0.4.2 httr_0.2 [7] memoise_0.1 parallel_2.15.1 plyr_1.7.1 [10] RCurl_1.95-3 RJSONIO_1.0-1stringr_0.6.1 [13] tools_2.15.1 websockets_1.1.6 whisker_0.1 [16] xtable_1.7-0 I have checked pause updates: Pause updates This should be UNchecked! So, Windows is not the issue, I have to update R to version 2.15.2 then seems logical to me. But, I ran it on R 2.15.1 and it worked fine. See my sessionInfo in the previous message. So, I'm not sure what's not working for you. Maybe some local security settings? Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
[R-SIG-Finance] chart_Series with knitr markdown
I'm having trouble getting chart_Series to render properly with markdown to html. Are others using chart_Series with markdown? What am I doing wrong? The Pub at this link should be self explanatory: http://rpubs.com/gsee/chart_Series_knit The .Rmd file used to produce it is below. Thanks, Garrett Why doesn't chart_Series look right? ```{r message=FALSE} library(quantmod) getSymbols(SPY, src='yahoo') ``` This looks fine ```{r fig.width=7, fig.height=6} chartSeries(SPY) ``` But, why does this look wrong? i.e. instead of being aligned at the left margin, there is a box with a question mark. ```{r fig.width=7, fig.height=6} chart_Series(SPY) ``` [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] xtsExtra
You've typed source instead of repos Try this: install.packages(xtsExtra, repos=http://r-forge.r-project.org;) HTH, Garrett On Sat, Nov 17, 2012 at 5:53 PM, Eric Thungstom eric.thungst...@gmail.comwrote: Getting this message when I try to install xtsExtra. install.packages('xtsExtra', source = http://r-forge.r-project.org;) Installing package(s) into C:/PROGRA~1/R/R-212~1.0/library (as lib is unspecified) Warning in install.packages : package xtsExtra is not available Is there a problem with this package to where it's no longer available ? [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] [R] (no subject)
Manasvi, Did you add 127.0.0.1 to Trusted IP Addresses? -Garrett On Fri, Nov 9, 2012 at 8:39 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Forwarding to the relevant list. MW On Fri, Nov 9, 2012 at 9:01 AM, Manasvi Dobhal manasvidob...@gmail.com wrote: Hi all, The TWS on my system is unable to connect to my R session. Here is the error that I'm getting: * tws-twsConnect() Error in socketConnection(host = host, port = port, open = ab, blocking = blocking) : cannot open the connection In addition: Warning message: In socketConnection(host = host, port = port, open = ab, blocking = blocking) : localhost:7496 cannot be opened* Here is the session info for the R session: *R version 2.15.1 (2012-06-22)* ** *Platform: x86_64-pc-linux-gnu (64-bit)* ** *locale:* * [1] LC_CTYPE=en_IN.UTF-8LC_NUMERIC=C* * [3] LC_TIME=en_IN.UTF-8LC_COLLATE=en_IN.UTF-8* * [5] LC_MONETARY=en_IN.UTF-8LC_MESSAGES=en_IN.UTF-8* * [7] LC_PAPER=CLC_NAME=C* * [9] LC_ADDRESS=CLC_TELEPHONE=C* *[11] LC_MEASUREMENT=en_IN.UTF-8 LC_IDENTIFICATION=C* * * *attached base packages:* *[1] statsgraphicsgrDevices utilsdatasets * *[6] methodsbase* * * *other attached packages:* *[1] IBrokers_0.9-10 xts_0.8-6zoo_1.7-8* * * *loaded via a namespace (and not attached):* *[1] grid_2.15.1lattice_0.20-0 tools_2.15.1* ** I have checked the Enable Activex and Socket clients but it hasn't helped. Since I'm running on an Ubuntu machine, I even tried changing the parameter *blocking *in the command *twsConnect() *to 1. *blocking = FALSE* 2. According to the one mentioned here http://code.google.com/p/ibrokers/source/detail?r=84path=/trunk/R/twsConnect.R but nothing has helped. Please let me know what I should do. Thanks. [[alternative HTML version deleted]] __ r-h...@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. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] [R-SIG-FINANCE] Low Priority - market component list and general coding help
Hi Martin, comments in-line. On Fri, Oct 26, 2012 at 2:01 PM, Martin Jenkins mje...@yahoo.com wrote: Hi, I've searched around and not found anything to help on this, even though it's not the first time it's been asked, so was wondering if anyone had any new ideas. I really like the device output of the chartSeries function and so have used it to output a bitmap of the stock chart. What I'm using it for is to get an entire market index component list, however to get that I've had to create my own flat file called masterlist.csv in the below code. Ideally I'd like to have a function do the same job so I don't have to create the file manually. This way I can quickly and easily get graphs for an entire stock market. Rather frustratingly Yahoo! have stopped allowing the component list for an index to be downloaded. If you just want a list of most stocks, use TTR::stockSymbols() R head(stockSymbols()$Symbol) Fetching AMEX symbols... Fetching NASDAQ symbols... Fetching NYSE symbols... [1] AA-P AAU ACU ACY ADGE ADK If the holdings of ETFs will suffice, you can use getHoldings from my qmao package on R-Forge (https://r-forge.r-project.org/R/?group_id=1113) R #install.packages(qmao, repos='http://r-forge.r-project.org') R library(qmao) R rownames(getHoldings(SPY, auto.assign=FALSE)) If you want components of specific indexes, you might look through the code from systematic investor https://github.com/systematicinvestor/SIT/blob/master/R/data.r I haven't used any of that code, but the file I linked to above appears to get the Symbols of stocks for different indexes. Also as you can see my coding skills are restricted by my procedural background, so whilst the below works fine, I'm sure it can be written more efficiently. One last thing, I'm using the auto.assign = FALSE so that I can use a variable in chartseries, this leaves me with the name of my variable, in this case 'x', on the bitmap, which isn't ideal, meaning I have to refer to the filename for the epic. You can simply provide a name argument to chartSeries() R s - AAPL R chartSeries(getSymbols(s, src='google', auto.assign=FALSE), name=s) Just curious, why use src='google' ? I've found yahoo's data to be slightly more reliable. HTH, Garrett Many thanks, Martin library(quantmod) masterfile - C:/Users/Admin/Documents/Programming/R/current/FTSE100/masterlist.csv path - C:/Users/Admin/Documents/Programming/R/ftse100bmps/ epicstable - read.table(masterfile, header=FALSE, sep=,) i - 1 while(is.na(epicstable$V1[i]) == FALSE) { epic_char - as.character(epicstable$V1[i]) x - try(getSymbols(epic_char, auto.assign=FALSE)) if (length(x)==1) { x - try(getSymbols(epic_char, src = google, auto.assign=FALSE)) } if (length(x) 1) { outputfile - paste(path, epicstable$V1[i], '.bmp') chartSeries(x,subset='2011-01::2012',TA=addVo();addMACD()) bmp(file=outputfile, bg = transparent, width = 1024, height = 768) dev.off() } i = i + 1 } [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Slow data EOD
And Jeff's already provided a quoteFormat (which I had forgotten about) so that you don't have to rearrange columns. getQuote(SPY, what=yahooQuote.EOD) Trade Time Open HighLow CloseVolume SPY 2012-10-12 04:00:00 143.46 143.95 142.58 142.89 124181904 On Tue, Oct 9, 2012 at 12:04 PM, Ralph Vince rvinc...@gmail.com wrote: Ah, okthen I can create a function to perhaps append it onto the file I am downloading entirely end of day or something like that. On Tue, Oct 9, 2012 at 1:02 PM, G See gsee...@gmail.com wrote: On Tue, Oct 9, 2012 at 11:58 AM, Ralph Vince rvinc...@gmail.com wrote: Thanks Garrett, Im really just looking for timely end-of-day data on this though. Ralph For example, getQuote(SPY), will return end of day data if you call it late in the afternoon ;-) ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Optimx help
Please don't crosspost. Ask other guy for clarification, not us. On Wed, Oct 10, 2012 at 10:37 AM, nserdar snes1...@hotmail.com wrote: I do not understand what other guy mentioned about my problem. So I asked in this part. Please explain other guy opinion about my problem. Regards, Serdar -- View this message in context: http://r.789695.n4.nabble.com/Optimx-help-tp4645666p4645723.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Slow data EOD
Hi Ralph, You can get real time intraday data from yahoo or google: http://www.quantshare.com/sa-426-6-ways-to-download-free-intraday-and-tick-data-for-the-us-stock-market Or you can get delayed data with quantmod::getQuote. Maybe that will work better for you. I'm not sure about your particular issue, but one of the issues with yahoo's daily data is that sometimes it has duplicate timestamps (and different volume) for the most recent observation. HTH, Garrett On Tue, Oct 9, 2012 at 11:26 AM, Ralph Vince rvinc...@gmail.com wrote: I'm downloading certain equity data from yahoo on an eod basis, using the code, below. It works wonderfully, formatting the data and dates precisely as I am looking for EXCEPT often the data is late. Often, the latest market day's data is not up until 10, 11 pm that night. Is there something I am doing wrong here? Surely, yahoo must have the data by the close. is the way I am invoking calling the file, below, causing this? Or is there a way to obtain it from google earlier? I;d be very grateful for any help along these lines. Ralph Vince require(quantmod) library(plan) brsym - c( AAPL, ABT, ... WMT, XOM ); for (i in 1:length(brsym)) { tryCatch({ j - paste(http://table.finance.yahoo.com/table.csv?s=,brsym[[i]],sep=;); j - paste(j,g=dignore=.csv,sep=); print(j); X - read.csv(j, header=TRUE); # Convert the Date column from a factor class to a Date class X$Date - as.Date(X$Date) # Sort the X object by the Date column -- order(-X$Date) will sort it in the other direction X - X[order(X$Date),] # Format the date column as you want X$Date - format(as.Date(X$Date),%Y%m%d); X - X[,1:6] kk - trim.whitespace(brsym[[i]]); k - paste(/home/oracle/broadbaseddata/, kk, sep=); k - trim.whitespace(k); k - paste(k,.csv, sep=); write.table(X, k, append = FALSE, quote = FALSE, sep = ,, eol = \n, na = NA, dec = ., row.names = FALSE, col.names = FALSE, qmethod = c(escape, double)); print(k); ko - paste(X$Date[1], -,X$Date[length(X$Date)]); print(ko); }, interrupt = function(ex) { cat(An interrupt was detected.\n); print(ex); }, error = function(ex) { cat(An error was detected.\n); print(ex); }, finally = { cat(done\n); }) } ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Slow data EOD
On Tue, Oct 9, 2012 at 11:58 AM, Ralph Vince rvinc...@gmail.com wrote: Thanks Garrett, Im really just looking for timely end-of-day data on this though. Ralph For example, getQuote(SPY), will return end of day data if you call it late in the afternoon ;-) ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] PerformanceAnalytics seems to break rollapply
There should be a GIANT WARNING when loading PerformanceAnalytics to let users know that their code will no longer be reproducible. The problem comes from the zzz.R that does these nasty things: mean.xts - function(x,...) { if(is.vector(x) ||is.null(ncol(x)) || ncol(x)==1){ x-as.numeric(x) mean(x,...) } else apply(x,2,mean.xts,...) } mean.matrix - function(x,...) {apply(x,2,mean,...)} sd.xts - function(x,na.rm=FALSE) { if(is.vector(x) || is.null(ncol(x)) || ncol(x)==1){ x-as.numeric(x) sd(x,na.rm=na.rm) } else apply(x,2,sd,na.rm=na.rm) } sd.matrix - function(x,na.rm=FALSE) {apply(x,2,sd,na.rm=na.rm)} rollapply.xts - xts:::rollapply.xts HTH, Garrett On Fri, Oct 5, 2012 at 2:04 PM, Bos, Roger roger@rothschild.com wrote: Unless I am making a user error, it seems that rollapply stops working with some functions after the PerformanceAnalytics packages has been loaded. I provide reproducible code below: test - xts(1:10, order.by=Sys.time()+(1:10)) w - function(x) { z - scale(x) attributes(z) - NULL z } rollapply(data=test, width=3, FUN=mean) rollapply(data=test, width=3, FUN=scale) rollapply(data=test, width=3, FUN=w) require(PerformanceAnalytics) rollapply(data=test, width=3, FUN=mean) rollapply(data=test, width=3, FUN=scale) rollapply(data=test, width=3, FUN=w) The first three calls to rollapply work fine. Then once the PerformanceAnalytics packages had been loaded mean still works but scale does not. I suspect it is because of the attributes which scale creates, but I tried creating a function (called w) which removes the attributes, but rollapply still does not work. Here is the error I get: rollapply(data=test, width=3, FUN=w) Error in xts(xx, tt, if (by == 1) attr(data, frequency)) : NROW(x) must match length(order.by) Thanks for any help or advice you can provide! Roger J. Bos, CFA Rothschild Asset Management, Inc. Tel +1 (212) 403-5471 Email roger@rothschild.com 1251 Avenue of the Americas, NY, NY 10020 *** This message is for the named person's use only. It may\...{{dropped:11}} ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Problem with updatePortf
If by cannot debug that function you mean you can't find the source code, you can view the code with blotter:::.updatePosPL or getAnywhere(.updatePosPL) Or, your can checkout the code with svn to see a commented copy. svn checkout svn://svn.r-forge.r-project.org/svnroot/blotter/ and browse to the file pkg/blotter/R/updatePosPL.R Or, you can view it online at https://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/blotter/R/updatePosPL.R?root=blotter HTH, Garrett On Thu, Sep 20, 2012 at 9:10 PM, Worik Stanton worik.stan...@gmail.com wrote: Friends I am running into trouble with updatePortf. Stepping through it the problem is with the call to .updatePosPL, but I cannot debug that function. I am working on a small example that exhibits the problem but in the mean time is there a way I can debug .updatePosPL? cheers Worik -- it does not matter I think that I shall never see how much I dig and digA billboard lovely as a tree this hole just Indeed, unless the billboards fall keeps getting deeper I'll never see a tree at all ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Problem with updatePortf
getPrice looks for a price column and it only works if the xts object has colnames. getPrice(USDCHF) Error in getPrice(USDCHF) : subscript out of bounds, no price was discernible from the data You need to add colnames. colnames(USDCHF) - c(Bid, Ask, Last.Price) getPrice(USDCHF) Last.Price 2005-09-01 1.2343 2005-09-02 1.2280 2005-09-05 1.2335 2005-09-06 1.2365 2005-09-07 1.2426 2005-09-08 1.2449 2005-09-09 1.2442 2005-09-12 1.2592 2005-09-13 1.2619 2005-09-14 1.2585 2005-09-15 1.2671 2005-09-16 1.2687 2005-09-19 1.2772 2005-09-20 1.2809 2005-09-21 1.2718 2005-09-22 1.2795 2005-09-23 1.2916 2005-09-26 1.2896 2005-09-27 1.2959 2005-09-28 1.2940 Although getPrice is not documented, you can look at its code to see what it does. If you do not provide a value for the prefer argument, it looks for a column name that contains the word price. If it cannot find that, it looks for trade. Finally, it looks for close. If your colnames don't contain any of those words, or if you want to use a different column, you can specify that with the prefer argument getPrice(USDCHF, prefer=Bid) Bid 2005-09-01 1.2558 2005-09-02 1.2368 2005-09-05 1.2344 2005-09-06 1.2404 2005-09-07 1.2444 2005-09-08 1.2470 2005-09-09 1.2470 2005-09-12 1.2597 2005-09-13 1.2640 2005-09-14 1.2613 2005-09-15 1.2696 2005-09-16 1.2729 2005-09-19 1.2815 2005-09-20 1.2818 2005-09-21 1.2825 2005-09-22 1.2809 2005-09-23 1.2918 2005-09-26 1.2965 2005-09-27 1.2998 2005-09-28 1.2984 Garrett On Thu, Sep 20, 2012 at 9:30 PM, Worik Stanton worik.stan...@gmail.com wrote: On 21/09/12 14:10, Worik Stanton wrote: [snip] I am working on a small example that exhibits the problem but in the mean time is there a way I can debug .updatePosPL? So here is an example without transactions. I am a novice with blotter so tis example could probably be smaller. I have tried to distill what are the most important points (hence no transactions). When I run this I get... go() 2005-09-01 FOO Error in getPrice(get(Symbol, pos = env), symbol = symbol, prefer = prefer) : subscript out of bounds, no price was discernible from the data ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Trouble with getSymbols.csv
This function should really have more formal arguments -- especially the format argument. As it is, the `format` will be set to . You should be able to pass `format` through the dots, but there's a syntax bug preventing that from working (`list(...)[[format]] - NULL`). As it is, the only way to load your data using getSymbols.csv is to set the `format` argument in the Symbol Lookup table. (I saved the text from your e-mail in a file at ~/tmp/worik.txt) setSymbolLookup(worik=list(src='csv', format='%Y-%m-%d')) getSymbols('worik', dir='~/tmp', auto.assign=FALSE, extension='txt') WORIK.Open WORIK.High WORIK.Low WORIK.Close WORIK.Volume 2011-12-28 1.5968 1.59871.5762 1.58270 2011-12-29 1.5831 1.58461.5695 1.57240 2011-12-30 1.5726 1.58771.5704 1.58610 2011-12-31 1.5850 1.58611.5850 1.58610 2012-01-01 1.5850 1.58611.5820 1.58610 2012-01-02 1.5871 1.58751.5768 1.58020 2012-01-03 1.5800 1.58371.5726 1.58180 2012-01-04 1.5819 1.58651.5796 1.58130 2012-01-05 1.5812 1.58541.5730 1.57950 2012-01-06 1.5796 1.58711.5745 1.58590 2012-01-07 1.5854 1.58541.5782 1.57820 2012-01-08 1.5808 1.58661.5808 1.58660 2012-01-09 1.5867 1.59101.5807 1.58150 WORIK.Adjusted 2011-12-281.58745 2011-12-291.57705 2011-12-301.57905 2011-12-311.58555 2012-01-011.58405 2012-01-021.58215 2012-01-031.57815 2012-01-041.58305 2012-01-051.57920 2012-01-061.58080 2012-01-071.58180 2012-01-081.58370 2012-01-091.58585 HTH, Garrett On Mon, Sep 17, 2012 at 4:12 PM, Worik Stanton worik.stan...@gmail.com wrote: Friends I have a file of data: Date,Open,High,Low,Close,Volume,Adjusted 2011-12-28,1.5968,1.5987,1.5762,1.5827,0,1.58745 2011-12-29,1.5831,1.5846,1.5695,1.5724,0,1.57705 2011-12-30,1.5726,1.5877,1.5704,1.5861,0,1.57905 2011-12-31,1.585,1.5861,1.585,1.5861,0,1.58555 2012-01-01,1.585,1.5861,1.582,1.5861,0,1.58405 2012-01-02,1.5871,1.5875,1.5768,1.5802,0,1.58215 2012-01-03,1.58,1.5837,1.5726,1.5818,0,1.57815 2012-01-04,1.5819,1.5865,1.5796,1.5813,0,1.58305 2012-01-05,1.5812,1.5854,1.573,1.5795,0,1.5792 2012-01-06,1.5796,1.5871,1.5745,1.5859,0,1.5808 2012-01-07,1.5854,1.5854,1.5782,1.5782,0,1.5818 2012-01-08,1.5808,1.5866,1.5808,1.5866,0,1.5837 2012-01-09,1.5867,1.591,1.5807,1.5815,0,1.58585 When I use getSymbols(.., src=csv) The dates are incorrect. The first date is 2012-09-18 It seems that in getSymbols.csv uses: as.Date(fr[, 1], format = format, ..., origin = 1970-01-01) Looking more closely... as.Date(2011-12-28, origin=1970-01-01, format=) [1] 2012-09-18 That is what I see. But either of... as.Date(2011-12-28, origin=1970-01-01) [1] 2011-12-28 as.Date(2011-12-28) [1] 2011-12-28 give me what I expect. What am I doing wrong? cheers Worik -- it does not matter I think that I shall never see how much I dig and digA billboard lovely as a tree this hole just Indeed, unless the billboards fall keeps getting deeper I'll never see a tree at all ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Aggregating tick-by-tick data to seconds
You can use `period.apply` (along with `endpoints()`) to apply any function you like over non-overlapping time periods. In this case, you want to sum columns 2 and 3 separately, so use `period.apply()` with `FUN=colSums` on just the 2nd and 3rd columns. period.apply(test[, 2:3], endpoints(test, 'secs'), FUN=colSums) Then you can merge that with the results of `to.period` cbind(to.period(test[, 1], name=test), period.apply(test[, -1], endpoints(test, 'secs'), FUN=colSums)) test.Open test.High test.Low test.Close up down 2012-09-12 16:30:00144.39144.39 144.38 144.38 5903 100 You could also use `period.sum()` on each column separately. HTH, Garrett On Sat, Sep 15, 2012 at 10:57 AM, Costas Vorlow costas.vor...@gmail.com wrote: Hello, I have the following data (xts) (last two columns refer to up and down volumes). head(test,20) [,1] [,2] [,3] 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 5000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 4000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 1000 2012-09-12 16:30:00 144.39 9000 2012-09-12 16:30:00 144.39 2000 2012-09-12 16:30:00 144.39 1030 2012-09-12 16:30:00 144.39 1970 2012-09-12 16:30:00 144.39 2000 2012-09-12 16:30:00 144.39 5000 2012-09-12 16:30:00 144.39 4000 2012-09-12 16:30:00 144.39 1000 2012-09-12 16:30:00 144.39 5000 2012-09-12 16:30:00 144.39 3000 2012-09-12 16:30:00 144.39 2000 2012-09-12 16:30:00 144.39 1030 2012-09-12 16:30:00 144.380 100 I can use the to.period to aggregate the above data to seconds test.Open test.High test.Low test.Close 2012-09-12 16:30:00144.39144.47 144.37 144.38 2012-09-12 16:31:00144.39144.40 144.33 144.37 2012-09-12 16:32:00144.37144.45 144.37 144.45 2012-09-12 16:33:00144.45144.47 144.42 144.47 but I am not sure how to do this for the volume columns. I would need to retrieve the volume sums per second. Is this functionality built into the xts package? Is there any other function that could be used to do something like that? Thanks best regards, Costas ___ [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Equities Data
On Thu, Sep 6, 2012 at 8:02 AM, Ralph Vince rvinc...@gmail.com wrote: Thanks for the replies. I'm not looking for data adjusted for splits and dividends, but rather the ex-dates when the dividend or split will be affecting prices, and the amount of the dividends/ splits. It appears Yahoo finance might have this information, Im just not sure how, in R, to extract anything other than prices in R. Ralph Vince library(quantmod) ?getDividends ?getSplits ?adjRatios ?getQuote ?yahooQF That is much more on topic that can someone tell me where to get some data? ;-) Best, Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Equities Data
Also in quantmod, there is `getFinancials` if you want financial statements In qmao (https://r-forge.r-project.org/R/?group_id=1113), there's `getEarnings` which will give you historic analyst estimates and actual earnings numbers `getEarningsCalendar` will show you all stocks (U.S. and non-U.S.) that report earnings. It supports from and to arguments. `getDividendsCalendar` will show you all stocks that go Ex-Div today (although it also supports from and to if you want to see historic calendars) `getEconomicCalendar` shows the calendar of economic number releases `getMergersCalendar` shows mergers/acquisitions -Garrett On Thu, Sep 6, 2012 at 8:18 AM, Ralph Vince rvinc...@gmail.com wrote: Ah, thank you! It must be in the Quantmod API / Thank you. Ralph Vince On Thu, Sep 6, 2012 at 9:05 AM, G See gsee...@gmail.com wrote: On Thu, Sep 6, 2012 at 8:02 AM, Ralph Vince rvinc...@gmail.com wrote: Thanks for the replies. I'm not looking for data adjusted for splits and dividends, but rather the ex-dates when the dividend or split will be affecting prices, and the amount of the dividends/ splits. It appears Yahoo finance might have this information, Im just not sure how, in R, to extract anything other than prices in R. Ralph Vince library(quantmod) ?getDividends ?getSplits ?adjRatios ?getQuote ?yahooQF That is much more on topic that can someone tell me where to get some data? ;-) Best, Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Equities Data
That data is expensive, but your prime broker will probably provide it for free. Otherwise, qmao::getDividendsCalendar can do it, but it's inefficient. You'd have to get the dividends calendar for future dates, and look for your symbols. Keep in mind that the local symbol will be used even if the stock also trades in the U.S. (i.e. BMW.DE instead of BMW) Good luck, Garrett On Thu, Sep 6, 2012 at 10:45 AM, Ralph Vince rvinc...@gmail.com wrote: I don't think this is going to do what I'm trying to accomplish here, which is determine the next, future, pending ex-date for dividends or splits, if there is one announced, so that I can prepare the systems for this in advance. It seems to be an nasty problem and I'm trying to get out of maintaining this by hand! On Thu, Sep 6, 2012 at 9:05 AM, G See gsee...@gmail.com wrote: On Thu, Sep 6, 2012 at 8:02 AM, Ralph Vince rvinc...@gmail.com wrote: Thanks for the replies. I'm not looking for data adjusted for splits and dividends, but rather the ex-dates when the dividend or split will be affecting prices, and the amount of the dividends/ splits. It appears Yahoo finance might have this information, Im just not sure how, in R, to extract anything other than prices in R. Ralph Vince library(quantmod) ?getDividends ?getSplits ?adjRatios ?getQuote ?yahooQF That is much more on topic that can someone tell me where to get some data? ;-) Best, Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Equities Data
On Thu, Sep 6, 2012 at 12:56 PM, Ralph Vince rvinc...@gmail.com wrote: THis looks pretty good, and could be parsed -- I just wish they had it for cash dividends as well; http://biz.yahoo.com/c/s.html Ralph Vince They do. Please look at library(qmao) ?getDividendsCalendar I think I've mentioned this before... Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Equities Data
You should be able to install it with this command install.packages(qmao, repos=http://R-Forge.R-project.org;) If for some reason that does not work, see this link: http://stackoverflow.com/questions/11105131/cannot-install-r-forge-package-using-install-packages Garrett On Thu, Sep 6, 2012 at 6:31 PM, Ralph Vince rvinc...@gmail.com wrote: Garrett, this is really great. So I only need to get the latest qmao to do this? It's in CRAN? Ralph VInce On Thu, Sep 6, 2012 at 2:49 PM, G See gsee...@gmail.com wrote: I guess since you really only care about the future, this would be more appropriate sc - getSplitsCalendar(from='2012-09-05', to='2012-12-31') sc[sc$Symbol ==LKQ, ] PayableEx.Date Company Symbol Optionable. Ratio Announced 4 2012-09-18 2012-09-19 LKQLKQ Y 2-1 2012-08-17 On Thu, Sep 6, 2012 at 1:44 PM, G See gsee...@gmail.com wrote: That's not really how the website is setup. So, I don't think that's how the function should be setup by default. But, you can easily filter the results by Symbol. Here is the wrapper I mentioned. getSplitsCalendar - function(from, to) { qmao:::getCalendarByMonth(.getSplitsCalendar, from=from, to=to) } This allows you to get and merge several months of splits calendars. sc - getSplitsCalendar(from='2012-01-01', to='2012-08-31') Now you have the splits calendar from January to August. You can filter that by the symbol you care about. sc[sc$Symbol == ALK, ] PayableEx.DateCompany Symbol Optionable. Ratio Announced 52 2012-03-16 2012-03-19 Alaska AirALK Y 2-1 2012-02-16 Good enough? Garrett On Thu, Sep 6, 2012 at 1:34 PM, Ralph Vince rvinc...@gmail.com wrote: Garrett, This is great. Do you think it would be possible to pass in a given ticker to get that informatoin, rather than getting the whole gulp? Ralph Vince ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Performance Analytics Calendar Returns
On Wed, Sep 5, 2012 at 12:21 AM, Nikos Rachmanis nikos.rachma...@gmail.com wrote: However, I am trying to transform the daily returns of my PL (which also include gaps) to monthly and unfortunately the to.monthly does not work very well. i am currently trying table.TrailingPeriods and rollapply. Any other ideas or functions? ?apply.monthly apply.monthly(PnL, sum) -Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] blotter updatePortf issue..
Hi Pie, Thanks for providing reproducible code. I committed a patch in Rev. 1151 that I believe will fix your problem. If you need help checking out and building the latest revision, see this post on SO: http://stackoverflow.com/a/11105132/967840 Internally, the code was checking to see if Dates was timeBased. If it wasn't, it was being converted to a timeBased vector. But, later, the code was treating Dates as if it were not timeBased. Hopefully my patch fixes your problem and doesn't create others. There are a couple other things to mention. First, these lines are not going to work: updateAcct(account, Dates=paste('::',as.Date(Sys.time()),sep='')) updateEndEq(account, Dates=paste('::',as.Date(Sys.time()),sep='')) These functions do not support that type of Dates strings. You'll have to either use Dates=NULL, or supply both starting and ending dates like this: updateAcct(account, Dates=paste(initDate, as.Date(Sys.time()),sep='::') ) updateEndEq(account, Dates=paste(initDate, as.Date(Sys.time()),sep='::') ) Second, I didn't get these warnings that you got getSymbols(symbols, src='yahoo', index.class=c(POSIXt,POSIXct),from='2001-01-01') [1] QQQ IWM Warning messages: 1: In download.file(paste(yahoo.URL, s=, Symbols.name, a=, from.m, : downloaded length 147933 != reported length 200 2: In download.file(paste(yahoo.URL, s=, Symbols.name, a=, from.m, : downloaded length 147996 != reported length 200 I'm not sure why you get those warnings, but your version of quantmod is a little older than mine (the R-forge version). HTH, Garrett On Sun, Sep 2, 2012 at 11:27 PM, pie trader pietra...@gmail.com wrote: Hi, Currently I am stuck on an error with updatePortf function in blotter. The error message is same as the issue mentioned on R-sig-finance previously i.e., http://r.789695.n4.nabble.com/blotter-updatePortf-issues-tp4635933.html updatePortf(Portfolio=portfolio,Dates=paste('::',as.Date(Sys.time()),sep='')) Error in if (length(c(year, month, day, hour, min, sec)) == 6 c(year, : missing value where TRUE/FALSE needed In addition: Warning message: In as_numeric() : NAs introduced by coercion ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] FinancialInstrument functions output / side effect variables
Doug, I re-read your question. Let me clarify. Instruments are stored in an environment called .instrument at the top level of the package. You can see everything in that environment like this ls(FinancialInstrument:::.instrument) However, there are lots of functions show the primary_ids of instruments that do some checking to make sure that what is being shown are indeed primary_ids of instruments. e.g ls_stocks() ls_currencies() ls_instruments() Let me know if I can offer more clarity. Best, Garrett On Fri, Aug 24, 2012 at 11:44 AM, G See gsee...@gmail.com wrote: Hi Doug, You can use getInstrument to see the instruments e.g. stock(SPY, currency(USD)) getInstrument(USD) getInstrument(SPY) Please take a look at the files in the demo directory (https://r-forge.r-project.org/scm/viewvc.php/pkg/FinancialInstrument/demo/FIdemo2.R?view=markuproot=blotter) You'll also probably be interested in ?buildHierarchy build_series_symbols does nothing but return a character vector and it does not store it anywhere and it does not create any instruments. (I personally use future_id from the twsInstrument package to serve the purpose of build_series_symbols) HTH, Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Bug in chart.CumReturns (PerformanceAnalytics)
Peter, I agree that this is confusing. From ?Return.cumulative: geometric generate geometric (TRUE) or simple (FALSE) returns, default TRUE So, you use geometric=FALSE to create simple returns. Then you use geometric=TRUE if you want to chart them? Best, Garrett On Wed, Aug 22, 2012 at 4:08 PM, Peter Carl pe...@braverock.com wrote: Correct, if you have simple returns, set geometric=TRUE. pcc -- Peter Carl http://www.braverock.com/peter Call it what you want but for a simple (arithematic or geometric = FALSE) return, the equity curve should be cumprod(1+R) not cumsum(R). C. De : Peter Carl pe...@braverock.com À : Chris de Bleu blue2b...@yahoo.fr Cc : r-sig-finance@r-project.org r-sig-finance@r-project.org Envoyé le : Mercredi 22 août 2012 22h55 Objet : Re: [R-SIG-Finance] Bug in chart.CumReturns (PerformanceAnalytics) The arithmetic and geometric tags (indicated as geometric=TRUE or FALSE) are used not for the returns themselves, but the *chaining method* used in the calculation. (I think the documentation says simple instead of arithmetic). Part of the confusion is that the language people are using in the literature is slightly different than what I adopted at the beginning, and it could be changed to be more clear. Also, geometric == compound. Perhaps we should use chaining.method=c(geometric, simple) for all of these functions in a future version. Alternatively, we could use returns.type=c(simple, log) and provide the transformed returns from the log case, although somewhat I'm reluctant to do that across the whole package. pcc -- Peter Carl http://www.braverock.com/peter ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] help with quantmod and addTA
I don't know, Oliver. You're code is not reproducible. However, a cursory search of this list suggests that wrapping your addTA calls in plot may help. HTH, Garrett On Fri, Aug 10, 2012 at 1:43 PM, Olivier MARTIN olivier.mar...@avignon.inra.fr wrote: Hi all, I don't understand very well the principles of oriented programmation and I have some diffculties with the function addTA(). I suppose I have plotted a time serie with the function candleChart() for example. I have a vector y with 1,-1 and 0 values with the same length than my serie. If i want to add a shaded region corresponding to the value 1, I can do it with addTA(y==1,col=gray90,border=NA,on=-1) So I would like to write a function that add the three different regions I tried this addshaded=function(x){ addTA(x==1,col=gray90,border=NA,on=-1) addTA(x==-1,col=green,border=NA,on=-1) addTA(x==0,col=red,border=NA,on=-1) } But the command addshaded(y) does not add the three different shaded regions. ;-( Regards, Olivier. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] quantmod bug ?
Also, shouldn't patches be encouraged? On Wed, Aug 8, 2012 at 10:16 AM, G See gsee...@gmail.com wrote: chartSeries is on CRAN and ?chart_Series says it's highly experimental. IMHO it's really not fair to tell people that they should use undocumented code. Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] IBrokers : quotes from futures combo and reqIds
I don't have a complete answer, but I don't think you directly request a quote for a twsBAG. You could get a quote for each leg and calculate it yourself. Below is an example. I hope you don't mind if I use the get_quote function from my twsInstrument package (https://r-forge.r-project.org/R/?group_id=1113). I don't know how IB calculates the BidSize and AskSize of a combo, but you can look at how I calculated it and see if it makes sense. [I don't trade subscribe to market data for MATIF, so below I'll make a combo between SPY and DIA. Note that the ratio I chose is by no means a recommendation -- I just picked a number that would make the spread close to dollar neutral] require(twsInstrument) bag - twsBAG( twsComboLeg( conId = 756733, #conId(SPY), ratio = 1, action = BUY, exchange = SMART ) , twsComboLeg( conId = 73128548, #conId(DIA), ratio = 1.06, action = SELL, exchange = SMART ) ) ## Get a quote for both legs (tmp - get_quote(c(bag$comboleg[[1]]$conId, bag$comboleg[[2]]$conId))) #BidSize BidPrice AskPrice AskSize Last LastSize Volume #SPY 108 137.45 137.46 138 137.453 385111 #DIA 25 129.10 129.11 23 129.091 10656 data.frame(BidSize=min(c(as.numeric(bag$comboleg[[1]]$ratio) * tmp$BidSize[1], as.numeric(bag$comboleg[[2]]$ratio) * tmp$AskSize[2])), BidPrice=as.numeric(bag$comboleg[[1]]$ratio) * tmp$BidPrice[1] - as.numeric(bag$comboleg[[2]]$ratio) * tmp$AskPrice[2], AskPrice=as.numeric(bag$comboleg[[1]]$ratio) * tmp$AskPrice[1] - as.numeric(bag$comboleg[[2]]$ratio) * tmp$BidPrice[2], AskSize=min(c(as.numeric(bag$comboleg[[1]]$ratio) * tmp$AskSize[1], as.numeric(bag$comboleg[[2]]$ratio) * tmp$BidSize[2])), row.names=paste(rownames(tmp), collapse=.)) #BidSize BidPrice AskPrice AskSize #SPY.DIA 24.38 0.59340.61426.5 HTH, Garrett On Thu, Jul 19, 2012 at 8:18 AM, omerle ome...@laposte.net wrote: Dear, 1 - Quotes from futures combo I need quotes from futures combo but I cant find how to find these quotes. I can place combo orders but I can't find how to get the quotes. For instance, I would like to have the quotes of the combo between ECO AUG12 (83617918) and ECO NOV12 (87689647). Do you have any idea ? Which part of the IB API documentation should I check ? That's quite important for me ! 2 - reqIds If I understand well reqIds, it doesnt give the next iDs from Interactive Broker but the last iDs + 1 of the R session or TWS. Sometimes it doesn't work for me because when I relaunch R or TWS it forgets the real last iDs. When the iDs count is relaunch ? How can I relaunch it ? Thanks a lot, Olivier MERLE Une messagerie gratuite, garantie à vie et des services en plus, ça vous tente ? Je crée ma boîte mail www.laposte.net ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] IBrokers : quotes from futures combo and reqIds
On Thu, Jul 19, 2012 at 10:09 AM, Stergios Marinopoulos stergios_marinopou...@yahoo.com wrote: In Java, if you create a proper BAG Contract you can use it with reqMktData() or reqHistoricalData(). I imagine the same holds true in R as well. (I can send Java examples if interested.) Try using IBrokers twsBAG() function to create a combo contract, and use the returned object as the contract to IBrokers's equivalent of reqMktData() and data should start streaming. I'm unable to get that to work. If anyone else can get it to work, please share your secret. Thanks, Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] IBrokers : quotes from futures combo and reqIds
:-( I'm afraid it doesn't even work with 1 and 1 Were you able to get market data for a twsBAG, Soren? In May, Jeff suggested it doesn't work: https://stat.ethz.ch/pipermail/r-sig-finance/2012q2/010258.html On Thu, Jul 19, 2012 at 11:36 AM, me m...@censix.com wrote: Hi Stergios I believe it is your ratios. They have to be integers. your second one is ratio = 1.06 You will have to calculate the most feasible rational approximation to your beta of -1.06/1 One solution would be -21/20 ~ -1.05 So you could set leg1: ratio = 21 leg2: ratio = 20 That should do it. Cheers Soren http://censix.com On Thu, 19 Jul 2012 08:28:17 -0700 (PDT) Stergios Marinopoulos stergios_marinopou...@yahoo.com wrote: I took Garrett's example and tried to get it working using IBrokers. It's starts writing data to a file as expected, but then the error below is produced and quote data is no longer written to the file. 2 1 320 Error reading request:-'wc' : cause - Unable format field - Here's the code: library(IBrokers) ; tws - twsConnect(1) bag - twsBAG( twsComboLeg( conId = 756733, #conId(SPY), ratio = 1, action = BUY, exchange = SMART ) , twsComboLeg( conId = 73128548, #conId(DIA), ratio = 1.06, action = SELL, exchange = SMART ) ) bag.csv - file(~/bag.csv, open=w) reqMktData(tws, bag, eventWrapper=eWrapper.MktData.CSV(1), file=bag.csv) -- Stergios Marinopoulos - Original Message - From: G See gsee...@gmail.com To: Stergios Marinopoulos stergios_marinopou...@yahoo.com Cc: omerle ome...@laposte.net; r-sig-finance@r-project.org r-sig-finance@r-project.org Sent: Thursday, July 19, 2012 11:11 AM Subject: Re: [R-SIG-Finance] IBrokers : quotes from futures combo and reqIds On Thu, Jul 19, 2012 at 10:09 AM, Stergios Marinopoulos stergios_marinopou...@yahoo.com wrote: In Java, if you create a proper BAG Contract you can use it with reqMktData() or reqHistoricalData(). I imagine the same holds true in R as well. (I can send Java examples if interested.) Try using IBrokers twsBAG() function to create a combo contract, and use the returned object as the contract to IBrokers's equivalent of reqMktData() and data should start streaming. I'm unable to get that to work. If anyone else can get it to work, please share your secret. Thanks, Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. -- Soren Wilkening http://censix.com ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] qsiblive, how to debug code with source() as sub procedure
On Sat, Jul 14, 2012 at 9:59 AM, unsown uns...@gmail.com wrote: I'm not an experienced R user and I'm currently trying with the psiblive demo codes. I found the source() command has been used in quite a few places in the codes. I understand that by using this a long procedure can be separated into several modules, but I found it is not easy to debug. One of the difficulty is that it seems not easy to find out which file and which line the error belonged to. Maybe ?getSrcFilename can help with this Regards, Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] TSE ticker problems
I don't think google provides that data in a nice format (i.e. CSV) If you go to http://www.google.com/finance/historical?q=NYSEARCA:SPY you can see that on the right side of the page there is a section called Export with a link called Download to spreadsheet However, if you go the analogous page for COS, there is no such link. http://www.google.com/finance/historical?q=TSE:COS On Wed, Jul 11, 2012 at 1:57 PM, Paul Gilbert pgilbert...@gmail.com wrote: My bad. Indeed the examples should have been: getSymbols(BMO.TO, src=yahoo) getSymbols(COS.TO, src=yahoo) getSymbols(TSE:COS, src=google) They lost something in translation from my code. The problem is not resolved by this correction, however the yahoo retrieval is fixed by the getSymbols.yahoo URL change suggested. The google retrieval still causes problems: getSymbols(TSE:COS, src=google) Error in download.file(paste(google.URL, q=, Symbols.name, startdate=, : cannot open URL 'http://finance.google.com/finance/historical?q=TSE:COSstartdate=Jan+01,+2007enddate=Jul+11,+2012output=csv' In addition: Warning message: In download.file(paste(google.URL, q=, Symbols.name, startdate=, : cannot open: HTTP status was '404 Not Found' Any further suggestions appreciated. Thanks, Paul ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] TSE ticker problems
Paul, Although, changing the yahoo URL seemed to work to get yahoo's data for COS.TO, beware that there is a 4+ month gap in their data in 2012. tail(COS.TO) COS.TO.Open COS.TO.High COS.TO.Low COS.TO.Close COS.TO.Volume 2012-02-22 23.25 23.61 23.2323.61 1473800 2012-02-23 23.68 23.75 23.4123.62 1560800 2012-02-24 23.74 23.96 23.6223.66 1639300 2012-02-27 23.60 23.60 23.2623.34 1261100 2012-02-28 23.34 23.70 23.2723.34 2038900 2012-07-11 19.13 19.59 18.9219.40 1286400 COS.TO.Adjusted 2012-02-22 23.61 2012-02-23 23.62 2012-02-24 23.66 2012-02-27 23.34 2012-02-28 23.34 2012-07-11 23.34 Garrett On Wed, Jul 11, 2012 at 1:57 PM, Paul Gilbert pgilbert...@gmail.com wrote: snip however the yahoo retrieval is fixed by the getSymbols.yahoo URL change suggested. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] blotter updatePortf issues
This does not have anything to do with xts. It is a blotter bug that was introduced in Rev. 1027 (http://r-forge.r-project.org/scm/viewvc.php/pkg/blotter/R/updatePosPL.R?sortby=revroot=blotterr1=1027r2=1026pathrev=1027) You can see from Hideyoshi's traceback, that updatePortf was called with Dates=paste(::, as.Date(Sys.time())) 6: updatePortf(Portfolio = portfolio.st, Dates = paste(::, as.Date(Sys.time()), sep = )) at macd.R#80 Then, later, in .updatePosPL, a / is added to the date string 8: index(prices[paste(/, .parseISO8601(Dates)$last.time, sep = )]) So, it's trying to parse something that looks sort of like this /::2012-07-10 That said, I'm not sure how to patch. Best, Garrett On Tue, Jul 10, 2012 at 4:12 AM, OpenTrades j...@opentrades.nl wrote: Hi Hideyoshi, On 10-07-12 02:44, Hideyoshi Maeda wrote: Hi guys, I am having a few issues with the updatePortf function...this error seems to keep re-occuring...but have managed to make a reproducible example...that occurs on the demos...fyi this error does not occur when running blotter version 0.8.9 when running demo(macd) the code stops with this error... updatePortf(Portfolio=portfolio.st,Dates=paste('::',as.Date(Sys.time()),sep='')) Error in if (length(c(year, month, day, hour, min, sec)) == 6 c(year, : missing value where TRUE/FALSE needed In addition: Warning message: In as_numeric() : NAs introduced by coercion Looks like you hit the same bug that I filed a couple of weeks ago, see: http://r-forge.r-project.org/tracker/index.php?func=detailaid=2116group_id=118atid=516 for a description and a workaround. Please attach your reproducible example to my bug report, so the developers can fix the bug. HTH, Jan. and running traceback() it shows this... traceback() 14: function (year = 1970, month = 12, day = 31, hour = 23, min = 59, sec = 59, subsec = 0.9, tz = ) { if (!missing(sec) sec%%1 != 0) subsec - 0 sec - ifelse(year 1970, sec, sec + subsec) mon.lengths - c(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) if (missing(day)) { day - ifelse(month %in% 2, ifelse(((year%%4 %in% 0 !year%%100 %in% 0) | (year%%400 %in% 0)), 29, 28), mon.lengths[month]) } if (length(c(year, month, day, hour, min, sec)) == 6 c(year, month, day, hour, min, sec) == c(1969, 12, 31, 23, 59, 59) Sys.getenv(TZ) %in% c(, GMT, UTC)) sec - sec - 1 ISOdatetime(year, month, day, hour, min, sec, tz) }(year = NA_real_, tz = ) 13: do.call(lastof, parse.side(intervals[2], intervals[1])) 12: as.POSIXlt(do.call(lastof, parse.side(intervals[2], intervals[1]))) 11: .parseISO8601(ii, .index(x)[1], .index(x)[nr], tz = tz) 10: `[.xts`(prices, paste(/, .parseISO8601(Dates)$last.time, sep = )) 9: prices[paste(/, .parseISO8601(Dates)$last.time, sep = )] 8: index(prices[paste(/, .parseISO8601(Dates)$last.time, sep = )]) 7: .updatePosPL(Portfolio = pname, Symbol = as.character(symbol), Dates = Dates, Prices = Prices, ... = ...) 6: updatePortf(Portfolio = portfolio.st, Dates = paste(::, as.Date(Sys.time()), sep = )) at macd.R#80 5: eval(expr, envir, enclos) 4: eval(ei, envir) 3: withVisible(eval(ei, envir)) 2: source(available, echo = echo, max.deparse.length = Inf, keep.source = TRUE) 1: demo(macd) Other discussions have related the error messages to a non-updated version of xts...I think everything is pretty much up-to-date, but just in case here is my sessionInfo() sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] C/en_US.UTF-8/C/C/C/C attached base packages: [1] tools parallel stats graphics grDevices utils datasets methods [9] base other attached packages: [1] XML_3.9-4Rook_1.0-5 [3] brew_1.0-6 lubridate_1.1.0 [5] knitr_0.6.3 rJava_0.9-3 [7] googleVis_0.2.16 RJSONIO_0.98-1 [9] timeDate_2160.95 plyr_1.7.1 [11] PerformanceAnalytics_1.0.4.4 quantstrat_0.6.8 [13] blotter_0.8.10 FinancialInstrument_0.15.1 [15] quantmod_0.3-19 Defaults_1.1-1 [17] TTR_0.21-1 xts_0.8-6 [19] zoo_1.7-7 loaded via a namespace (and not attached): [1] digest_0.5.2 evaluate_0.4.2 formatR_0.5grid_2.15.1 lattice_0.20-6 [6] stringr_0.6 Any help would be greatly appreciated! And thanks again to you guys who put in so much hard work to build this amazing software! Thanks ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. -- Jan
Re: [R-SIG-Finance] blotter updatePortf issues
Apologies for the misinformation. blotter was version 0.8.9 at Rev. 1027, and according to the OP version 0.8.9 does not have the error. I am unable to reproduce the error. Garrett On Tue, Jul 10, 2012 at 8:20 AM, G See gsee...@gmail.com wrote: This does not have anything to do with xts. It is a blotter bug that was introduced in Rev. 1027 (http://r-forge.r-project.org/scm/viewvc.php/pkg/blotter/R/updatePosPL.R?sortby=revroot=blotterr1=1027r2=1026pathrev=1027) You can see from Hideyoshi's traceback, that updatePortf was called with Dates=paste(::, as.Date(Sys.time())) 6: updatePortf(Portfolio = portfolio.st, Dates = paste(::, as.Date(Sys.time()), sep = )) at macd.R#80 Then, later, in .updatePosPL, a / is added to the date string 8: index(prices[paste(/, .parseISO8601(Dates)$last.time, sep = )]) So, it's trying to parse something that looks sort of like this /::2012-07-10 That said, I'm not sure how to patch. Best, Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] yahoo dates
FWIW, I download 33 fields from yahoo every night at 10 p.m. CDT using quantmod::getQuote, and the prices and volumes (and everything else except 50-day MA, 200-day MA and Ave. Daily Volume) reported by getQuote at 10 p.m. CDT on 2012-07-03 were the same as those reported at 10 p.m. CDT on 2012-07-04 I only download data for stocks (not stock indexes), but using SPY as an example, the Volume as reported by getQuote was 80450168 on both dates. If I use getSymbols now, it tells me that the volume was 8045 (i.e. the same, but rounded). getQuote reported the same volume on both days for all of the roughly 7500 stocks and ETFs that are listed in the U.S. for which I collect data. So, at least for stocks, the extra volume never showed up using getQuote. But, since I wasn't downloading data for indexes, I can't say whether it would have shown up there. Regards, Garrett On Thu, Jul 5, 2012 at 4:47 PM, Motley Fool motleyf...@dawgstar.org wrote: On Thu, Jul 5, 2012 at 11:33 AM, Paul Gilbert pgilbert...@gmail.com wrote: Occasionally this week it seems that yahoo is using the previous day's date SNIP Does anyone know what is going on at yahoo? What is the convention at other data suppliers for adjustment data on holidays, or are these real prices and volume that occurred after July 3? Paul Paul I saw this start Tueday, the closing $amount for the previous day is the same, but the volume is different. I've used Yahoo data though Holiday periods before and this is the first time I've seen this happen. diana ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] addTxns addfees
My apologies. I see what you are talking about, and I see where that is hardcoded in. So, you would need to replace TxnFee - 0 with TxnFee - as.numeric(TxnData[row, txnfees]) On Wed, Jul 4, 2012 at 6:24 PM, Hideyoshi Maeda hideyoshi.ma...@gmail.com wrote: Thanks for your response. I am aware that addTxn is not vectorized... but what I am using below is addTxns...(note the 's' after Txn) This allows transaction data through the TxnData argument It is, in effect, a vectorised version of addTxn...even the blotter demo from demo(amzn_test) uses this However unlike the demo...i wanted to include Transaction fees, and wanted to know if this was possible...as the function for addTxns automatically assigns this to zero... On 5 Jul 2012, at 09:15, G See wrote: Hi Hideyoshi, addTxn is not vectorized, and it does not have a txnData argument. To see how the function is intended to be used, please read ?addTxn Then look at the demos that are included with blotter as well as the examples in ?blotter. HTH, Garrett On Wed, Jul 4, 2012 at 5:46 PM, Hideyoshi Maeda hideyoshi.ma...@gmail.com wrote: If an example is required Here is an example: rm(list=ls(pos=.blotter),pos=.blotter) rm(list=ls(pos=.instrument),pos=.instrument) rm(list=ls(pos=.strategy),pos=.strategy) currency('USD') stock(SPY, currency=USD, mulitplier=1) getSymbols('SPY', from='2012-03-01', to='2012-07-04') portf.name - dummy.Portfolio initPortf(portf.name, 'SPY', initDate='2012-02-29') initAcct(portf.name, portf.name, initDate='2012-02-29', initEq=1e6) qty - rep(c(1,-1), nrow(SPY)/2) price - SPY[,4] txnfees - rep(-5, nrow(SPY)) txndata - cbind(qty, price, txnfees) colnames(txndata) - c(Quantity,Price,txnfees) blotter:::addTxns(Portfolio=portf.name, Symbol='SPY', TxnData=txndata ) txns - getTxns(Portfolio=portf.name, Symbol='SPY') head(txns) This will show the buying and selling of 1 share on alternate days at the close but will not show any of the fees relating to each transaction. Thanks HLM On 5 Jul 2012, at 01:48, Hideyoshi Maeda wrote: Hi I am looking at the addTxns function in blotter, and I would like to add fees data/information in the TxnData argument (as a column). When looking at the function, by running blotter:::addTxns it seems to use the column names Price and Quantity but automatically sets/assigns the TxnFees to zero. Is there a way of overwriting this, so that it can be included in my analysis? ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] PortfolioAnalytics
I suggest that when you take this up on a Cygwin SVN list you show *exactly* what commands you entered, and *exactly* what errors you saw. Or, you could just use TortoiseSVN. On Thu, Jun 21, 2012 at 8:19 AM, Pierre-Alexandr des Mazis p.desma...@gmail.com wrote: Hi I used SVN with Cygwin to checkout the project but host name could not be reached. Regards Pierre-Alexandre des Mazis + 447 779 171 499 On 21 Jun 2012, at 13:59, G See gsee...@gmail.com wrote: Precisely what do you mean by the SVN is not working? When you read the thread that Julien provided, did you follow this link that I provided in that thread? http://stackoverflow.com/questions/11105131/cannot-install-r-forge-package-using-install-packages R-Forge does not build packages for old versions of R. You have to build it yourself. If it really is an SVN problem, then R-sig-finance is not the best place to ask. HTH, Garrett On Thu, Jun 21, 2012 at 7:21 AM, Pierre-Alexandr des Mazis p.desma...@gmail.com wrote: The SVN is not working on my side. Do you think I could find any Orr package zip for R 2.12? I am not very familiar with the building process . Regards Pierre-Alexandre des Mazis + 447 779 171 499 On 21 Jun 2012, at 12:04, julien cuisinier j_cuisin...@hotmail.com wrote: Please do some research before posting: http://r.789695.n4.nabble.com/Where-to-obtain-version-of-PortfolioAnalytics-package-installable-on-R-2-15-td4633724.html Same comment would be valid for Juan's post yesterday asking about the RExcel, half a minute googling would have told him how to extract a tar.gz file, even on Windows seems there have been some issues with the build as Garret mentioned, you might have to build it yourself. If you do please share with the list Rgds, Julien From: p.desma...@gmail.com Date: Thu, 21 Jun 2012 11:42:09 +0100 To: r-sig-finance@r-project.org Subject: [R-SIG-Finance] PortfolioAnalytics Hi I was looking for PortfolioAnalytics package zip but could not find it on the web. Can you please help on that Thank you ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Where to obtain version of PortfolioAnalytics package installable on R 2.15
On Mon, Jun 18, 2012 at 2:34 PM, G See gsee...@gmail.com wrote: I wish there were an R-Forge FAQ I could point to. Now we can direct these types of question to this post: http://stackoverflow.com/questions/11105131/cannot-install-r-forge-package-using-install-packages Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Where to obtain version of PortfolioAnalytics package installable on R 2.15
I wish there were an R-Forge FAQ I could point to. You need to use svn to checkout the code. (tortoise svn is popular for Windows) svn checkout svn://svn.r-forge.r-project.org/svnroot/returnanalytics/ Navigate to the pkg directory of what you just checked out cd returnanalytics/pkg Then build and install it. Since you're on Windows, you'll need http://cran.r-project.org/bin/windows/Rtools/ R CMD INSTALL --build PortfolioAnalytics As you noticed, that package has some problems that prevent it from passing R CMD check, so don't hold your breath waiting for R-Forge to build it. (Also, don't expect the documentation to match the code) If you're going to use code that is under development, you need to learn to use svn and how to build packages from source. If you have trouble building from source, follow up on R-help. HTH, Garrett On Mon, Jun 18, 2012 at 12:02 PM, David-Michael Lincke dlin...@lincke.com wrote: Could somebody please point me to where I can obtain a version of package PortfolioAnalytics that can be installed on R 2.15 (x86 32 bit) on Windows? The obvious approach fails: install.packages(PortfolioAnalytics,repos=http://r-forge.r-project.org;) Warning message: package ‘PortfolioAnalytics’ is not available (for R version 2.15.0) A closer look on R-Forge shows that the package has not been building successfully for some time due to issues with compiling the documentation into pdf. Thanks, David [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Compute jump test statistic
We don't have your data, so we can't get past numr = 1 - (outads$medrv/outads$rv) Error: object 'outads' not found Please see: tinyurl.com/reproducible-000 and http://www.r-project.org/posting-guide.html Also, it wouldn't hurt to explain what you're doing, what all those terms are in your formula, and what the notation means. Finally, only send text e-mails to the list; no HTML. Garrett On Mon, Jun 18, 2012 at 2:16 PM, Caolan Harvey caolan.harv...@mail.dcu.ie wrote: Im trying to compute the following statistic testing for jumps in high frequecy asset prices, J t,M = (1 – MedRVt,M / RVt,M) /(sqrt*( 0.96 * 1/M * max(1, MedRQt,M/ MedRV2t,M )) I have in R: ## ADS Test Statistic numr = 1 - (outads$medrv/outads$rv) outads$medrq/(outads$medrv^2) - denom2 fix(denom2) But when I try to run the max(1, MedRQt,M/ MedRV2t,M)) part I get: max(1, denom2)[1] NA I guess this is returned because I am tryin to maximise a time series / sequence against a constant but I am not sure how to run this? Any advice? Thanks [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Error in midnightStandard(charvec, format)
Hi Wei-han, The problem is that your csv has tabs in the date. One solution would be to remove the tabs with gsub like this dataset$Date - gsub(\t, , dataset$Date) That should get rid of the error. A more elegant solution might be to use read.zoo from the zoo package to read your csv. HTH, Garrett On Tue, Jun 5, 2012 at 7:10 PM, Wei-han Liu weihanliu2...@yahoo.com wrote: Hi R users: I am trying some functions in QRMlib package and applying to my own trial dataset but encountered the following error message when dealing with time series data. Error in midnightStandard(charvec, format) : 'charvec' has non-NA entries of different number of characters I have googled for some solution but the discussions are not clear enough to me if the issue can be solved or not. I suppose it is due to the data type conflict. Listed below is the coding and dataset is attached: dataset - read.csv(D:/stockindex.csv, header=TRUE, sep = ,); tsData - as.timeSeries(dataset); Date - tsData[,1]; SP500ts - tsData[,2]; SP500.nreturns - -mk.returns(SP500ts); tD - timeDate(05/16/1992,%m/%d/%Y); window - (seriesPositions(SP500.nreturns) tD); SP500.nreturns - SP500.nreturns[window]; Thanks for your attention and assistance. Wei-han ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] IBrokers - reqOpenOrders and placeOrder not working anymore
Checkout the code with svn and build it yourself. The current version is 0.9-7 On linux or mac, you'd do something like this svn checkout http://ibrokers.googlecode.com/svn/trunk/ ibrokers That will checkout the code into a directory called ibrokers. Then you can R --vanilla CMD INSTALL --build ibrokers HTH, Garrett On Thu, May 17, 2012 at 3:15 PM, omerle ome...@laposte.net wrote: Hi, I just dowload IBrokers from http://code.google.com/p/ibrokers/downloads/detail? name=IBrokers_0.9-0.tar.gzcan=2q= and install IBrokers with install.packages(C:/IBrokers_0.9-0).tar.gz, repos = NULL, type=source) but reqOpenOrders and placeOrders is not working anyway ! Any other advice ? Thanks Try updating to the newest googlecode version. A change in IB response. Jeff Jeffrey Ryan | Founder | jeffrey.r...@lemnica.com www.lemnica.com On May 11, 2012, at 5:26 PM, G See wrote: FWIW, I have the opposite problem. When connected with a live account, I see: tws - twsConnect() tws$nextValidId [1] 1 But, with the demo account, the account number is being stored in nextValidId: tws - twsConnect() tws$nextValidId [1] DU123456 # But, I changed the actual account number Best, Garrett On Fri, May 11, 2012 at 8:03 AM, omerle wrote: Dear All, First thanks to Jeff Ryan for the very interesting IBrokers package. After looking for answers on Rseek without success, your are my last hope ! Here is my problem : placeOrder reqOpenOrders don't work on my trading accout but its working on my demo account ! For instance when I do reqOpenOrders(twsconn) or IBrokers:::.reqOpenOrders(twsconn) = I get only the error message 53 (OPEN_ORDER_END) even if I have open order in my console. OR placeOrder = it doesnt do anything = But I can get TWS real time quotes or accountUpdate (I think it was ok before at least for placeOrder) I set the same parameter in configurationAPIs for both my demo account and trading account but trading account is still not working. Do you have any idea what I did wrong and how I can use both placeOrder and reqOpenOrders ? Many Thanks, Olivier Merle Une messagerie gratuite, garantie à vie et des services en plus, ça vous tente ? Je crée ma boîte mail www.laposte.net ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. Une messagerie gratuite, garantie à vie et des services en plus, ça vous tente ? Je crée ma boîte mail www.laposte.net ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] quanstrat rule to exit same day close (using daily data)
Extending on what Jan said, perhaps you could add a PrevClose column to your data and use prefer='PrevClose' Garrett On Sun, May 13, 2012 at 2:55 PM, s p algotr8...@gmail.com wrote: okay so that means I can't use quantstrat for strategies where the entry and exit are on the same bar (in this case daily bar). I can do this in blotter - which I guess is fine. Thanks for the feedback. On Sun, May 13, 2012 at 3:46 PM, OpenTrades j...@opentrades.nl wrote: In quantstrat, if your have a signal on bar t, the rule will be executed at bar t+1. In your case, this means that the order will be added for the next day. Use the 'prefer'-argument to specify which of next day's rates (open, low, high, close) you want to use. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] IBrokers - reqOpenOrders and placeOrder not working anymore
FWIW, I have the opposite problem. When connected with a live account, I see: tws - twsConnect() tws$nextValidId [1] 1 But, with the demo account, the account number is being stored in nextValidId: tws - twsConnect() tws$nextValidId [1] DU123456 # But, I changed the actual account number Best, Garrett On Fri, May 11, 2012 at 8:03 AM, omerle ome...@laposte.net wrote: Dear All, First thanks to Jeff Ryan for the very interesting IBrokers package. After looking for answers on Rseek without success, your are my last hope ! Here is my problem : placeOrder reqOpenOrders don't work on my trading accout but its working on my demo account ! For instance when I do reqOpenOrders(twsconn) or IBrokers:::.reqOpenOrders(twsconn) = I get only the error message 53 (OPEN_ORDER_END) even if I have open order in my console. OR placeOrder = it doesnt do anything = But I can get TWS real time quotes or accountUpdate (I think it was ok before at least for placeOrder) I set the same parameter in configurationAPIs for both my demo account and trading account but trading account is still not working. Do you have any idea what I did wrong and how I can use both placeOrder and reqOpenOrders ? Many Thanks, Olivier Merle Une messagerie gratuite, garantie à vie et des services en plus, ça vous tente ? Je crée ma boîte mail www.laposte.net ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] IBrokers - reqOpenOrders and placeOrder not working anymore
Oops. I was on an old revision. After updating to the version in the repo (http://code.google.com/p/ibrokers), all is well. Garrett On Fri, May 11, 2012 at 5:26 PM, G See gsee...@gmail.com wrote: FWIW, I have the opposite problem. When connected with a live account, I see: tws - twsConnect() tws$nextValidId [1] 1 But, with the demo account, the account number is being stored in nextValidId: tws - twsConnect() tws$nextValidId [1] DU123456 # But, I changed the actual account number Best, Garrett On Fri, May 11, 2012 at 8:03 AM, omerle ome...@laposte.net wrote: Dear All, First thanks to Jeff Ryan for the very interesting IBrokers package. After looking for answers on Rseek without success, your are my last hope ! Here is my problem : placeOrder reqOpenOrders don't work on my trading accout but its working on my demo account ! For instance when I do reqOpenOrders(twsconn) or IBrokers:::.reqOpenOrders(twsconn) = I get only the error message 53 (OPEN_ORDER_END) even if I have open order in my console. OR placeOrder = it doesnt do anything = But I can get TWS real time quotes or accountUpdate (I think it was ok before at least for placeOrder) I set the same parameter in configurationAPIs for both my demo account and trading account but trading account is still not working. Do you have any idea what I did wrong and how I can use both placeOrder and reqOpenOrders ? Many Thanks, Olivier Merle Une messagerie gratuite, garantie à vie et des services en plus, ça vous tente ? Je crée ma boîte mail www.laposte.net ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Generating a front month only Time Series for Futures Prices
John, I think you probably meant to send this to the list instead of just me; apologies if not. I agree that when possible, you should avoid building continuous series. Nonetheless, that's what the OP asked for. Sometimes, there is value in analyzing a long history of data (for example when analyzing risk) and in such cases, a constant maturity future makes sense. Also, if your time-frame is short and you're careful about how you adjust and how you use the adjusted data, I think it can be useful. The OP wanted to combine and not adjust, which, IMO is more dangerous than combining and adjusting. If you're going to combine the price series of 2 different expiration months, then you have to adjust for the roll. Otherwise, you may see a trend or mean-reversion where there isn't one, or worse, the opposite is actually occurring. Your point about this being a difficult thing to generalize (e.g. different grades for different expirations, or first notice day being different than expiration, etc.) is valid. Regards, Garrett On Thu, May 10, 2012 at 12:48 PM, BBands bba...@gmail.com wrote: I feel that reiterating my prior warning is worthwhile. The proper way to do this is to analyze the actual contracts and roll just as you would have to if you were actually trading; exit the current contact when the crowd moves enter the new actively-traded front month and account for each separately. I coded this in Python and it works well, but I have yet to tackle futures in R. Some problems: In some commodities not all months actually trade actively. Backwardation and contango can impact the rolls dramatically. While analyzing months in delivery may seem OK, traders avoid them. None of the shortcuts that I know of comes even close to approximating the realities of the marketplace. Most analysts (including most of the tblox crowd) simply ignore these problems, analyze continuous contracts and are burned when they enter the marketable. Current example problem: Different crude contracts track different delivery venues and are priced differently. Think WTI versus Brent, spread truculently running tin the $10 range, which not too long ago was thought 'impossible. This is a very deep well. Best, John ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Generating a front month only Time Series for Futures Prices
repost for the archives: I agree that when possible, you should avoid building continuous series. Nonetheless, that's what the OP asked for. Sometimes, there is value in analyzing a long history of data (for example when analyzing risk) and in such cases, a constant maturity future makes sense. Also, if your time-frame is short and you're careful about how you adjust and how you use the adjusted data, I think it can be useful. The OP wanted to combine and not adjust, which, IMO is more dangerous than combining and adjusting. If you're going to combine the price series of 2 different expiration months, then you have to adjust for the roll. Otherwise, you may see a trend or mean-reversion where there isn't one, or worse, the opposite is actually occurring. Your point about this being a difficult thing to generalize (e.g. different grades for different expirations, or first notice day being different than expiration, etc.) is valid. Regards, Garrett ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] object .blotter not found
My guess is that either you used a clear workspace button on your GUI, or you did something to the effect of rm(list=ls(all=TRUE)). .blotter is an environment that is stored under your .GlobalEnv when you load the package. If you delete it, you have to put it back with something like this if (!exists('.blotter')) .blotter - new.env() Prior to 2012, the .instrument environment was also stored in the .GlobalEnv, but with FinancialInstrument version 0.10.0, it was moved to live in the top level of the package. Therefore, the .instrument environment doesn't get wiped out if the user clears their workspace. But, it appears to be missing unless you know where to look. This should work ls(FinancialInstrument:::.instrument) But, it's not as robust as using ls_instruments() .blotter should probably be moved out of the .GlobalEnv as well, but for now, either don't clear your .GlobalEnv, or recreate a .blotter environment after you do. HTH, Garrett On Sun, May 6, 2012 at 1:23 AM, Peter Chan heypeterc...@yahoo.com wrote: Hi there I am running demo(longtrend) but it is failing on initPortf (although the blotter package is loaded): ltportfolio='longtrend' ltaccount='longtrend' initPortf(ltportfolio,'GSPC', initDate=initDate) Error in exists(paste(portfolio, name, sep = .), envir = .blotter, : object '.blotter' not found Any ideas? I also noticed that .instrument environment isn't found in my workspace, but I can use getInstrument! ls(envir=.instrument) Error in ls(envir = .instrument) : object '.instrument' not found getInstrument('USD') primary_id :USD currency :USD multiplier :1 tick_size :0.01 identifiers: list() type :currency ls(envir=.blotter) Error in ls(envir = .blotter) : object '.blotter' not found Thanks Peter sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_Singapore.1252 LC_CTYPE=English_Singapore.1252 [3] LC_MONETARY=English_Singapore.1252 LC_NUMERIC=C [5] LC_TIME=English_Singapore.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] blotter_0.8.8 FinancialInstrument_0.14.2 quantmod_0.3-17 [4] TTR_0.21-1 xts_0.8-6 zoo_1.7-7 [7] Defaults_1.1-1 loaded via a namespace (and not attached): [1] grid_2.15.0 lattice_0.20-6 tools_2.15.0 [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Generating a front month only Time Series for Futures Prices
On Fri, May 4, 2012 at 3:27 AM, gussinsky sd...@hotmail.com wrote: Hey Garrett, I think the ContinousSeriesCreator, is probably exactly what I am looking for. Thanks, and how did you find this function?? No special search skills, I just try to keep track of what code is in packages I maintain. ;-) ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] quantstrat with intraday data
Jim, So, on any day that there is a dividend or a split, you want to back adjust your data that you're using to calculate the next signal. Every time you back-adjust, you have to recreate your signals. If that's how you want to do it, then I think that in quantstrat world, you're better off running multiple backtests (e.g. 1 for each quarter for a stock that pays quarterly dividends) and gluing them together instead of adjusting on the fly. i.e. try to let the quantstrat part of it be as vectorized as possible. If there were an addSplit function, it would adjust the quantity of shares that you own, but last I looked, the order-sizing functionality of quantstrat was still broken which means that you wouldn't be able to adjust how many shares you trade going forward. So, assuming you're using a fixed quantity of shares for your transactions (which you are unless you patch quantstrat ;-)), AddCumDiv is like a walk-forward adjustment of price (for dividends, but you could pre-adjust your data, in a walk-forward manner, for splits as well). At the very least, it's pretty good proxy. HTH, Garrett On Wed, May 2, 2012 at 11:19 PM, Jim Green student.northwest...@gmail.com wrote: On 3 May 2012 00:07, G See gsee...@gmail.com wrote: If a stock splits in half, don't you think you should adjust for that before performing technical analysis? You'd treat that big jump in price the same as a real price jump even though if you had a position in the stock, your PnL would be unaffected by the split? sorry I was unclear... that would generate wrong signals.. I think the correct way to use split/dividend adjusted daily data for technical analysis is: 1, for each day, generate signals using adjusted data till before that day, in a walking forward fashion. 2, for pnl logistics, use trade based adjustments or position adjustments. the above are not currently supported by quantstrat and underlying blotter but is really a nice to have. is qmao addressing the them in some way? Jim. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] SMA and TTR
Just a slightly different approach: getSymbols(AAPL, src='yahoo') # 50 day moving average for last 10 days tail(SMA(tail(Ad(AAPL), 59), 50), 10) Garrett On Thu, May 3, 2012 at 8:03 AM, Brian G. Peterson br...@braverock.com wrote: On Thu, 2012-05-03 at 08:47 -0400, Gordon Erlebacher wrote: I wish to compute trading criteria only for past 10 days. That involves, say, a 50 day moving average. The SMA function does not allow me to only compute the 50 day moving average over the past 10 days, even if I have the symbol series for the past 200 days! getSymbols(AAPL) SMA(AAPL, 10) will compute the moving average for the entire series with 9 NAs. But that is more expensive than computing only the last 10 moving averages, necessary for my trading system. (this is just an example). If I am mistaken, could you please let me know how? I believe that all the TTR functions should be amended to compute the time series between a from and to date. Yes, you are mistaken. Please look for information on 'vectorization' in R. While it is sometimes true that TTR will not use a vectorized calculation, you can always subset your data in xts to use a shorter series. the 'from' and 'to' date in this case would be represented like so: from - '2012-04-01' to - '2012-05-02' #assume x is my xts time series SMA(x[paste(from,to,sep='/')],10) Also note that you would need only 20 days of data, not 50, for get 10 periods of a ten day SMA. The subset you need is easily computed from the indices of the data, using e.g. lt - length(index(x)) lf - lt-20 SMA(x[lf:lt,],10) -- Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Generating a front month only Time Series for Futures Prices
Gussinsky, Since you are looking to test for cointegration, and you say you're looking at energy products (which have liquidity in more than just the front contract), I'd suggest creating a constant maturity future (CMF) that is the interpolated price between the 2 lead contracts (see Carol Alexander's stuff for more info). CMFs don't require any back adjusting, they just require that you partially roll your position every day. HTH, Garrett On Thu, May 3, 2012 at 2:02 PM, BBands bba...@gmail.com wrote: Beware, this is a mine field! For example, one problem you will need to deal with is that different commodities roll on different dates. Then there is the nightmare quagmire of back adjusting, which is best skipped altogether in my opinion. In short, there are many ways to get hurt here. There is a large literature on the topic, starting with W. D. Gann 80+ years ago. The writings of Bob Pelletier of CSI are a good trail-head. John On Thu, May 3, 2012 at 11:44 AM, gussinsky sd...@hotmail.com wrote: Hello All, I am struggeling to find a method which would enable me to generate a historical time series which only contains a commodities front month price, and after expiry automatically rolls over to the next month. I suspect one has to code the roll over rule from the respective exchange into a function, and supply the function with the respective expired historical data. My aim is to backtest those data for delta 1 strategies, but also for cointegration. One example would be heating oil futures vs. gasoil futures. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Generating a front month only Time Series for Futures Prices
I'm not sure if this link will work; if not, I'm trying to point you to page 75 of Market Risk Analysis: Pricing, Hedging and Trading Financial Instruments http://books.google.com/books?id=3Xg4pO1PEpUCpg=PR13lpg=PR13dq=carol+alexander+constant+maturity+futuresource=blots=ArlAbn7XPWsig=1WGn8vNIVRy-FEYFhNyncd_WVU0hl=ensa=Xei=O92iT46KEYPO9QTry7jeCAved=0CDkQ6AEwBA#v=onepageq=constant%20maturityf=false Garrett On Thu, May 3, 2012 at 2:28 PM, G See gsee...@gmail.com wrote: Gussinsky, Since you are looking to test for cointegration, and you say you're looking at energy products (which have liquidity in more than just the front contract), I'd suggest creating a constant maturity future (CMF) that is the interpolated price between the 2 lead contracts (see Carol Alexander's stuff for more info). CMFs don't require any back adjusting, they just require that you partially roll your position every day. HTH, Garrett On Thu, May 3, 2012 at 2:02 PM, BBands bba...@gmail.com wrote: Beware, this is a mine field! For example, one problem you will need to deal with is that different commodities roll on different dates. Then there is the nightmare quagmire of back adjusting, which is best skipped altogether in my opinion. In short, there are many ways to get hurt here. There is a large literature on the topic, starting with W. D. Gann 80+ years ago. The writings of Bob Pelletier of CSI are a good trail-head. John On Thu, May 3, 2012 at 11:44 AM, gussinsky sd...@hotmail.com wrote: Hello All, I am struggeling to find a method which would enable me to generate a historical time series which only contains a commodities front month price, and after expiry automatically rolls over to the next month. I suspect one has to code the roll over rule from the respective exchange into a function, and supply the function with the respective expired historical data. My aim is to backtest those data for delta 1 strategies, but also for cointegration. One example would be heating oil futures vs. gasoil futures. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Generating a front month only Time Series for Futures Prices
If you just want to combine 2 series together, no problem: use rbind. But, then you'll have a gap in your data on the roll date, and you'll be back asking how to adjust for it. ;-) That's where the minefields come into play. I look at roll cost like a dividend (which is often negative). You can adjust for it a couple different way. You could add the roll costs back to the series, which may mean negative prices in the past. Or, you could multiply by an adjustment ratio (treat it like a split). If you don't adjust for the roll, you'll have big gaps in your data. Imagine buying the front month VIX future and rolling it each month. 10 years later, the VIX may still be at the same price, but you'll likely have lost way more than you started with. If you do adjust for the roll, either the oldest prices or the newest prices may not be reasonable. To get this back to R, let's get some code involved. This is laying in the FinancialInstrument sandbox; I haven't personally looked at it, so I don't know how it works. Ditto for FinancialInstrument:::slice and FinancialInstrument:::splooth https://r-forge.r-project.org/scm/viewvc.php/pkg/FinancialInstrument/sandbox/continuousSeries.R?view=markuproot=blotter If you just want daily data that has already been adjusted for you, look here for code to download data from trading blox (it has Heating Oil.. not gasoil though): https://r-forge.r-project.org/scm/viewvc.php/pkg/FinancialInstrument/inst/parser/download.tblox.R?view=markuproot=blotter I believe Trading Blox simply adds back the roll cost. And, I think they roll when Open Interest rolls. source(http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/FinancialInstrument/inst/parser/download.tblox.R?root=blotter;) chartSeries(HO[, 8]) #unadjusted addTA(HO[, 4], col='red', on=1) #adjusted Or, are you looking for code to calculate the expiration dates of instruments? What have you tried? ;-) Garrett On Thu, May 3, 2012 at 3:07 PM, gussinsky sd...@hotmail.com wrote: Hey Garrett, thank you for this, I had a read through this page in the book you referenced. And looking at Agricultural Commodities this makes a lot of sense. And if you look at Wheat and Corn on the CBOT, I think you only have 5 deliveries per year, hence the massive gaps when each contract rolls off. So here the interpolation makes sense, and I think one could approach this trade as a box. But lets consider for example heating oil again, here you have monthly deliveries, and the seasonality is far less nowadays, in Europe even less due to the increased Diesel consumption on the roads. But lets consider this: Trading in a current month shall cease on the last business day of the month preceding the delivery month. This is the expiry rule for Heating Oil on the Nymex. I think this is codeable without minefields isn't it. It would be terrific if anyone could point me in the right direction on how to approach this. I think it wont be possible to download this with one simple function. I suspect one would have to store individual files for the respective expiry contracts, and perhaps index the file names. And then perhaps through a loop function could read out the corresponding 1:n values for each month, store them in an array, and then run the next month with the same rule, and store them again, etcIn the end one needs to connect all those arrays into one big time series. And here is my problem, I dont know how to code this, I know what I want Many thanks for the advice so far Best Gussinsky PS: Garrett, it is your Pair Trading code that brought this up my mind again :-) -- View this message in context: http://r.789695.n4.nabble.com/Generating-a-front-month-only-Time-Series-for-Futures-Prices-tp4606794p4606979.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] Generating a front month only Time Series for Futures Prices
note that if you adjust by adding back roll costs and then try to calculate returns, your returns will be off (read:wrong) On Thu, May 3, 2012 at 3:32 PM, G See gsee...@gmail.com wrote: On Thu, May 3, 2012 at 3:28 PM, G See gsee...@gmail.com wrote: If you just want to combine 2 series together, no problem: use rbind. But, then you'll have a gap in your data on the roll date, and you'll be back asking how to adjust for it. ;-) That's where the minefields come into play. I look at roll cost like a dividend (which is often negative). You can adjust for it a couple different way. You could add the roll costs back to the series, which may mean negative prices in the past. Or, you could multiply by an adjustment ratio (treat it like a split). If you don't adjust for the roll, you'll have big gaps in your data. Imagine buying the front month VIX future and rolling it each month. 10 years later, the VIX may still be at the same price, but you'll likely have lost way more than you started with. If you do adjust for the roll, either the oldest prices or the newest prices may not be reasonable. To get this back to R, let's get some code involved. This is laying in the FinancialInstrument sandbox; I haven't personally looked at it, so I don't know how it works. Ditto for FinancialInstrument:::slice and FinancialInstrument:::splooth https://r-forge.r-project.org/scm/viewvc.php/pkg/FinancialInstrument/sandbox/continuousSeries.R?view=markuproot=blotter If you just want daily data that has already been adjusted for you, look here for code to download data from trading blox (it has Heating Oil.. not gasoil though): https://r-forge.r-project.org/scm/viewvc.php/pkg/FinancialInstrument/inst/parser/download.tblox.R?view=markuproot=blotter I believe Trading Blox simply adds back the roll cost. And, I think they roll when Open Interest rolls. source(http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/FinancialInstrument/inst/parser/download.tblox.R?root=blotter;) # oops. forgot this line getSymbols(HO, src='tblox') chartSeries(HO[, 8]) #unadjusted addTA(HO[, 4], col='red', on=1) #adjusted Or, are you looking for code to calculate the expiration dates of instruments? What have you tried? ;-) Garrett On Thu, May 3, 2012 at 3:07 PM, gussinsky sd...@hotmail.com wrote: Hey Garrett, thank you for this, I had a read through this page in the book you referenced. And looking at Agricultural Commodities this makes a lot of sense. And if you look at Wheat and Corn on the CBOT, I think you only have 5 deliveries per year, hence the massive gaps when each contract rolls off. So here the interpolation makes sense, and I think one could approach this trade as a box. But lets consider for example heating oil again, here you have monthly deliveries, and the seasonality is far less nowadays, in Europe even less due to the increased Diesel consumption on the roads. But lets consider this: Trading in a current month shall cease on the last business day of the month preceding the delivery month. This is the expiry rule for Heating Oil on the Nymex. I think this is codeable without minefields isn't it. It would be terrific if anyone could point me in the right direction on how to approach this. I think it wont be possible to download this with one simple function. I suspect one would have to store individual files for the respective expiry contracts, and perhaps index the file names. And then perhaps through a loop function could read out the corresponding 1:n values for each month, store them in an array, and then run the next month with the same rule, and store them again, etcIn the end one needs to connect all those arrays into one big time series. And here is my problem, I dont know how to code this, I know what I want Many thanks for the advice so far Best Gussinsky PS: Garrett, it is your Pair Trading code that brought this up my mind again :-) -- View this message in context: http://r.789695.n4.nabble.com/Generating-a-front-month-only-Time-Series-for-Futures-Prices-tp4606794p4606979.html Sent from the Rmetrics mailing list archive at Nabble.com. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
Re: [R-SIG-Finance] quantstrat with intraday data
As an alternative to adjusting for dividends in quantstrat or blotter, my qmao package (https://r-forge.r-project.org/R/?group_id=1113) has two functions that adjust intraday data for dividends. `adjustIntraday.yahoo` will download dividend data from yahoo and calculate daily ratios. Those ratios will then be applied to intraday data. `AddCumDiv` simply adds back all dividends to the price series. With adjustIntraday.yahoo, the most recent observations will be the same as the unadjusted data, but the older observations will be lower than those that are unadjusted. With AddCumDiv, the oldest observations will be the same for the adjusted and unadjusted data, but the most recent observations will be higher for AddCumDiv. Although I believe these functions work like they're supposed to, they have not been rigorously tested, so YMMV. bug reports encouraged. Since I just committed the AddCumDiv function a few minutes ago, it is not yet in the R-Forge build (although it is in the repo if you know how to svn checkout). Since it's not in the build yet, I attached it. Regards, Garrett On Wed, May 2, 2012 at 8:02 AM, Brian G. Peterson br...@braverock.com wrote: On Wed, 2012-05-02 at 00:00 -0400, Jim Green wrote: Greetings! Pls forgive me if this is an old topic. I have searched through list archives extensively but I am just not sure if I am using quantstrat correctly with intraday data. ... Currently I use something similar to attached test.R to do intraday work. in the code I liquidate everything before close so that I don't need to worry about splits and dividends. Is what I am doing the correct way of using quantstrat with intraday data? That's certainly the easiest answer. blotter contains some support for dividends, but it is only lightly tested, since I personally don't need that functionality. Additional testing, direct feedback, and patches are always welcome. Participation by users is one of the ways these packages grow over time. (and feel free to take those conversations off-list) Also if in future I will hold overnight positions, How would I make sure dividends and splits are correctly adjusted for pnl and summary statistics? would underlying blotter be smart enough to handle all the housekeeping? No Guarantees (of course that's true of everything in R). My recollection is that the addDiv function will add cash to your account to cover dividends. I don't believe that there is a function for splits. You'd likely need to write that, we'd love the contribution. It shouldn't be hard, as all that needs to happen is that you add a transaction for the split with a price of zero, adding more shares and lowering your average cost to compensate for the split. As xts gains support for differing column classes this summer as part of the funded GSoC project, it will get easier to add additional information to transactions that will definitely include transaction type. Regards, - Brian -- Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. AddCumDiv.R Description: Binary data ___ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.