Tag Archives: Code

Walkthru and code of Karen Super Trader strategyy with CSharp Postgres SQL IQFeed Interactive Brokers

Walkthru and code of Karen Super Trader strategy with CSharp Postgres SQL IQFeed Interactive Brokers

Here i Visual Studio 2013 solution projects

Continue reading

R Code for for charting Daily Crude Oil Futures spread of calendar spread of first two months

This came in from the NYC Contact which could be very very useful for y’all. More to come!

R Code for for charting Daily Crude Oil Futures spread (calendar spread of first two months) .

The chart shows mean reversion and volatility. Extreme contango has happened several times.
Here is the R code:

CL1 = read.csv('http://www.quandl.com/api/v1/datasets/CHRIS/CME_CL1.csv?&trim_start=1983-03-31&trim_end=2014-03-24&sort_order=desc', colClasses=c('Date'='Date'))

CL2 = read.csv('http://www.quandl.com/api/v1/datasets/CHRIS/CME_CL2.csv?&trim_start=1983-03-30&trim_end=2014-03-24&sort_order=desc', colClasses=c('Date'='Date'))

CL_Spread["Date"] = CL1["Date"]

CL_Spread["Settle"] = CL1["Settle"] - CL2["Settle"]

rdate fix(rdate)
plot(CL_Spread$Settle~rdate, type="l",col="blue",axes=F)
box()
axis(1,rdate,format(rdate,"%m-%y"))
axis(2,CL_Spread$Settle)

Here is a Youtube Video Series on How to Write Fast R Code

Here is a Youtube Video Series on How to Write Fast R Code

One of my Quant Finance Meetup members, Alon, has put up two videos in a series about speeding up the execution of R. It was a presentation he did a few months ago to the group. Thanks to him for these videos and presenting.

This is an instructional video on increasing the speed with which R code is executing. It is mostly related to tricks in the R syntax that substantially decrease the time it takes for R to execute code.  There are 12 different tricks in the tutorial to increasing the efficiency of your code. Specific replicable examples are given so that you can try them at home. The neatest thing about these techniques is that they do not require any additional tools beyond the standard R Build. I have decreased the time it takes for a complex simulation from 15 minutes to less than 2 without using any compiled languages!!!

[youtube_sc url=”http://www.youtube.com/watch?v=d6cDjY6lfgI” playlist=”r fast code”]

[youtube_sc url=”http://www.youtube.com/watch?v=CDvf5Wzw584″ playlist=”r fast code part 2″]

 

The HUGE edge of Matlab over R is the Matlab Coder Toolbox. Converting R script code to C++/C?

The HUGE edge of Matlab over R is the Matlab Coder Toolbox. Converting R script code to C++/C?

I was reading the various links from the fantastic Stack Overlflow:

http://stackoverflow.com/questions/9154383/converting-loop-from-r-to-c-using-rcpp

http://stackoverflow.com/questions/10089754/converting-models-in-matlab-r-to-c-java

It seems the RCPP R package always come up in name. It is that or a derivative like RCPPArmadillo. I have played with RCpp which is really good. I am very impressed with it but when you look  at the equivalent from the Matlab world, it seems that your choices are Matlab Builder JA or Matlab Builder NE toolboxes. For those new to it, you also need to include the Matlab Compile Runtime which can lead your target application potentially extra heavy so why go there. Also, the code you need to develop to be compliant with the MCR is ugh…. how shall we say?  Extra long and wonky. Boo to that on that one.

I have experimented the various equivalent R packages of RCPP/Rinside, RJava, and R.Net which work really well. You can also make direct calls into R from these languages with little hassle compared to Matlab’s way. It seems slightly fast also since the loading of R can be very lightweight. Very cool.

But that brings me to a very important question that Matlab does have an edge. It is called Matlab Coder Toolbox which is very cool. Introduced last year, it allows you to truly convert your Matlab M Script into C or C++. It is very cool but offers limited support for the Matlab toolboxes. The functions I wanted to use were not supported but the current version of Matlab might address that. If your M script does not use any toolboxes, you can definitely use this Coder toolbox as an option. It is very cool in how it works but it is very expensive. Try $6000 but it might be worth it since you no longer need to hire a $100+K C++ developer. This is one option that Matlab has which R does not.

I hope someone can crack this code despite using something like RCpp. I think a tool to convert to C++ like the Matlab Coder would be completely awesome but I am sure this would not be a cheap R package. The amount of work would be huge.
Try joining my New R/Matlab users Meetup group.