Elite Trader

Elite Trader (http://www.elitetrader.com/vb/index.php)
-   Programming (http://www.elitetrader.com/vb/forumdisplay.php?f=65)
-   -   R for datamining/backtesting/trading (http://www.elitetrader.com/vb/showthread.php?t=238107)

caementarius Mar 6th, 2012 01:40 AM

R for datamining/backtesting/trading
 
I've used a few platforms for strategy development. I always seem to come up against obstacles where I might as well write my own stuff rather than go through the gymnastics to get what I want out of the platform. For example, NinjaTrader felt weird to try to access more than 1-2 securities prices at a time (needed to wrap them into a derived indicator, if I remember correctly). With tradelink, not everything worked out of the box - so there was tweaking to be done plus data management was clunky.

With R/quantmod and other modules, there is some nice open-source work mostly approached from an academic angle.

The academic angle uses vector operations and can make for some nice succinct functional code. See this backtest in just a few lines of R script:
http://blog.fosstrading.com/2011/03/...tegy-in-r.html

But, using vector operations isn't great when you want to switch to an event-driven model that responds to new bars or new ticks - like what happens when you want to run on live data and generate signals. And, more path-dependent trade logic expands the number of vectors needed until it's more messy than it's worth. The nice thing about NT and tradelink is that they are built from the ground up to run the same code whether you are backtesting or running live.

Overarching all of this is my belief that I am likely better served developing systems by first exploring relationships in data and then seeing what might be a trade.

So, I think R might be the way - but when I use it, iterating over bar data, it feels like I'm doing it wrong by introducing flow control into a functional language.

Has anyone made R their "home" for everything (mining+testing+live signals)? Or - If you've been down the same road building your own tools for the whole process, what technologies did you settle on?

tradelink Mar 6th, 2012 11:54 AM

"Overarching all of this is my belief that I am likely better served developing systems by first exploring relationships in data and then seeing what might be a trade.

A pretty common thing among tradelinkers is to use R or matlab for analysis and modeling, then use tradelink for heavy backtesting and live trading.

this is why tradelink has R/matlab/excel hooks in every application.

"So, I think R might be the way - but when I use it, iterating over bar data, it feels like I'm doing it wrong by introducing flow control into a functional language."

It shouldn't be necessary to iterate

tlindicators<-read.csv("indicatorsFromGauntletRun.csv")

price<-tlindicators[,3]
time<-tlindicators[,1]

plot(time,price)

linearmodel <- lm(price~time)
abline(linearmodel)

Rodney King Mar 6th, 2012 12:13 PM

Re: R for datamining/backtesting/trading
 
Quote:

Quote from caementarius:

See this backtest in just a few lines of R script: http://bit.ly/jhvufT
This isn't really "a few lines of R," it's a script invoking the functionality of several very good finance-specific R add-on packages with their own quirks and fiddly bits, that are quite complex internally.

caementarius Mar 6th, 2012 12:19 PM

Re: Re: R for datamining/backtesting/trading
 
Quote:

Quote from Rodney King:

This isn't really "a few lines of R," it's a script invoking the functionality of several very good finance-specific R add-on packages with their own quirks and fiddly bits, that are quite complex internally.
correct:

Quote:

Quote from caementarius:

With R/quantmod and other modules, there is ...

I like R for exploration, like how tradelink just posted. My point is that the trade logic and order matching are clunky and unnatural (that's where I'm iterating over bars, keeping orders in data frames, bleah).

What I'm trying to find, or simply just lamenting about, is exploration using nice tools and ability to deploy a model with trading logic without rewriting it in tradelink (or NT, or..) for realtime use.

tradelink Mar 6th, 2012 12:30 PM

Once you have found a relationship that is stable and exploitable, it's fairly easy to port this to tradelink.

One option is R embed, and calling your routines via a dll in TL.

Another option is calling R routines via a scripted interface. There's a plan to import a module we use to simplify this in TL (import it into the TL project).

A third option if you really want to do actual trading in R, sent you a PM about that.

Rodney King Mar 6th, 2012 03:02 PM

Quote:

Quote from tradelink:

A third option if you really want to do actual trading in R, sent you a PM about that.
http://cran.r-project.org/web/packag...ers/index.html, or something superspecialsecret that requires a private message?


All times are GMT -4. The time now is 08:35 AM.