Message-ID: <D3F541EA-FE6E-46E5-B810-34C837945A3A@comcast.net>
Date: 2013-01-08T00:25:44Z
From: David Winsemius
Subject: multiple versions of function
In-Reply-To: <CAPr7RtU1hLjqH62At+aZ=V6aHU4Az0Qj_8eeM4UPxi3g217vSQ@mail.gmail.com>
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