[R-SIG-Finance] [R] how to vectorize EuropeanOptio nImpliedVolatility

Dirk Eddelbuettel edd at debian.org
Tue Aug 16 14:54:27 CEST 2011


On 16 August 2011 at 12:44, 이원재 wrote:
| Hi, 
| I had error messages as below with EuropeanOptionImpliedVolatility function because this function is limited to scalar cases. 
| Is there any way to use vectorized inputs instead of loop?

Yes. Patches welcome. 

I wrote the code below almost a decade ago when I knew a lot less about R
programming, but seemingly I haven't gotten around to making it much
cleaner.   One obvious solution would be vector inputs to the C++ layer but
then I could never decide which of input type, value, spot, strike, divyield,
riskfree, timetomaturity I would want as a vector.  Possibly all, but then
the return array (or list) becomes a little hard to handle.

Dirk

| Thanks in advance
| Wonjae Lee
| underlying=c(100,90,95)
| value=c(11.1,11.2,11.3)
| type=c("call","call","call")
| strike=c(120,110,110)
| dividendYield=c(0,0,0)
| riskFreeRate=c(0.03,0.03,0.03)
| maturity=c(0.5,0.5,0.5)
| initialvolatility=c(0.25,0.25,0.25)
| EuropeanOptionImpliedVolatility(type,value,underlying, strike, dividendYield, riskFreeRate, maturity, initialvolatility)
| > EuropeanOptionImpliedVolatility(type,value,underlying, strike, dividendYield, riskFreeRate, maturity, initialvolatility)
| Error in EuropeanOptionImpliedVolatility.default(type, value, underlying, : 
|  expecting a single value
| > mapply(EuropeanOptionImpliedVolatility(type,
| value
| ,
| underlying
| , strike, dividendYield, riskFreeRate, maturity, 
| initialvolatility
| ),
| type,
| value
| ,
| underlying
| , strike, dividendYield, riskFreeRate, maturity, initialvolatility
|  )
| Error in EuropeanOptionImpliedVolatility.default(type, val, und, strike, : 
|  expecting a single value
| 
| 	[[alternative HTML version deleted]]
| 
| _______________________________________________
| R-SIG-Finance at r-project.org 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.

-- 
Two new Rcpp master classes for R and C++ integration scheduled for 
New York (Sep 24) and San Francisco (Oct 8), more details are at
http://dirk.eddelbuettel.com/blog/2011/08/04#rcpp_classes_2011-09_and_2011-10
http://www.revolutionanalytics.com/products/training/public/rcpp-master-class.php



More information about the R-SIG-Finance mailing list