# good R package for vectorized option pricing

I am using for now the package fOptions but it doesn't allow for vectorized computation of black76 prices and delta. Which package can be used to do that?

As noted by @Richard, I could use lapply, but it is actually looping in R, which is slow (at least too slow for me). I am looking for a package that has a compiled loop, ie that provides a native vectorized function.

• what do you mean by vectorized? Getting price and delta with one function call? Or getting the price for a bunch of options with one call? – Richard Jul 1 '15 at 7:52
• @Richard getting the price for a bunch of options with one call, or getting the delta for a bunch of options with one call – RockScience Jul 1 '15 at 7:54

Answering my own question as it could be useful for others. Actually package fOptions is vectorized. The only constraint (and that make sense) is that you can't compute at the same time 2 different greeks, or mix up calls and puts.

So assuming that you want to compute the delta of a set of puts, the code will be the following:

fOptions::GBSGreeks(Selection = "Delta",
TypeFlag="p",
S=c(100,100)+1:2,
X=c(100,100),
Time=c(0.1,0.2),
r=c(0,0),
b=c(0,0),
sigma=c(0.2,0.2))


which returns the same (that's the validation) as the output of mapply:

mapply(FUN       = fOptions::GBSGreeks,
Selection = c("Delta","Delta"),
TypeFlag=c("p","p"),
S=c(100,100)+1:2,
X=c(100,100),
Time=c(0.1,0.2),
r=c(0,0),
b=c(0,0),
sigma=c(0.2,0.2))


nice...

if you put all your option objects into a list then you can use lapply. Read the documentation or just thist post for details.

• thank you for your answer, but lapply is actually looping in R, which is slow (at least too slow for me). I am looking for a package that has a compiled loop, ie that provides a native vectorized function. – RockScience Jul 1 '15 at 8:01
• I see ... this is different. – Richard Jul 1 '15 at 8:02
• I updated my question to make it more clear – RockScience Jul 1 '15 at 8:03
• I stumbled upon this post: r-bloggers.com/… there they propose to use the compiler package which can improve speed under some circumstances ... – Richard Jul 1 '15 at 8:06