Tag Archives: How to

My video demo and introductory checklist on how to debug with R and Eclipse IDE

My video demo and introductory checklist on how to debug with R and Eclipse IDE

Install instructions to debug R with R

Install correct Eclipse version plugin from and follow instructions:

http://www.walware.de/

Also, ensure to install RJ R package dependency as well at.

Ie. Use in R:

install.packages(c(“rj”, “rj.gd”), repos=”http://download.walware.de/rj-1.1″)

Note during the Eclipse Stat ET plugin install, it may complain about not finding any dependency plugins. I just installed everything offered as I don’t have time to monkey around with this. My Eclipse version was Indigo or 3.7.

Original testing Rsource came from:

http://navisan.com/Articles/EclipseRHTML.aspx

Once everything is installed and correctly configured within Eclipse, make sure to switch to your Stat ET perspective. I have verified the above does work properly with the correct versions once the plug in and proper Eclipse version is lined up. Don’t forget that R package as well!

If your run test fails, check the trouble shooting guide at the end of  http://navisan.com/Articles/EclipseRHTML.aspx

Note everything runs as it should.

To debug in Eclipse

Go to the near the end of the above link to the optional debug R package to be installed. This is called debug so ensure it is installed in to your R environment. You can do all this from within the R console within Eclipse. Pretty neat. It is not as nice as RStudio’s install package console but you do need to install within Eclipse manually. You obviously use the library R function for this as indicated in this image.

http://navisan.com/Articles/EclipseFiles/Eclipse_RDebuggerLoaded.jpg

Debugging
To debug, make sure your test code is an R function like:

# TODO: Add comment

#

# Author: mark qu

################################################################

# some test code…

myFunction <- function(x)

{

                a = 2

                b = 3

                c = a+b

                c

}

Note the last image screen capture and comments at the end of the navisan.com link:

Debugging with the R debugger under Eclipse StatET. Note the mtrace debug statement, which kicks off the debug session upon the function, and the subsequent function call that is then intercepted by the debugger at the automatic breakpoint at line 1 (breakpoint indicated by the red star). Here we single stepped through the function and are at line 3, indicated by the green bar. Note from the Console window that we at this point examined the contents of variable b.

Also, you may need to set the working directory to your Eclipse R project with setwd and source functions. i.e.

library(debug)

setwd(“C:\Users\xx\workspace\R Project Test”)

source(“test.R”)

mtrace(test)

Loading required package: parser

Also, it seems the launcher run configuration does not load R with a new Eclipse session. If this is the case, just launch manually it within run configuration. Run->Run Configuration and choose Run.

This Eclipse StatET plugin could have bugs so it might not work as expected depending on your plugin and Eclipse version.

[youtube_sc url=”bGkvQw67qKc” playlist=”video, demo, introductory, checklist , how to, debug, R, Eclipse, IDE”]

Excellent tutorial on pair trading in R on how to Estimate parameters for back test, Create trading signal,, Back-test performance

Excellent tutorial on pair trading in R on how to Estimate parameters for back test, Create trading signal,, Back-test performance
This is an excellent tutorial that shows R’s pair trading capabilities with the PairTrading package.
It includes benefits how to do:
Estimate parameters for back test
Create trading signal
Back-test performance
http://www.r-bloggers.com/pair-trading-strategy-how-to-use-pairtrading-package/

How to do computation finance with R for newbies

How to do computation finance with R for newbies

This is a really good tutorial for R newbies.

http://www.rmi.nus.edu.sg/csf/webpages/Authors/firstdraft/Nolan_draft_1.pdf

Do note that three R functions are at the end of the document. This includes get.stock.data, get.stock.price, and get.portfolio.returns

Give it a whirl but nothing new here for advanced users

 

How to use Principal component analysis for financial within R

How to use Principal component analysis for financial within R
These two links will help you understand what PCA is within R
http://www.r-bloggers.com/principal-component-analysis-use-extended-to-financial-economics-part-1/
http://www.r-bloggers.com/principal-component-analysis-use-extended-to-financial-economics-part-2/

For part 1 to create data, use http://www.nseindia.com/content/indices/ind_cnx500.htm, click Daily Return values and select period. Download as a CSV to be named Returns_CNX_500.csv. It appears to load fine.  You will also need to create a matrix called return1 before executing the code.

For part 2, you need to download MIBOR.CSV from http://dl.dropbox.com/u/20480592/MIBOR.csv

Other than that, the code in part 2 does work!

How to measure Liquidity measure Aggregation and volatility, Inferred trade direction from market data in R

How to measure Liquidity measure Aggregation and volatility, Inferred trade direction from market data in R

From http://www.econ.kuleuven.be/public/n09022/RTAQ_vignette.pdf

This appears to work ok but this RTAQ package is impressing me each time

How to do parallel R loops within Windows and Linux. No more expensive Matlab worker licenses

How to do parallel R loops within Windows and Linux. No more expensive Matlab worker licenses

The major reasons I switched from Matlab was for exactly this. Under Matlab, the worker licenses will kill but now you can you can do this for free under R. Thanks to makers of these adequate R packages.

If you follow this tutorial

http://viksalgorithms.blogspot.ca/2012/01/parallel-r-loops-for-windows-and-linux.html

You should hjave no problems executing these commands as I tried with no issues. Just do note the proper R packages you need in your backend depending on your operating system of Windows versus Linux.

An excellent tutorial on how to use the Pairs Trading package in R

An excellent tutorial on how to use the Pairs Trading package in R

http://www.r-bloggers.com/pair-trading-strategy-how-to-use-pairtrading-package/

I can verify the above code works from end to end. The impressive thing is it is much simpler tha the Matlab version with their webinar. Here you estimate, generate the signal, and perform a backtest. It shows how easy some of these R packages are.

 

R source code example on how to trade using a GARCH Volatility Forecast

R source code example on how to trade using a GARCH Volatility Forecast

I found this link:

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

I am using RStudio so I can confirm sthat the code seems to be ok but the plots fail with a message;
> plotbt.custom.report.part1(regime.switching.garch, regime.switching, buy.hold)
Error in plot.window(…) : Logarithmic axis must have positive limits
In addition: Warning message:
In xy.coords(x, y, xlabel, ylabel, log) :
  3120 y values <= 0 omitted from logarithmic plo

Could it be the data used? I am not sure but I only need the data anyhow. Looks good but still need to validate it as I get more comfortable with R.