[R] multiple versions of function
ivo welch
ivo.welch at anderson.ucla.edu
Tue Jan 8 00:57:38 CET 2013
dear R experts:
I want to define a function the calculates the black-scholes value.
it takes 5 named parameters, BS <- function(S,K,dt,rf,sigma) {} .
let's presume I want to be able to call this not only with my 5
numeric vectors BS( sigma=0.3, S=100, K=100, dt=1, rf=0.1 ) and BS(
100, 100, 1, 0.1, 0.3), but also with a data frame that contains the
variables alll in a neat data frame already, BS( data.frame( S=100,
K=100, dt=1, rf=0.1, sigma=0.3 )). I could of course define BS6 and
BS1, but it would be nice to wrap this functionality into one function
that can do both.
I know that BS has to parse an '...' argument, but there could be a
couple of magical R functions that might make this easier than I would
do it with my planned clunky version. what's the elegant version?
/iaw
----
Ivo Welch (ivo.welch at gmail.com)
More information about the R-help
mailing list