Tag Archives: HFT

Video of R, RCPP, RInside makes use of C++ so much easier than Matlab Builder NE for high frequency trading aka HFT potential

Video of R, RCPP, RInside makes use of C++ so much easier than Matlab Builder NE for high frequency trading aka HFT potential

So I am going from trying out an open source C# application trading platform to an open source C++ ‘platform’ using Interactive Brokers. I also switched from Matlab to R. Lastly; I am looking at more open source projects including Linux where Ubuntu is becoming my preferred distribution. As you can tell, I am straying away from expensive options like Matlab. Being a developer, I can quickly debug most applications if need be.

The benefit I am finding switching to R as compared to using Matlab with something like Matlab’s Builder JA (for Java) or Builder NE (for .NET languages like C#) toolboxes. When I tried out the combination of R packages RCpp and RInside, I was pleasantly surprised for a number of things. Installing any R package is quite easy. Building or ‘making’ the provided C++ examples for RInside was flawless and easy to execute. The most impressive were samples of parallelization of C++ which was jaw dropping.

Now I am hoping I can see my newer open source C++ trading solution Trading Shim (http://www.tradingshim.org/) will work at some point as well.   Hey…it is C++ so leave it alone. But the speed and scalability of it should be impressive. I just wish there was a complete open source trading platform in Java that could connect to my chosen broker Interactive Brokers.

Anyhow, back to the R packages of RCpp and Rinside. I need to give a shout out to the contributors for making these packages happen in a quick and easy way. The provided C++ examples really do make a difference to showcase how a C++ application can call the R shell processor and execute individual R functions directly. You could not do that with the Matlab NE Builder as you could only call M scripts with their archaic programming structure. The C++ code within RInside as compared to Matlab NE is much simpler, tighter, and smaller. The Matlab NE Builder is really meant for C# so trying it in Visual C++ would have been ‘interesting.’ I am just glad I found this deadly combination of R, RCpp/Rinside, with C++. It may work well for my hopeful high frequency trading platform with R for prototyping and analytics.

[youtube_sc url=”http://www.youtube.com/watch?v=wIzrJFy-VCA” playlist=”Calling R from a C application for HFT development with MPI parallelzation ” title=”Calling%20R%20from%20a%20C%20application%20for%20HFT%20development%20with%20MPI%20parallelzation%20″]

Crucial and many helpful R packages and research papers for finance and HFT with quant model, algo, and strategy example

Crucial and many helpful R packages and research papers for finance and HFT with quant  model, algo, and strategy example

Note none of these have NOT been verified or validated yet but don’t mind me, I feel like a kid in a candy factory with these!

With Interactive Brokers and R:

http://blog.fosstrading.com/2010/05/introducing-ibrokers-and-jeff-ryan.html

http://cran.r-project.org/web/packages/IBrokers/vignettes/RealTime.pdf

Implied volatility:

http://www.r-bloggers.com/the-only-thing-smiling-today-is-volatility/

For volatility forecasting using GARCH

http://www.r-bloggers.com/trading-using-garch-volatility-forecast/

Time series analysis and computational finance Cointegration test

www.stat.ucl.ac.be/ISdidactique/Rhelp/library/tseries/html/00Index.html
urca R package with Conintegration
http://cran.r-project.org/web/packages/urca/index.html

http://global-4-lvs-colossus.opera-mini.net/hs36-13/15877/1/-1/cran.r-project.org/urca.pdf

Limit Order Book R package

http://r-forge.r-project.org/R/?group_id=790  <– not in CRAN but does not seem to have a download link
Engle Granger coefficient test

http://cran.r-project.org/web/packages/tsDyn/tsDyn.pdf
CRAN – Package crawl random walk theory

http://cran.r-project.org/web/packages/crawl/index.html

Time series analysis in r (includes autocorrelation p17)

http://www.statoek.wiso.uni-goettingen.de/veranstaltungen/zeitreihen/sommer03/ts_r_intro.pdf
Ljung box test in r (includes times series)

Ljung Box part of this: http://www.statoek.wiso.uni-goettingen.de/veranstaltungen/zeitreihen/sommer03/ts_r_intro.pdf

http://cran.r-project.org/doc/contrib/Ricci-refcard-ts.pdf

Auto regressive estimation model
http://cran.r-project.org/web/packages/cts/vignettes/kf.pdf

Auto regressive is part of http://quantlabs.net/r-blog/2012/05/excellent-tutorial-on-using-urca-r-package-for-var-cointegration-statistical-tests-non-stationary-processes-benchmarks-and-estimating-models/
R time series pair trading Engle and Granger cointegartion
http://cran.r-project.org/web/packages/PairTrading/PairTrading.pdf
Volatility models
http://cran.r-project.org/web/packages/realized/realized.pdf
Brownian Motion
http://cran.r-project.org/web/packages/sde/sde.pdf
Non parametric regression estimation
http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-nonparametric-regression.pdf
Time based arbitrage opportunities
http://www.r-bloggers.com/time-based-arbitrage-opportunities-in-tick-data/

Bid Ask spread with tick data rtaq R package
http://cran.r-project.org/web/packages/RTAQ/RTAQ.pdf
Tick data bid ask spread
http://cran.r-project.org/web/packages/FinTS/FinTS.pdf
High frequency data analysis in r with taq data base
http://faculty.washington.edu/ezivot/research/hfanalysis.pdf
Probability of observing k arrivals

http://cran.r-project.org/web/packages/HMM/HMM.pdf
Note Amihud reference of cran in the following research paper:

http://poseidon01.ssrn.com/delivery.php?ID=595118123002081089030087126071081068052035058029030050009002086102005018011112069076118021122027111056019097028001082100025005051092069006116118100098122075080031073081071095115105007093083028120122&EXT=pdf
Info and market impact

http://www.econ.kuleuven.be/public/n09022/RTAQ_vignette.pdf
Most profitable hedge fund strategy in r

http://www.r-bloggers.com/most-profitable-hedge-fund-style/
Econometric Analysis of Financial Market Data

http://www.math.uncc.edu/~zcai/FE-notes.pdf

PCA in R

http://www.r-bloggers.com/principal-component-analysis-use-extended-to-financial-economics-part-2/
Statistical arbitrage in r

http://www.r-bloggers.com/most-profitable-hedge-fund-style/

Dynamic modeling of mean-reverting spreads for statistical arbitrage

http://imperial.academia.edu/GiovanniMontana/Papers/1104540/Dynamic_modeling_of_mean-reverting_spreads_for_statistical_arbitrage

CAPM n r (note PerformanceAnalytics R package may be just as effective)
http://cran.r-project.org/web/packages/BLCOP/vignettes/BLCOP.pdf
Package RTAQ liquidity arbitrage

http://cran.r-project.org/web/packages/RTAQ/index.html

Crucial and many helpful R packages and research papers for finance and high frequency trading with a quant  model, algo, and strategy example

Note none of these have NOT been verified or validated yet but don’t mind me, I feel like a kid in a candy factory with these!

With Interactive Brokers and R:

http://blog.fosstrading.com/2010/05/introducing-ibrokers-and-jeff-ryan.html

http://cran.r-project.org/web/packages/IBrokers/vignettes/RealTime.pdf

Implied volatility:

http://www.r-bloggers.com/the-only-thing-smiling-today-is-volatility/

Time series analysis and computational finance Cointegration test

www.stat.ucl.ac.be/ISdidactique/Rhelp/library/tseries/html/00Index.html
urca R package with Conintegration
http://cran.r-project.org/web/packages/urca/index.html

http://global-4-lvs-colossus.opera-mini.net/hs36-13/15877/1/-1/cran.r-project.org/urca.pdf

Limit Order Book R package

http://r-forge.r-project.org/R/?group_id=790
Engle Granger coefficient test

http://cran.r-project.org/web/packages/tsDyn/tsDyn.pdf
CRAN – Package crawl random walk theory

http://cran.r-project.org/web/packages/crawl/index.html

Time series analysis in r (includes autocorrelation p17)

http://www.statoek.wiso.uni-goettingen.de/veranstaltungen/zeitreihen/sommer03/ts_r_intro.pdf
Ljung box test in r (includes times series)

http://cran.r-project.org/doc/contrib/Ricci-refcard-ts.pdf
Auto regressive estimation model
http://cran.r-project.org/web/packages/cts/vignettes/kf.pdf
R time series pair trading Engle and Granger cointegartion
http://cran.r-project.org/web/packages/PairTrading/PairTrading.pdf
Volatility models
http://cran.r-project.org/web/packages/realized/realized.pdf
Brownian Motion
http://cran.r-project.org/web/packages/sde/sde.pdf
Non parametric regression estimation
http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-nonparametric-regression.pdf
Time based arbitrage opportunities
http://www.r-bloggers.com/time-based-arbitrage-opportunities-in-tick-data/

Bid Ask spread with tick data rtaq R package
http://cran.r-project.org/web/packages/RTAQ/RTAQ.pdf
Tick data bid ask spread
http://cran.r-project.org/web/packages/FinTS/FinTS.pdf
High frequency data analysis in r with taq data base
http://faculty.washington.edu/ezivot/research/hfanalysis.pdf
Probability of observing k arrivals

http://cran.r-project.org/web/packages/HMM/HMM.pdf
Note Amihud reference of cran in the following research paper:

http://poseidon01.ssrn.com/delivery.php?ID=595118123002081089030087126071081068052035058029030050009002086102005018011112069076118021122027111056019097028001082100025005051092069006116118100098122075080031073081071095115105007093083028120122&EXT=pdf
Info and market impact

http://www.econ.kuleuven.be/public/n09022/RTAQ_vignette.pdf
Most profitable hedge fund strategy in r

http://www.r-bloggers.com/most-profitable-hedge-fund-style/
Econometric Analysis of Financial Market Data

http://www.math.uncc.edu/~zcai/FE-notes.pdf

PCA in R

http://www.r-bloggers.com/principal-component-analysis-use-extended-to-financial-economics-part-2/
Statistical arbitrage in r

http://www.r-bloggers.com/most-profitable-hedge-fund-style/

Dynamic modeling of mean-reverting spreads for statistical arbitrage

http://imperial.academia.edu/GiovanniMontana/Papers/1104540/Dynamic_modeling_of_mean-reverting_spreads_for_statistical_arbitrage

CAPM n r (note PerformanceAnalytics R package may be just as effective)
http://cran.r-project.org/web/packages/BLCOP/vignettes/BLCOP.pdf
Package RTAQ liquidity arbitrage

http://cran.r-project.org/web/packages/RTAQ/index.html

The mother load of R packages for financial trading, quant, and potential high frequency trading (HFT) needs

The mother load of R packages for financial trading, quant, and potential high frequency trading (HFT) needs

So there seems to be this endless supply of what look to be a decent list of R finance packages. Some of these include quant based ones. This is my first day researching so I cannot vouch for any of these yet. I do know some R packages can be duds but I am not sure if these ones will be either but are part of CRAN which says positive things. Here we go:

Extreme value analysis:

http://cran.r-project.org/web/packages/evir/evir.pdf

Refer to p 39 for parameter use in Gvt:

http://www.stat.colostate.edu/graybillconference2009/Workshop%20Files/ShortCourseGraybill.pdf

 

 

Potential fat tail analysis which lead to the ones below:

http://braverock.com/brian/R/PerformanceAnalytics/html/Return.Geltner.html

PerformanceAnalytics package is quite amazing and easy to use for the amount of analysis it has: i.e. VaR

http://r.789695.n4.nabble.com/Value-at-risk-td3516991.html

Overview and demo of PerformanceAnalytics (PA):

http://cran.r-project.org/web/packages/PerformanceAnalytics/vignettes/PerformanceAnalyticsChartsPresentation-Meielisalp-2007.pdf

http://www.rinfinance.com/RinFinance2009/presentations/PA%20Workshop%20Chi%20RFinance%202009-04.pdf

How read profitable data and convert to PA package

http://quant.stackexchange.com/questions/1536/use-trades-as-input-for-performanceanalytics

How to back test strategies with PA:

http://blog.fosstrading.com/2011/03/how-to-backtest-strategy-in-r.html

A technical package:

http://cran.r-project.org/web/packages/TTR/index.html

TradeAnalytics packages which includes quantstrat:

 

 

http://cran.r-project.org/web/packages/TTR/index.html

Intro to quantstrat:

http://blog.fosstrading.com/2011/08/introduction-to-quantstrat.html

General list of R packages for quant trading:

http://blog.fosstrading.com/2011/08/introduction-to-quantstrat.html

The motherload of all financial trading packages in CRAN:

http://cran.wustl.edu/web/views/Finance.html

I feel like a kid a candy factory with all this. Makes me wonder how Matlab is going to keep up. Wow! Thanks to all contributors above for all these. Now I have to start digging and play with everything. I will also keep reporting through this blog for those interested.

 

Advantages of R in high frequency trading with Redis NOSQL, doRedis, dot NET C# HFT on Linux and Windows

Advantages of R in high frequency trading with Redis NOSQL, doRedis, dot NET C# HFT on Linux and Windows

I talk about the advantages of this stack for an High Frequency Trading environment. This of couse includes the advantages of R over something like Matlab.

[youtube_sc url=”9QsWeqwyxa0″ playlist=”HFT with Redis NOSQL, R doRedis dot NET C Sharp trading platform on Linux and Windows ” title=”HFT%20with%20Redis%20NOSQL,%20R%20doRedis%20dot%20NET%20C%20Sharp%20trading%20platform%20on%20Linux%20and%20Windows%20″]

Here is an example doRedis R interation in RStudio with a remote Redis server:

registerDoRedis(queue=’jobs’,host=”192.168.2.15″,port=6379)
> library(‘doRedis’)
Loading required package: rredis
Loading required package: foreach
foreach: simple, scalable parallel programming from Revolution Analytics
Use Revolution R for scalability, fault tolerance and more.
http://www.revolutionanalytics.com
Loading required package: iterators
> registerDoRedis(‘jobs’)

> registerDoRedis(‘jobs’,’92.168.2.15′,’6379′)

> registerDoRedis(queue=’jobs’,host=’92.168.2.15′,port=’6379′)

> registerDoRedis(queue=’jobs’,host=’192.168.2.15′,port=’6379′)
> startLocalWorkers(n=2,queue=’jobs’,host=’192.168.2.15′,port=’6379′)
> removeQueue(‘jobs’)
[1] TRUE
> startLocalWorkers(n=2,queue=’jobs’,host=’192.168.2.15′,port=’6379′)
> startLocalWorkers(n=2,queue=’jobs’,host=’192.168.2.15′,port=’6379′)
> removeQueue(‘jobs’)
[1] TRUE
> startLocalWorkers(n=2,queue=’jobs’,host=’192.168.2.15′,port=’6379′)
> foreach(icount(10),.combine=sum,.multicombine=TRUE,.inorder=FALSE) %dopar% 4*sum((runif(1000000)^2 + runif(1000000)^2)<1)/10000000
[1] 3.141388

From http://cran.r-project.org/web/packages/doRedis/vignettes/doRedis.pdf