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.