## Archive for the ‘**Programming: R**’ Category

## [WP] Shiny for Finance

For those familiar with R, Shiny offers a great alternative to spreadsheets. Targeted at instructors, we have a new paper introducing Shiny for finance applications in the classroom. Here is a longish abstract:

Despite the popularity of open-source languages like R and Python in modern empirical research and the data-science industry, spreadsheet programs like Microsoft Excel remain the data analysis software of choice in much of the business-school curriculum, including at IIMA. Even if instructors are comfortable with modern programming languages, they have to pitch their courses at the level of computer literacy prevalent among students. Excel then appears to be a natural choice given its popularity, but this choice constrains the depth of analysis that is possible and requires a certain amount of dumbing-down of the subject by the instructor. Recent software advances however make the ubiquitous web browser a worthy challenger to the spreadsheet. This article introduces one such browser-based tool called Shiny for bringing finance applications to the classroom and smart phones. Fueled by the availability of high-quality R packages in finance and statistics, Shiny brings together the power of HTML with the R programming language. It naturally creates an environment for the instructor to focus on the role of parameters and assumptions in analysis without the clutter of data, and allows the instructor to go beyond the toy problems that are necessitated by the nature of spreadsheets. The learning curve is short for an interested instructor with even a rudimentary exposure to programming in any language. The article ends with the discussion of a fully-worked out example of Shiny for teaching the mean variance efficient frontier in a basic investments course.

The working paper is here. It needs a bit of fine tuning yet, but comments welcome.

## R through Excel

Richard Hieberger and Erich Neuwirth have developed a wonderful little tool call RExcel, which brings the power of R to the ease of Excel. Seems perfect for building prototypes and for in-class illustrations.

**Installing the RExcel Addin**

The developers claim on their website that RExcel works with Excel 2003, 2007 and 2010**. **

Installing the RExcel add-in is easy. If you don’t have R already installed on your machine, just download and run the “RAndFriends” executable from the statconn website and you are ready to go (it is claimed it installs both R and RExcel while taking care of all the dependencies – I haven’t tried it though).

If you already have R, but rather not tinker with its installation, there is quite a useful wiki to guide one through the steps. I recently installed it on my PC running Excel 2010 Professional and I had no trouble getting it to work. Here are the commands I used. Just run them in order in your R console and you should be up and running:

` install.packages("rcom")`

library(rcom)

installstatconnDCOM()

comRegisterServer()

comRegisterRegistry()

` install.packages("Rcmdr", dependencies = TRUE)`

install.packages("RExcelInstaller")

install.packages("HH")

install.packages("RthroughExcelWorkbooksInstaller")

install.packages("RcmdrPlugin.HH")

(I know one can concatenate the above set of commands and use install.packages just once – it’s just a lot easier this way to ‘see’ what’s going on.)

At this point you should see the R command prompt. Don’t forget to ‘activate’ the installed packages:

` library(RExcelInstaller)`

installRExcel()

library(RthroughExcelWorkbooksInstaller)

installRthroughExcel()

Now you should have a short-cut on your desktop called *RExcel20** with RCommander*.

**Update**: I hastily tried installing statconnDCOM in the latest version of R (2.13.1) and got an error saying statconnDCOM is not available for that version. For new users I would suggest directly installing from the RAndFriends executable.