[R] multiple versions of function

David Winsemius dwinsemius at comcast.net
Tue Jan 8 01:25:44 CET 2013


On Jan 7, 2013, at 3:57 PM, ivo welch wrote:

> 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?
> 

apply( dfrm, 1, BS)

-- 

David Winsemius
Alameda, CA, USA




More information about the R-help mailing list