# Tag Info

## Hot answers tagged r

24

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.

19

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

13

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

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

11

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

10

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

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

9

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$ $$C=e^{-rT} \int_0^\infty (S-K)^+ p(S) dS$$ Therefore we can write e^{rT} ...

7

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

7

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.

7

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

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

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

7

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.

7

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

7

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

6

Getting something up and running quickly -- i.e. data manipulation and exploration are activities R are adept at, and there are a plethora of packages to help you. Flexibility and speed (of research) are R's primary strengths. I feel memory and computing power are less expensive than the thought cycles used to explore an idea. If you're entering a ...

6

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

6

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

6

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

6

Systematic Investor also did a two part series implementation in R which is also quite helpful as he details the pitfalls too. Post One: http://systematicinvestor.wordpress.com/2012/11/01/regime-detection/ Part Two: http://systematicinvestor.wordpress.com/2012/11/15/regime-detection-pitfalls/

6

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

6

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

6

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

5

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

5

To expand on what Joshua has already stated, here is a truncated parameter list of similar functions, along with the package to which they belong. quantmod::Delt(x1,type = c("arithmetic", "log")) quantmod::periodReturn(x, type='arithmetic') # log would be "log" TTR::ROC(x, type=c("continuous", "discrete")) PerformanceAnalytics::CalculateReturns(prices, ...

5

What about customizing KNIME (Open source aswell) for this particular problem? I am no expert, just my two cent. KNIME comes with Weka(I dont mean complete Weka, but a basic machine learning functions) & R integration aswell(Importing/Exporting R codes are easy), Text Mining, Neural Nets etc. I reckon, KINME(www.knime.org) with it's enterprise ...

5

http://lobster.wiwi.hu-berlin.de/forum/viewtopic.php?f=4&t=30 R code, pictures and discussion, it's easy to modify it

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