It's slow for two very good reasons. First, you're looping in R- a
language that isn't designed for running through loops quickly. Second,
GBSVolatility is a function that uses root-solving methods, which are by
nature and definition iterative, and no matter what programming language
you use, iterative programming is going to be slower than simple
arithmetic operations- that's just the way it is.

If you want to speed up the code, I recommend using the "apply" function
in R. "apply" will take a function and its constituent arguments and
recursively apply said function to elements of a two-dimensional array
according to the dimension(s) you specify. This is much faster than
using a "for" loop in most cases.

On Thu, 2010-11-04 at 20:04 +0530, Rohit Taklikar wrote:

> Thanks David
> 
> GBSVolatility is darn slow though. Any faster alternatives available?
> 
> Regards,
> 
> On 4 November 2010 18:58, David Reiner <David.Reiner@xrtrading.com> wrote:
> 
> > Right, the function is not vectorized. See ?Vectorize
> > HTH,
> > David L. Reiner
> > XR Trading LLC
> >
> > -----Original Message-----
> > From: r-sig-finance-bounces@stat.math.ethz.ch [mailto:
> > r-sig-finance-bounces@stat.math.ethz.ch] On Behalf Of Rohit Taklikar
> > Sent: Thursday, November 04, 2010 3:10 AM
> > To: r-sig-finance@stat.math.ethz.ch
> > Subject: [SPAM] - [R-SIG-Finance] Implied Volatility, Column operation -
> > Email found in subject
> >
> > Hi,
> >
> > I have raw options data in an array and i am trying to calculate implied
> > volatility in a new column for all rows at once -
> >
> > > sres$CALL_IV =
> >
> > GBSVolatility(sres$CALL_PRICE,"c",sres$UNDERLYING_PRICE,sres$STRIKE,sres$TIME2EXP,0,0)
> >
> > where, CALL_IV, CALL_PRICE, UNDERLYING_PRICE etc. are columns of "sres"
> >
> > I am getting an errors and warnings for this:
> > ======
> > Error in uniroot(.fGBSVolatility, interval = c(-10, 10), price = price,  :
> >  invalid function value in 'zeroin'
> > In addition: Warning messages:
> > 1: In if (is.na(f.lower)) stop("f.lower = f(lower) is NA") :
> >  the condition has length > 1 and only the first element will be used
> > 2: In if (is.na(f.upper)) stop("f.upper = f(upper) is NA") :
> >  the condition has length > 1 and only the first element will be used
> > 3: In if (f.lower * f.upper > 0) stop("f() values at end points not of
> > opposite sign") :
> >  the condition has length > 1 and only the first element will be used
> > ======
> >
> > However this works when i run a for loop it works. Does it mean column
> > operation is not supported by fOptions functions?
> >
> > Any idea how to do this efficiently?
> >
> > Regards,
> >
> >        [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-SIG-Finance@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> > -- Subscriber-posting only. If you want to post, subscribe first.
> > -- Also note that this is not the r-help list where general R questions
> > should go.
> >
> >
> > This e-mail and any materials attached hereto, including, without
> > limitation, all content hereof and thereof (collectively, "XR Content") are
> > confidential and proprietary to XR Trading, LLC ("XR") and/or its
> > affiliates, and are protected by intellectual property laws.  Without the
> > prior written consent of XR, the XR Content may not (i) be disclosed to any
> > third party or (ii) be reproduced or otherwise used by anyone other than
> > current employees of XR or its affiliates, on behalf of XR or its
> > affiliates.
> >
> > THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF
> > ANY KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY
> > DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR
> > CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE
> > LIABLE FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED
> > TO, DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF
> > PROFITS AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE
> > UPON, OR INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE
> > POSSIBILITY OF SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.
> >
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-SIG-Finance@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
> 



	[[alternative HTML version deleted]]

