Re: [R-SIG-Finance] moving averages on specific interval and merge
Thanks Garret, it worked correctly. I found a similar question here at http://r.789695.n4.nabble.com/Speed-optimization-on-minutes-distribution-calculation-td929537.html and Jeff gave a very fast solution. Just for the reference. Now I am attempting to write a custom indicator doing what you showed to be used in quantstrat. Jim. On 12 May 2012 12:54, G See wrote: > Hi Jim, > > We prefer if you share with us what you tried and what you've done to > attempt to solve the problem yourself. Anyway here's one way to > start. > > library(quantmod) # for the Vo function as well as xts and zoo > load("~/Downloads/a.rda") > CalcMinuteVolume <- function(x) { > # This function will calculate the average of the volume for a given minute > #of every day > mvolm <- aggregate(Vo(x), format(index(x), "%H:%M"), mean) > xts(coredata(mvolm), as.POSIXct(paste(as.Date(end(x)), index(mvolm)), > format="%Y-%m-%d %H:%M")) > } > dtemp <- to.daily(temp) > index(dtemp) <- as.Date(index(dtemp)) # in case you have an old version of xts > # make strings to use to subset the data by 10 day periods > subsets <- rollapplyr(index(dtemp), 10, function(x) > paste0(first(x), "/", last(x))) > out <- lapply(subsets, function(ss) { > CalcMinuteVolume(temp[ss]) > }) > names(out) <- index(dtemp)[-c(1:9)] # days 1:9 were burned to calculate 1st > mean > # Now you have a list of days. e.g. > out[["2012-02-15"]] > # Now merge > temp$Average.Volume.at.current.interval <- do.call(rbind, out) > temp > > > Things to consider: > - You almost certainly want to throw a lag in there. > - You have a different number of rows for different days. > > Also, see ?agrregate.zoo or ?tapply, ?rollapply, ?period.apply, and ?do.call > > HTH, > Garrett > > > On Thu, May 10, 2012 at 8:11 PM, Jim Green > wrote: >> Greetings! >> >> I am using quantstrat and xts to do some intraday work and come up >> with this problem. the xts object temp in the following example is >> attached as and rda file. >> >>> head(temp) >> A.Open A.High A.Low A.Close A.Volume >> 2012-02-01 08:29:00 42.47 43.76 41.410 43.76 2071 >> 2012-02-01 09:30:00 43.38 43.38 42.970 43.15 40300 >> 2012-02-01 09:31:00 43.14 43.28 43.130 43.28 14990 >> 2012-02-01 09:32:00 43.27 43.37 43.270 43.37 3300 >> 2012-02-01 09:33:00 43.37 43.50 43.370 43.48 3056 >> 2012-02-01 09:34:00 43.49 43.50 43.396 43.44 10968 >> >>> tail(temp) >> A.Open A.High A.Low A.Close A.Volume >> 2012-03-27 16:07:00 45.6650 45.6650 45.6650 45.6650 170 >> 2012-03-27 16:08:00 45.6710 45.6710 45.6710 45.6710 474 >> 2012-03-27 16:10:00 45.9131 45.9131 45.9131 45.9131 1800 >> 2012-03-27 16:13:00 45.6952 45.6952 45.6952 45.6952 300 >> 2012-03-27 16:15:00 45.9368 45.9368 45.9368 45.9368 791 >> 2012-03-27 16:21:00 45.7000 45.7000 45.7000 45.7000 22000 >> >> >> I would like to calculate moving averages of minute volume for >> specific interval and merge with the original minute ohlc data. >> >> take 09:40:00 for example, calculate the average previous 10 days >> volume between 09:39:00 to 09:40:00 and merge with exiting data. >> >> ultimately I want to get an xts object with columns >> >> Open High Low Close Volume Average.Volume.at.current.interval >> 2012-03-27 16:07:00 45.6650 45.6650 45.6650 45.6650 170 177 >> 2012-03-27 16:08:00 45.6710 45.6710 45.6710 45.6710 474 500 >> ... >> ... >> .. >> 2012-03-27 16:21:00 45.7000 45.7000 45.7000 45.7000 22000 1000 >> >> any pointers are appreciated! >> >> 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. ___ 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 wrote: > Hi, > > I just dowload IBrokers from > http://code.google.com/p/ibrokers/downloads/detail? > name=IBrokers_0.9-0.tar.gz&can=2&q= > 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] IBrokers - reqOpenOrders and placeOrder not working anymore
Hi, I just dowload IBrokers from http://code.google.com/p/ibrokers/downloads/detail? name=IBrokers_0.9-0.tar.gz&can=2&q= 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.
Re: [R-SIG-Finance] look at the underlying source code
On Thu, 2012-05-17 at 19:40 +0200, jaimie villanueva wrote: > hi > > someone can show me how can i get the source code of a function. Exactly, > Function "ugarchsim" from library (rugarch). > I need to know (in detailed ) how the variance and mean ecuation of a > arma/garch process are calculated. > With other packages like "fGarch" i used to invoked the function debug () > and allows me to step into the functions but with ugarchsim i can't use it. > > any suggestions are well received 1> this is not a finance question. Please direct general R questions to r-help, and/or follow the advice that Alexios already gave you to look up the answer. 2> all the code is on R-Forge, download it and look. 3> much of the rugarch and rmgarch code is compiled, and other parts of it are S4, these are not as easy to debug into as vanilla R code. See the answer to 1> above for details on how to do this, and pursue further non-finance questions about it on r-help, not here. 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.
Re: [R-SIG-Finance] look at the underlying source code
simply type the name of the function in the console without parenthesis or anything - much easier than debug HTH, Julien > Date: Thu, 17 May 2012 19:40:00 +0200 > From: jaimie.villanu...@gmail.com > To: R-SIG-Finance@r-project.org > Subject: [R-SIG-Finance] look at the underlying source code > > hi > > someone can show me how can i get the source code of a function. Exactly, > Function "ugarchsim" from library (rugarch). > I need to know (in detailed ) how the variance and mean ecuation of a > arma/garch process are calculated. > With other packages like "fGarch" i used to invoked the function debug () > and allows me to step into the functions but with ugarchsim i can't use it. > > any suggestions are well received > > thanks > > Jamie > > [[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] look at the underlying source code
On Thu, May 17, 2012 at 12:40 PM, jaimie villanueva wrote: > hi > > someone can show me how can i get the source code of a function. Exactly, > Function "ugarchsim" from library (rugarch). > I need to know (in detailed ) how the variance and mean ecuation of a > arma/garch process are calculated. > With other packages like "fGarch" i used to invoked the function debug () > and allows me to step into the functions but with ugarchsim i can't use it. > > any suggestions are well received > I reiterate the suggestion Alexios already gave you, namely that you use some of the, "many resources online to learn about R, S3, S4 etc.". Also, "how do I look at source code?" is not a finance-related question, even though you want to look at the source code of a finance-related function. > thanks > > Jamie > Best, -- Joshua Ulrich | 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] look at the underlying source code
hi someone can show me how can i get the source code of a function. Exactly, Function "ugarchsim" from library (rugarch). I need to know (in detailed ) how the variance and mean ecuation of a arma/garch process are calculated. With other packages like "fGarch" i used to invoked the function debug () and allows me to step into the functions but with ugarchsim i can't use it. any suggestions are well received thanks Jamie [[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] IBrokers: issues with combo contracts
I don't think I've tried this, so I may be wrong, but twsBAG isn't a real contract, it is for the order itself. Therefore you can't get mktData on it. Additionally, snapshot= isn't in the documentation for reqMktData. Read the docs,and then see if you can get further along. It (API and IBrokers) is intentionally tricky to prevent wide-spread self-inflicted harm ;-) And 'paper account' is a good step... Best, Jeff On 5/17/12 12:03 PM, "Alain Burt" wrote: >Hi there, > >I am having some troubles with the use of the IBrokers package on my IB >paper account. I am trying to get market data and an order execution for a >combo contract, with no success in both cases. I wonder if anyone could >help. Here is the code I tried > > > > ibg <- ibgConnect() > > > >leg1 <- twsComboLeg( conId = "79265697", > > ratio = 1, > >action = "BUY", > > exchange = "SMART") > > > >leg2 <- twsComboLeg( conId = "79265687", > > ratio = 1, > >action = "SELL", > > exchange = "SMART") > > > > reqMktData(conn = ibg, Contract = twsBAG(leg1,leg2), tickGenerics = "", >tickerId = "1", snapshot = T) > > > > placeOrder(ibg, twsBAG(leg1,leg2), twsOrder(reqIds(ibg),"BUY",1,"MKT")) > > > >About the market data, I am not getting anything, even by setting snapshot >= F. As for the order, it is placed but never executed. Could it be a >problem with contract objects created by twsBAG ? Does anyone know how to >fix these issues ? > > > >Best regards, > >Alain > > [[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] IBrokers: issues with combo contracts
Hi there, I am having some troubles with the use of the IBrokers package on my IB paper account. I am trying to get market data and an order execution for a combo contract, with no success in both cases. I wonder if anyone could help. Here is the code I tried ibg <- ibgConnect() leg1 <- twsComboLeg( conId = "79265697", ratio = 1, action = "BUY", exchange = "SMART") leg2 <- twsComboLeg( conId = "79265687", ratio = 1, action = "SELL", exchange = "SMART") reqMktData(conn = ibg, Contract = twsBAG(leg1,leg2), tickGenerics = "", tickerId = "1", snapshot = T) placeOrder(ibg, twsBAG(leg1,leg2), twsOrder(reqIds(ibg),"BUY",1,"MKT")) About the market data, I am not getting anything, even by setting snapshot = F. As for the order, it is placed but never executed. Could it be a problem with contract objects created by twsBAG ? Does anyone know how to fix these issues ? Best regards, Alain [[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] mark random rows of xts object
On Thu, 2012-05-17 at 14:01 +0200, Andreas Voellenklee wrote: > To compare results of a trading system against a > random-entry-benchmark, I'm trying to program a function that marks > random 5% of bars of a xts object. > > The result should be a xts object with the same indexes as the OHLCV > object and one column "random_entry" that contains boolean values. getSymbols('MMM') MMM$random<-0 MMM$random[sample(1:nrow(MMM),round(nrow(MMM)/20),replace=FALSE),]<-1 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] mark random rows of xts object
Hi, To compare results of a trading system against a random-entry-benchmark, I'm trying to program a function that marks random 5% of bars of a xts object. The result should be a xts object with the same indexes as the OHLCV object and one column "random_entry" that contains boolean values. I tried this without success: # returns true in 5% of calls random <- function() {runif(1,0,1) >= .95} getSymbols("MMM") > as.xts(apply(MMM, 1, random)) Fehler in FUN(newX[, i], ...) : unbenutzte(s) Argument(e) (newX[, i]) Thanks for your help, Andreas ___ 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] About rugarch (message to alexios)
Jaimie, 1. This is a mailing list so do not start a message by addressing it to one individual. 2. Following from 1, your message has no context for anyone but myself which defeats the purpose of posting to a mailing list. Your original question was: > My question is in line with function "ugarchsim". With the package > "fGarch" to be sure about what the simulation function is doing, i > used to use a function call "debug" wich allows you to make a step by > step analysis. To me it's usefull to understand, for example, how de > variance of a garch process are calculated, or the innovations, how > they have been calculated. The main purpose is to ensure that > functions are doing what i really want. The debug function allows you > to see the formulas and you can type any variable and returns it's > value. > But when i try to do the same with the function "ugarchsim", i > can't. I can't get into the formula to see the process of > calculating." I mentioned that the package uses S4 methods and classes which add a layer of abstraction on top of the code. If you do not know what these are, there are many resources online to learn about R, S3, S4 etc. The same goes about how to source the code or see under the hood (it is OPEN SOURCE). Regards, Alexios On 17/05/2012 09:36, jaimie villanueva wrote: First, I apologize because i`m not an expert using R. I'm not sure to understand you when you say "The rugarch provide an added layer of abstraction on top of the code". you mean that i can access to that added layer? Second is : How can i look at the source code? regards Jaimie ___ 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] About rugarch (message to alexios)
First, I apologize because i`m not an expert using R. I'm not sure to understand you when you say "The rugarch provide an added layer of abstraction on top of the code". you mean that i can access to that added layer? Second is : How can i look at the source code? regards Jaimie ___ 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.