Jul
1

## Simple Dummy R GUI Generator

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,

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 "

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.

For a simple example, I create a European option pricer with Black Scholes formula,

It returns a GUI looks like

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 "

Hot posts:

15 Incredibly Stupid Ways People Made Their Millions

Online stock practice

Ino.com: Don't Join Marketclub until You Read This MarketClub Reviews

World Changing Mathematical Discoveries

Value at Risk xls

Random posts:

Multidimensional numerical integration

MatLab for Financial Engineers

Workshop on Stochastic and PDE Methods in Financial Mathematics, 2012, Armenia

Quant Q&A Wall

Interview: Donald R. van Deventer Risk Management

**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))

}

}

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

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**People viewing this post also viewed:**

Hot posts:

Random posts: