8
$\begingroup$

The results are very different.I know the code from quantlib and the result of quantlib seem right(close to market price). Is there anyone know why the value from fOptions is so large or fOptions used different approach? Thank you

  library(fOptions)
    library(RQuantLib)

    TypeFlag<-"c"
    S<-530.32
    X<-550
    Time<-283/365
    r<-0.000703
    b<-0.05
    sigma<-0.2442

    fOptions.BAW<-BAWAmericanApproxOption(TypeFlag, S, X, Time, r, b, sigma,
                                          title = NULL, description = NULL)
    quantlib.BAW<-AmericanOption("call", S, X,
                                 b, r, Time, sigma,
                                 timeSteps=150, gridPoints=149, engine="BaroneAdesiWhaley")

    modelName<-c("fOptions.BAW","quantlib.BAW")
    result <-cbind(modelName,
             c(fOptions.BAW@price,quantlib.BAW[1]$value))
    colnames(result)<-c("Model","Value")

enter image description here

$\endgroup$
3
  • $\begingroup$ The source code for both is available. Have you looked at it? $\endgroup$ Jun 13, 2014 at 12:51
  • $\begingroup$ I already read the quantlib version (it can be found at github). I try to find the foptions source, but it wrote by fortran (which I don't understand). am i right or could you send me the link about foptions source code. Much obliged $\endgroup$
    – galaxyan
    Jun 13, 2014 at 14:34
  • $\begingroup$ Yes, it's in Fortran. You could compare the current version with archived versions of fOptions on CRAN. Maybe one of the older versions had a pure-R implementation. $\endgroup$ Jun 13, 2014 at 15:06

2 Answers 2

8
$\begingroup$

The price difference is so large -- that the only possible reason is that you have spot and strike confused between the two functions.

And indeed:

R> fOptions.BAW <- BAWAmericanApproxOption(TypeFlag, S, X, Time,
+                       r, b, sigma, title = NULL, description = NULL)
R> quantlib.BAW <- AmericanOption("call", X, S, b, r, Time, 
+                       sigma, timeSteps=150, gridPoints=149,
+                       engine="BaroneAdesiWhaley")
R> result <- c("fOptions"=fOptions.BAW@price,
+             "RQL"=quantlib.BAW$value)
R> result
fOptions      RQL 
 47.7631  47.5193 
R> 
$\endgroup$
2
$\begingroup$

The prices should be 'really' close to each other. My result is:

>result
 Model          Value             
[1,] "fOptions.BAW" "47.7630796321483"
[2,] "quantlib.BAW" "47.747504045402"

The reason is here we need to deal with three variables:

r (risk free rate), d (dividend yield), b (cost-of-carry rate).

and

d = r -b 

The documentation of these two functions are: (look at the end of the first and third line)

BAWAmericanApproxOption(TypeFlag, S, X, Time, r, b,   
sigma, title = NULL, description = NULL)

AmericanOption(type, underlying, strike, dividendYield, riskFreeRate,  
maturity, volatility, timeSteps=150, gridPoints=149, engine="BaroneAdesiWhaley")

As you can see, one uses "r" and "b". The other uses "d" and "r".

A little modification (Just change "b" to "r-b") to the poster's code here will fix the problem.

library(fOptions)
library(RQuantLib)

TypeFlag<-"c"
S<-530.32
X<-550
Time<-283/365
r<-0.000703
b<-0.05
sigma<-0.2442

fOptions.BAW<-BAWAmericanApproxOption(TypeFlag, S, X, Time, r, b, sigma,
                                      title = NULL, description = NULL)
quantlib.BAW<-AmericanOption("call", S, X,
                             r-b, r, Time, sigma,
                             timeSteps=150, gridPoints=149, engine="BaroneAdesiWhaley")

modelName<-c("fOptions.BAW","quantlib.BAW")
result <-cbind(modelName,
         c(fOptions.BAW@price,quantlib.BAW[1]$value))
colnames(result)<-c("Model","Value")

The result will be the "47.76" and "47.74" I posted above.

##################-----------------------------

Below is the answer that I wrote on Oct 18. I would keep it there.

##################-----------------------------

In RQuantLib, the formula you are using should include "dividendYield" which is "r-b" instead of b (the annualized cost-of-carry rate)

quantlib.BAW<-AmericanOption(type = TypeFlag, underlying = S, strike = X, dividendYield = r - b, 
                  riskFreeRate = r, maturity = Time, volatility = sigma, engine="BaroneAdesiWhaley")

This will provide the same(similar) answer to fOptions.

$\endgroup$
2
  • $\begingroup$ No, that is in-line with the documentation and moves the price for me from 29.82 to 29.91. $\endgroup$ Nov 18, 2015 at 12:35
  • $\begingroup$ My code gives the result: 47.747504045402, not 29.91. And this is a call option, the underlying price should be "S<-530.32 ", the strike price here is "X<-550". It is easy to verify that your way of fixing it does not work. Change "S<- 530.32" to "S <- 500", and you can see the results differs a lot again by only switching the places of "S" and "X". $\endgroup$
    – ZMatrix
    Dec 15, 2015 at 23:39

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.