Bonjour friends,

The holiday season is upon us, and I wanted to jam through this highly useful article for your research and statistical analysis on how to make R language work for you.This write-up covers the following topics:
  • Introducing R
  • R Installation
  • Installing packages
  • Creating graphs
INTRO
If you’re not already familiar with R programming, there’s no better time to learn and get started with this powerful little programming pack. In it you can run very detailed statistical analysis in a matter of no time. Knowing how to code and planning your work will help you in your analysis and research. Since R is recognized as a credible statistical package, it’s helpful for you to know how to code with this language to help shape your writings in global currencies.

First thing to know is that R works off of the S language framework developed at Bell labs; and S-PLUS, which is mathematically expressive. So, if you have any experience with coding in S or so-called latex in your research papers, you will quickly learn how to master R programming language.

During my time as an undergrad at the University, I had the privilege of working with really good statistical software for my analysis, putting me in the driver seat for notes and interpretation with just an intermediate understanding of math and statistics. All of the tedious calculations are done for you and the output results are clear to read, better than most other data analysis software. The great thing about R language programming is that you will receive all of the same capabilities as the full suite software package, and the best part is that it’s free of cost!

So, without further ado let’s go ahead and get to installing R on your desktop or laptop so we can start.

INSTALLATION
To install R, first thing you’ll do is download the binary .zip file on your laptop or desktop computer. You can download the appropriate file from The Comprehensive R Archive Network (CRAN) mirrors website. Once you unzip the folder that corresponds to your machine. You can simply run the program in GUI by double-clicking the application icon.

Depending on your system, you may be able to install both the 32-bit and 64-bit versions of the software. Since I’m running Windows 64-bit operating system, this example will guide along those lines for the install.

For serious technologists: you must realize that 32-bit installations are the best way to go when it comes to compatibility. And for serious banking professionals: you must realize that 64-bit installations are the most secure.


In the case of 64-bit operating systems you have the choice of running and installing programs with either of the two. For 32-bit installation you must set the file path in the C:\Program Files (x86)\ directory instead of the regular program files folder. If you need assistance knowing what your installation needs are, please refer to the admin and install manual.

Or, you may be experienced in building from source, for example, adding external libraries and custom .dll in your trading software. You are able to do this with R language, the installation manual goes over how, step-by-step.

CLI
If you prefer running your software directly from the command line, you can set this up by declaring the environment variable on your PC’s system. This must be the absolute path directory to your executable bin folder. For instance, in my installation the file path to the bin folder is C:\Program Files\R\R-3.3.2\bin . That means that the program will execute to that directory, assuming there is an executable program file there.

Now set the environment variable as follows: R_USER= C:\Program Files(x86)\R\R-3.3.2\bin\i386 , and also add the same path, unique to your personal install, and it to your PATH variables. On Windows 8 computers that can be done by simply right-clicking on the windows start icon and clicking ‘System’ in the pop-up menu. Otherwise, you can always adjust your environment variables under Control Panel-->System Settings-->Advanced System Settings-->Environment Variables.

Once you have done that you can open a new command-line terminal by going to your windows start button and typing cmd to open the command line. NOTE: unless you are logged into your computer as an admin you will have to right-click on the command prompt and ‘run as administrator’, if your accessing it through the graphical-user-interface GUI, you may perform this same function by right-clicking on the app icon and configuring the properties to run as administrator. Once you’re running the command prompt as admin, you start the program by entering ‘R’ with the first line. That starts the CLI, you’re then prompted with a greeting!

INSTALLING PACKAGES
In order to perform some of the more advanced and customizable functions of the software you need to install library packages. In the next article I will explain how to create graphs in R, which implement the “PerformanceAnalytics” library package, so let’s go ahead and install that. What you will do is enter install.packages(“PerformanceAnalytics&rdquo into the command-line interface. If you’re installing from the cmd prompt, it should look like this:



Press enter. Next you will see the mirror servers, select the one closest to you. After you have installed the PerformanceAnalytics library package and all its dependencies. Enter library(“PerformanceAnalytics&rdquo in the first line of the interface. After you hit enter it should run a script and finish with a line and saying ‘legend’.



As you can see in the screenshot, ‘Package PerformanceAnalytics (1.4.x) loaded’. This is how you install and run library packages in R, and there are lots and lots of add-ons like this! With the “PerformanceAnalytics” loaded we can now create detailed charts and graphs.


CREATING GRAPHS
For making your own custom equity charts and graphs, you will have to learn how to import datasets, for this example we may just chart directly from the example dataset given in the package.

The example dataset in the dataset is called ‘managers’, a time-series dataset that compares relative performance versus different indices. To make the data ready for charting you must enter data(managers) Then type head(managers), to name the headers of the file. Since this datafile is pre-loaded in the package, you’re pretty much set. By typing ‘managers’ and hitting enter you will see a rundown of the entire dataset. To draw the graph all we need to do now is type charts.PerformanceSummary(managers) and press enter. You should generate a performance chart that looks similar to this:

Keep in mind you can edit the graph how you want, changing colorsets, labels; of course, the title of the graph. Let’s try changing the colorset. Since all we did in the previous chart was perform default functions, this time we will change the colorset to one called ‘set6equal’ and add a different title. Let’s call it ‘Manager Perf. Chart’. All we need to do now is enter the proper command in the prompt as follows: charts.PerformanceSummary(managers, colorset=set6equal, main=’Manager Perf. Chart&rsquo

And, voila, here is the chart:

Now that you know how to build custom charts and graphs, you can learn more at the CRAN website and import your own custom data sets to create graphs and perform statistical analysis in R.
Translate to English Show original