Quantitative finance collector
C++ Matlab VBA/Excel Java Mathematica R/Splus Net Code Site Other
Jul 1

Simple Dummy R GUI Generator

Posted by abiao at 11:28 | Code » R/Splus | Comments(1) | Reads(12317)
Imagine you finish a dirty coding project and want to present to your boss who is not in a good mood (may not be occasionally), how are you going to start? Show him your hundreads of lines code, point to the lines, explain what the arguments and outputs are? No, it is not a smart way since you are supposed to introduce in a few short sentences. Generating a GUI is probably the quickest / easiest way of understanding what this code does. As the old saying goes: a picture is worth a thousand words, so in a same logic, a GUI is worth n thousand words.

However, generating GUI is by no means easy as I know the pain when creating the Matlab-GUI equity derivative calculator. It becomes even worse in R language, to be honest, I hate the graph plotting in R, terribly unflexible compared with in Matlab. Luckily I came across a good R GUI package named "fgui", it does as its description: Rapidly create a GUI interface for a function you created by automatically creating widgets for arguments of the function.

Very nice indeed, after playing for half an hour, it is simple to use, especially when what you need is just a basic GUI demonstrating to others a rough idea. One line code is enough.

For a simple example, I create a European option pricer with Black Scholes formula,
EuropeanOption <- function (s, k, r, t, vol, CallOption) {
  d1 <- (log(s/k)+(r+0.5*vol^2)*t)/(vol*sqrt(t))
  d2 <- d1-vol*sqrt(t)
  if (CallOption){  
    return (s*pnorm(d1)-k*exp(-r*t)*pnorm(d2))
  } else {
    return (k*exp(-r*t)*pnorm(-d2)-s*pnorm(-d1))

then generating a GUI for this function is as simple as adding the following code
res <- gui(EuropeanOption, argOption=list(CallOption=c("TRUE","FALSE")))

It returns a GUI looks like
Open in new window
where you are able to set inputs and get outputs. Nice. More advanced GUI is possible by adding more lines.

Interested readers shall download the package "fgui" at http://cran.r-project.org/web/packages/fgui/index.html

Tags: ,
Your content is high quality, you can discover quite a few special stuff that can't be spotted on many other web sites, fairly useful but still very accurate!
critical ops cheats
Pages: 1/1 First page 1 Final page
Add a comment
Enable HTML
Enable UBB
Enable Emots
Nickname   Password   Optional
Site URI   Email   [Register]