6
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$
    – Richi Wa
    Jul 1, 2015 at 7:52
  • $\begingroup$ @Richard getting the price for a bunch of options with one call, or getting the delta for a bunch of options with one call $\endgroup$ Jul 1, 2015 at 7:54

2 Answers 2

4
$\begingroup$

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

$\endgroup$
0
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$ Jul 1, 2015 at 8:01
  • $\begingroup$ I see ... this is different. $\endgroup$
    – Richi Wa
    Jul 1, 2015 at 8:02
  • $\begingroup$ I updated my question to make it more clear $\endgroup$ Jul 1, 2015 at 8:03
  • $\begingroup$ I stumbled upon this post: r-bloggers.com/… there they propose to use the compiler package which can improve speed under some circumstances ... $\endgroup$
    – Richi Wa
    Jul 1, 2015 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.