Hot answers tagged

28

Don't have to switch -- it's not either / or after all. Use either where it has an advantage: R for explorations, modeling, ... and C++ for industrial-strength and high-performance implementations (at a possible cost in terms of time to code). And (with the obvious Rcpp plug coming) you can even combine both of them.


21

R can be pretty slow, and it's very memory-hungry. My data set is only 8 GB or so, and I have a machine with 96 GB of RAM, and I'm always wrestling with R's memory management. Many of the model estimation functions capture a link to their environment, which means you can be keeping a pointer to each subset of the data that you're dealing with. SAS was much ...


18

My deal is HFT so what I care about is read/load data from file or DB quickly in memory perform very efficient data-munging operations (group,transform) visualize easily the data I think is is pretty clear that 3. goes to R, graphics and ggplot2 and others allow you to plot anything from scratch with little effort. About 1. and 2. I am amazed reading ...


15

I am not an R advocate, but can witness that R is trivially very, very good at data analysis. It is essentially a LISP-like functional language domesticated enough to make you productive in one afternoon. It is unbeatable at getting data in your system, analyzing them, and producing high-quality output, be it latex reports or charts. I have used several ...


14

You can directly imply a probability distribution from a volatility skew. Note that, for any terminal probability distribution $p(S)$ at tenor $T$, we have the model-free formula for the call price $C(K)$ as a function of strike $K$ \begin{equation} C=e^{-rT} \int_0^\infty (S-K)^+ p(S) dS \end{equation} Therefore we can write \begin{equation} e^{rT} \...


14

This is interesting because I see another trend: Matlab is being replaced by R, but I guess this is another story. I use R for my academic (I am also teaching this stuff) as well as my consulting work (I am mainly working in the $\mathbb{P}$ area, with some excursions into $\mathbb{Q}$). I tried Python but it didn't work for me. I think the main reasons I ...


14

I've used both R and Python with Pandas in a professional quantitative financial work to do both large and small scale projects. I would strongly recommend Python with Pandas over R for most new projects in the field especially in time series analysis. While I don't dispute vonjd in that you will find more libraries in R with algorithms on the bleeding ...


13

I don't know why it was removed, but the R package "orderbook" was available: http://journal.r-project.org/archive/2011-1/RJournal_2011-1_Kane~et~al.pdf http://cran.r-project.org/web/packages/orderbook/index.html In the IBrokers package, the function "reqMktDepth" is used for streaming order book data. http://cran.r-project.org/web/packages/IBrokers/...


13

There are many specialised products for HF tick data. In addition to KDB which you mentioned, there is OneTick, Vertica, Infobright, and some open-source ones like MonetDB etc. (see http://en.wikipedia.org/wiki/Column-oriented_DBMS). My experience is that Column Oriented Databases are overrated when it comes to tick data, because very often you request the ...


12

The clearest and most intuitive article I have seen so far is Kritzman et al., Regime Shifts: Implications for Dynamic Strategies in FAJ (May / June 2012) It not only shows how you can use HMM for financial modelling but it also goes through the actual estimation algorithm (Baum-Welch) step-by-step and even gives full MATLAB-code. From the abstract: ...


12

I don't know how to select ARMA lag length when doing ARMA-GARCH. Perhaps someone can edit it into this answer. For the univariate case you want rugarch package. If you're doing multivariate stuff you want rmgarch. The reason these are better than other packages is threefold; (i) Support for exogenous variables which I haven't seen in any other package, (...


12

Instead of wild guesses about R's/python's future in the community, here some facts: The following query on StackExchange Data Explorer counts the number of questions that have <r> or <python> tags. If you scroll down on one of the three webpages provided below, you can see a graph with data on a monthly basis. You can easily run this query on ...


11

The greatest weakness and greatest strength of R is that it is not a strongly typed language. Therefore easy tasks in strongly typed languages such as re-factoring, auto-compiler checks, unit testing, etc. can be more difficult in R. On the other hand, one can rapidly prototype in the R language. R is an interpreted language -- it will dynamically convert ...


10

As a disclaimer, I'm a noted advocate of using Python to build production systems for quant finance (old talk but: http://python.mirocommunity.org/video/1531/pycon-2010-python...). I've been very successful at doing it and largely as the result of my example many other quant shops have chosen the Python route to excellent results. The pandas Python library (...


10

You are simply doing $log(S_t) - log(S_t) = 0$ for all $t$. Instead, try > n <- length(prices); > lrest <- log(prices[-1]/prices[-n]) Should do the trick.


9

A simple google search should get your started: I like this one the best because it compares different packages: http://stat-www.berkeley.edu/~brill/Stat248/kalmanfiltering.pdf and here couple more: http://www.r-bloggers.com/the-kalman-filter-for-financial-time-series/ http://cran.r-project.org/web/packages/dlm/index.html http://cran.r-project.org/...


9

It only indicates that the null hypothesis of uncorrelated increments is violated. For the sake of simplicity, assume a time series is stationary. Then a sufficient statistic for arbitrary variance ratios is its covariance function. In general, a given deviation from the null can originate from different covariance functions, which in turn, entails that ...


9

For data analysis, particularly for large data analysis project, pretty much most of the top quant hedge funds and a lot of the banks are using Python (over R) for a couple of reasons but many still have bits and pieces of R for specific packages or functions (I work at a bank and interface with quite a few quant hedge funds on data analysis): Earlier ...


8

Take a look at the sde package; specifically the dcOU and dsOU functions. You may also find some examples on the R-SIG-Finance mailing list, which would be in the results of a search on www.rseek.org.


8

If you've got a list of trades, I would first suggest using the blotter package to enter those transactions and compute your cash P&L. Then you can use the tradeStats function to see trade related statistics, or the portfReturns function to extract percent returns for your portfolio of symbols as a contribution to total account equity returns. After ...


8

The PortfolioAnalytics package will create weights without reference to current weights, if that's what you want. It should also have much of the reporting that you like from Rmetrics fPortfolio. There is a longer seminar presentation on Portfolioanalytics from 2010's R/Finance conference here: Complex Portfolio Optimization with Generalized Business ...


7

Is it worth it to learn R? Switching from C/C++ to R has increased my productivity and shrunk code line-counts for similar tasks by roughly an order of magnitude. To give a small flavor of why, consider one of the most common patterns of iteration over some collection, selection and action: declare iterator for collection for element in collection ...


7

This is the website to the R/Finance conference this year. Tons of great links. http://www.rinfinance.com/agenda/ Brian Peterson's slide (Building and Testing Quantitative Strategy Models in R) mentions Portfolio-Analytics (which I think is based on R/Metrics). And here is a paper based on Portfolio-Analytics. http://cran.r-project.org/web/packages/...


7

The code of Euler Maruyama simulation method is pretty simple (nu is long run mean, lambda is mean reversion speed): ornstein_uhlenbeck <- function(T,n,nu,lambda,sigma,x0){ dw <- rnorm(n, 0, sqrt(T/n)) dt <- T/n x <- c(x0) for (i in 2:(n+1)) { x[i] <- x[i-1] + lambda*(nu-x[i-1])*dt + sigma*dw[i-1] } return(x); }


7

So one such visualization package is demonstrated in http://www.tradeworx.com/movie/booklet_demo/temp/booklet_demo2.mov. AFAICT it looks like a tk script. Trading Technologies (TT) sells another visualization tool. But TBH writing your own tool takes a few hours and allows you to focus on what information you are interested in finding.


7

The "Component ES" section of ?ES says: For the decomposition of Gaussian ES, the estimated mean and covariance matrix are needed. For the decomposition of modified ES, also estimates of the coskewness and cokurtosis matrices are needed. The estimate of the coskewness and cokurtosis matrices are what take such a long time. You can calculate them ...


7

Here is my code: require(xts) require(urca) # Load data gld <- read.csv("~/Downloads/CBA.csv", stringsAsFactors = FALSE) gdx <- read.csv("~/Downloads/WBC.csv", stringsAsFactors = FALSE) # Convert to xts gld <- xts(gld[, 4], as.POSIXct(gld[, 1], tz = "GMT", format = "%Y-%m-%d", tzone = "GMT")) gdx <- xts(gdx[, 4], as.POSIXct(gdx[, 1], tz = "...


7

One relevant paper is: Shenoy, C. and Shenoy, P.P., Bayesian network models of portfolio risk and return, 1999. PDF


7

It appears that you are re-running the regression with each new data point. Instead, you should use an update/online formula (see an excellent answer by the famous Dr. Huber at stats.se). You can find an implementation in the R package biglm. If it doesn't have all the features you need (no windowing out of old data) you can at least adapt it and use it ...


7

I'm familiar with the library, but not with the way it is exported to R. Anyway: gearings are optional multipliers of the LIBOR fixing (some bonds might pay, for instance, 0.8 times the LIBOR) and spreads are the added spreads. In your case, the gearing is 1 and the spread is 0.0140 (that is, 140 bps; rates and spread must be expressed in decimal form). ...



Only top voted, non community-wiki answers of a minimum length are eligible