Re: [R-SIG-Finance] Equality of covariance matrices??
I hope you do not assume Gaussianity, don't you? Marc Von: r-sig-finance-boun...@r-project.org [r-sig-finance-boun...@r-project.org]" im Auftrag von "benn fine [bennf...@gmail.com] Gesendet: Sonntag, 21. Juli 2013 13:37 An: R-SIG-Finance@r-project.org Betreff: [R-SIG-Finance] Equality of covariance matrices?? HI: I know there are several likelihood ratio tests for comparing two covariance matrices but darned if I can find them coded in R. Does anyone know if they are lurking in some package? Thanks! b [[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] how to get programmatically "portfolio weights" from portfolioFrontier-Object after optimization
Hi There ! I have folowing problem. I'm using portfolioFrontier function from fPortfolio package to find optimal portfolio allocation. That what I want is when the portfolioFrontier function has the job done, I get in the r-console some print out of the found optimization object with weights, target return and so on. But I want to read this informations automatically from returned object to start other functions with this informations as parameters This Property I can call "Frontier@portfolio". But retruned object is to complex and I want to get single properties from tthere. I tried to reach single on this way properties from object Frontier@portfolio@weights Frontier@portfolio$weights but I'v got such errors "$ operator not defined for this S4 class" or "No Slot "weights" for this Objekt of the class "fPFOLIOVAL" Can anyone say to me how to get "portfolio weights" and "Target Return and Risks:", from returned object ? thanks a lot Zak [[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 storing Interactive data.
If you can't find the exact solution you want, there is a neat project that you might want to look at, TradingShim. The author, Russ Herrold, is a long-time R user. http://www.trading-shim.org/ The shim can capture your data in the background and you can easily access it from R. John On Sat, Jul 20, 2013 at 9:38 PM, ganesha0701 wrote: > I came across IBrokers, and was impressed. My goal is to save real time > data through the Interactive Brokers API and am looking to use it. > > The data I need should be in the following format > > timestamp, product, bid1Price, bid1Size, ask1Price, ask1Size,bid2Price, > bid2Size, ask2Price, ask2Size,bid3Price, bid3Size, ask3Price, > ask3Size,bid4Price, bid4Size, ask4Price, ask4Size,bid5Price, bid5Size, > ask5Price, ask5Size, last Trade Price, last Trade Size > > So basically I am looking for all the 5 levels and the last trade > information if there was any. > > I understand their API and know that I need to call the reqMarketDepth > method. The problem is that they don't really give any time stamp > information. > > So my question is can I use this package to do the above, if yes, how do > you generate the time stamp info? How do I get the last trade info? > > I would be grateful to you if you could offer any light on the matter. ___ 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 storing Interactive data.
Within IBrokers you would simply extend the eWrapper.MktDepth.CSV eWrapper method to save what you would like (and how you would like, csv in this instance). Note that the reqMktDepth call won't return Last prices, as that is within the reqMktData (IB API) call. You will instead need to have both requests running and collecting the data required. I don't have example code for this, but it wouldn't be hard to do. You could effectively share one data object within R (and the eWrappers) and update this object at each new message. You could also [more easily] use the prebuilt *.CSV methods in the package to save the incoming messages to individual files, and then use standard R/xts tools to rebuild the book at whatever granularity you wanted. In short, the tools are all there, you just need to cut/paste/borrow/extend to convert the messages into whatever form you want. With respect to timestamps, you are 100% correct that they are not provided by the API for most data. I do think Last has something of a timestamp attached, though I don't think the default wrappers are using it. Instead the timestamps are getting created when the message is processed. This gives a more realistic view into when you can act on the data anyway, but clearly isn't the only solution you could desire - especially for the Last value. If I get a chance to provide a working example, I will pass along. HTH Jeff P.S. As John's follow-up mentions, the shim is a pretty neat bit of code. Russ is a regular at the R/Finance conferences as well, and a stellar resource on the topic. Take a look at both of these set-ups to figure out how you can solve your problem. ex (not tested, and probably missing something since I am writing this quickly from memory - though it is all documented in the package and/or slide decks I've given): tws <- twsConnect() reqMktDepth(tws, twsSTK("AAPL"), eventWrapper=eWrapper.MktDepth.CSV(), file='aapl.mkdepth.csv') Calls ===> > eWrapper.MktDepth.CSV function () { eW <- eWrapper(NULL) eW$updateMktDepth <- function(curMsg, msg, timestamp, file, ...) { e_update_mkt_depth_csv(NULL, msg, timestamp, file, ...) } eW } ### at each new message. > IBrokers:::e_update_mkt_depth function (msg, contents, timeStamp, file, ...) { id <- as.numeric(contents[2]) file <- file[[id]] if (!is.null(timeStamp)) cat("<", as.character(timeStamp), ">,", sep = "", file = file, append = TRUE) position <- contents[3] operation <- switch(contents[4], `0` = "insert", `1` = "update", `2` = "delete") side <- ifelse(contents[5] == "1", "bid", "ask") price <- contents[6] size <- contents[7] cat(paste("id=", id, ",", sep = ""), file = file, append = TRUE) cat(paste("pos=", position, ",", sep = ""), file = file, append = TRUE) cat(paste("operation=", operation, ",", sep = ""), file = file, append = TRUE) cat(paste("side=", side, ",", sep = ""), file = file, append = TRUE) cat(paste("price=", price, ",", sep = ""), file = file, append = TRUE) cat(paste("size=", size, sep = ""), "\n", file = file, append = TRUE) } > On Sat, Jul 20, 2013 at 11:38 PM, ganesha0701 wrote: > I came across IBrokers, and was impressed. My goal is to save real time > data through the Interactive Brokers API and am looking to use it. > > The data I need should be in the following format > > timestamp, product, bid1Price, bid1Size, ask1Price, ask1Size,bid2Price, > bid2Size, ask2Price, ask2Size,bid3Price, bid3Size, ask3Price, > ask3Size,bid4Price, bid4Size, ask4Price, ask4Size,bid5Price, bid5Size, > ask5Price, ask5Size, last Trade Price, last Trade Size > > So basically I am looking for all the 5 levels and the last trade > information if there was any. > > I understand their API and know that I need to call the reqMarketDepth > method. The problem is that they don't really give any time stamp > information. > > So my question is can I use this package to do the above, if yes, how do > you generate the time stamp info? How do I get the last trade info? > > I would be grateful to you if you could offer any light on the matter. > > [[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.
Re: [R-SIG-Finance] Equality of covariance matrices??
You can compare correlation matrices using Kullback-Leibler divergence. There is an implementation in my package tawny on CRAN. library(tawny) divergence.kl(sigma.1, sigma.2) Brian > I know there are several likelihood ratio tests for comparing two > covariance matrices but darned if I can find them coded in R. Does anyone > know if they are lurking in some package? ___ 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] create data frame with coefficients from many regressions
Hi ! I want to ask if somebody knows the way to create data frame with coefficients from many regressions I regress the first column from ret against the first columns from median, then the second with the second and so on. This is the code used for regression i<-1:6 lapply(seq_len(ncol(ret)),function(i) {lm(ret[,i]~median[,i])} I get 6 results for each regression [[1]] Call: lm(formula = ret[, i] ~ median[, i]) Coefficients: (Intercept) median[, i] 01 [[2]] Call: lm(formula = ret[, i] ~ median[, i]) Coefficients: (Intercept) median[, i] -1.411e-171.000e+00 now I would like to create a data frame with intercepts which looks like it [[1]] [[2]] Intercept median I tried to use ddply command but it does not work. I will be very grateful for the hint :) Thank you in advance ___ 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 data frame with coefficients from many regressions
summary(lm(y ~ x))$coef[1,] gives you the intercept, standard error, p-value etc. then write a function and use lapply( yourlist, function) Am 2013-07-22 1:54 PM, schrieb iza.ch1: Hi ! I want to ask if somebody knows the way to create data frame with coefficients from many regressions I regress the first column from ret against the first columns from median, then the second with the second and so on. This is the code used for regression i<-1:6 lapply(seq_len(ncol(ret)),function(i) {lm(ret[,i]~median[,i])} I get 6 results for each regression [[1]] Call: lm(formula = ret[, i] ~ median[, i]) Coefficients: (Intercept) median[, i] 01 [[2]] Call: lm(formula = ret[, i] ~ median[, i]) Coefficients: (Intercept) median[, i] -1.411e-171.000e+00 now I would like to create a data frame with intercepts which looks like it [[1]] [[2]] Intercept median I tried to use ddply command but it does not work. I will be very grateful for the hint :) Thank you in advance ___ 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 data frame with coefficients from many regressions
The results of an lapply call can be joined together easily with do.call(cbind or do.call(rbind or do.call(c. Though what you need is probably requiring one additional step to use a custom function to get the result you want in some sensible structure for the above. This isn't at all a finance question though. Should be redirected to r-help. Thanks Jeff Jeffrey Ryan|Founder|jeffrey.r...@lemnica.com www.lemnica.com On Jul 22, 2013, at 12:54 PM, "iza.ch1" wrote: > Hi ! > > I want to ask if somebody knows the way to create data frame with > coefficients from many regressions > I regress the first column from ret against the first columns from median, > then the second with the second and so on. > This is the code used for regression > > i<-1:6 > lapply(seq_len(ncol(ret)),function(i) {lm(ret[,i]~median[,i])} > > I get 6 results for each regression > > [[1]] > > Call: > lm(formula = ret[, i] ~ median[, i]) > > Coefficients: > (Intercept) median[, i] > 01 > > > [[2]] > > Call: > lm(formula = ret[, i] ~ median[, i]) > > Coefficients: > (Intercept) median[, i] > -1.411e-171.000e+00 > > now I would like to create a data frame with intercepts which looks like it > >[[1]] [[2]] > Intercept > median > > I tried to use ddply command but it does not work. I will be very grateful > for the hint :) > > Thank you in advance > > ___ > 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?
Jim, Thanks for noticing this. It was a separate issue in updateAcct that was hidden by the timezone issue. Should be fixed in rev1484. Best, -- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com On Sun, Jul 21, 2013 at 9:01 PM, Jim Green wrote: > updated to v1483, saw this error running longtrend.R > > [1] "Setting up indicators" > [1] "Initializing portfolio and account structure" > . > [1] "1998-10-30 00:00:00 GSPC 91 @ 1098.67" > Error in periodicity(table) : > can not calculate periodicity of 1 observation > In addition: There were 14 warnings (use warnings() to see them) >> sessionInfo() > R version 3.0.0 (2013-04-03) > 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 > LC_MONETARY=en_US.UTF-8 > [6] LC_MESSAGES=en_US.UTF-8LC_PAPER=C LC_NAME=C > LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] graphics utils datasets stats grDevices methods base > > other attached packages: > [1] blotter_0.8.14 PerformanceAnalytics_1.1.0 > FinancialInstrument_1.1.9 quantmod_0.4-0 TTR_0.22-0.1 > [6] xts_0.9-5.1zoo_1.7-10 Defaults_1.1-1 > > loaded via a namespace (and not attached): > [1] grid_3.0.0 lattice_0.20-15 > > > > On 21 July 2013 21:34, Joshua Ulrich wrote: >> >> Mark, >> >> It's been awhile, but I finally looked at this and patched it in >> revision 1483. It's forces the session timezone to UTC... not ideal, >> but it works. >> > ___ 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?
On Mon, Jul 22, 2013 at 2:38 PM, Joshua Ulrich wrote: > Jim, > > Thanks for noticing this. It was a separate issue in updateAcct that > was hidden by the timezone issue. Should be fixed in rev1484. > > Best, > -- > Joshua Ulrich | about.me/joshuaulrich > FOSS Trading | www.fosstrading.com Hey Joshua, Thanks for looking into this and no worries about the delay. Question: I'm working in R-Studio in Windows 7. When I look at the packages tab it says my version of blotter is 0.8.14 and no updates appear to be available. (Or rather, I did whatever updates it offered and that's the version I have. Anyway, I think I downgraded R to version 2.15.3 back when I was trying this stuff out. I'd like to move to a newer version if it's supported. Maybe I just need to wait a few days for your newer package to show up on CRAN @ Bezerkley? Inputs? 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.
Re: [R-SIG-Finance] Do the blotter demos work?
Mark, on windows you can use tortoise svn to checkout the trunk source code, build and install if you don't want to wait the path is: svn checkout svn://svn.r-forge.r-project.org/svnroot/blotter/ Jim [[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] Do the blotter demos work?
On Mon, Jul 22, 2013 at 3:14 PM, Jim Green wrote: > Mark, on windows you can use tortoise svn to checkout the trunk source code, > build and install if you don't want to wait > > the path is: > svn checkout svn://svn.r-forge.r-project.org/svnroot/blotter/ > > Jim Thanks Jim. As I'm focused on a lot of things in R right now I think I'll wait a while and see what shows up. If I get some time then I'll give that a try. Cheers, 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.
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] Do the blotter demos work?
On Mon, Jul 22, 2013 at 4:27 PM, G See wrote: > 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 Thanks Garrett, I installed as per your suggestion. No errors but I still see 0.8.14. Maybe that's right, or possibly wrong. I don't know how that number matches Joshua's version number of 1484. Unfortunately when I run the longtrend demo it fails: > demo(longtrend, package="blotter") demo(longtrend) ~ Type to start : > # This is a very simple trend following strategy for testing the results of: > # Faber, Mebane T., "A Quantitative Approach to Tactical Asset Allocation." > # Journal of Risk Management (Spring 2007). + # Calculate P&L and resulting equity with blotter + updatePortf(ltportfolio, Dates = CurrentDate) + updateAcct(ltaccount, Dates = CurrentDate) + updateEndEq(ltaccount, Dates = CurrentDate) + } # End dates loop . [1] "1998-10-30 00:00:00 GSPC 91 @ 1098.67" Error in lag.xts(TmpPeriods$Pos.Value, 1) : abs(k) must be less than nrow(x) In addition: There were 16 warnings (use warnings() to see them) I'll be happy to try things out if it helps the group but someone will have to make suggestions. If this requires a newer version of xts or something else then I'd appreciate knowing where to look to figure that out. 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] day/month/year functions?
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.
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 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] day/month/year functions?
Maybe, library(lubridate)x <- ymd("2012-03-26")year(x)month(x)day(x) Daniel Merino 2013/7/22 Mark Knecht > 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. > -- Daniel [[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] Finding price difference of a time series
Hi R users, # How to find price difference of a-b and c-d ?. require(quantmod) require_symbol <- function(symbol, envir = parent.frame()) { if (is.null(envir[[symbol]])) { envir[[symbol]] <- getSymbols(symbol, auto.assign = FALSE) } envir[[symbol]] } # Create an environment for storing data symbol_env <- new.env() s1="SPY" s2="GOOG" A<- require_symbol(s1, symbol_env) B<- require_symbol(s2, symbol_env) x1=A[,6] x2=B[,6] a=head(x1,1) b=tail(x1,1) c=head(x2,1) d=tail(x2,1) J=a-b I got the following messages. > J Data: numeric(0) Index: numeric(0) > str(J) An 'xts' object of zero-width with regards. veepsirtt -- View this message in context: http://r.789695.n4.nabble.com/Finding-price-difference-of-a-time-series-tp4672099.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.