[R-SIG-Finance] GBSVolatility not working on vectors?
Joachim Breit
jbreit at nexgo.de
Thu Sep 25 11:47:39 CEST 2014
Hi,
I am struggling with the GBSVolatility function. I have a huge dataframe
'd' with options market data and want to add a column with the implied
volatility computed from the ask price.
When invoking GBSVolatility with a single line of the dataframe
everything works fine. But when feeding the columns of the dataframe
into GBSVolatility I get an error message.
To tackle the issue I took a mini-dataframe 'dtemp' with only two rows
(arbitrary subset of the original d)
## mini-dataframe ########################################
> dtemp <- d[515:516,]
> dtemp
strike cp ask bid c ntd rb iva
1081 50 c 16.17 15.37 65.79 32 0.00384 1e+09
1083 51 c 15.17 14.37 65.79 32 0.00384 1e+09
## invoking with the entire mini-dataframe ####################
> dtemp$iva <- GBSVolatility(price = dtemp$ask, TypeFlag = dtemp$cp,
S = dtemp$c , X = dtemp$strike, Time = dtemp$ntd / 253.8,
r = pmax(dtemp$rb, 0), b = pmax(dtemp$rb, 0))
Fehler in uniroot(.fGBSVolatility, interval = c(-10, 10), price = price, :
ungültiger Funktionswert in 'zeroin'
Zusätzlich: Warnmeldungen:
1: In if (is.na(f.lower)) stop("f.lower = f(lower) is NA") :
Bedingung hat Länge > 1 und nur das erste Element wird benutzt
2: In if (is.na(f.upper)) stop("f.upper = f(upper) is NA") :
Bedingung hat Länge > 1 und nur das erste Element wird benutzt
3: In if (f.lower * f.upper > 0) stop("f() values at end points not of
opposite sign") :
Bedingung hat Länge > 1 und nur das erste Element wird benutzt
## invoking with the first row of the mini-dataframe ###############
> dtemp <- d[515:515,]
> dtemp$iva <- GBSVolatility(price = dtemp$ask, TypeFlag = dtemp$cp,
S = dtemp$c , X = dtemp$strike, Time = dtemp$ntd / 253.8,
r = pmax(dtemp$rb, 0), b = pmax(dtemp$rb, 0))
> dtemp
strike cp ask bid c ntd rb iva
1081 50 c 16.17 15.37 65.79 32 0.00384 0.5340467
## invoking with the 2nd row of the mini-dataframe ###############
> dtemp <- d[516:516,]
> dtemp$iva <- GBSVolatility(price = dtemp$ask, TypeFlag = dtemp$cp, S
= dtemp$c , X = dtemp$strike, Time = dtemp$ntd / 253.8, r =
pmax(dtemp$rb, 0), b = pmax(dtemp$rb, 0))
> dtemp
strike cp ask bid c ntd rb iva
1083 51 c 15.17 14.37 65.79 32 0.00384 0.5030617
Can somebody please help? I am going crazy...
Joachim
More information about the R-SIG-Finance
mailing list