I seem to get different results when using the C++ version
from what I get
when I use the C# version of QL. Here is my C# code:
namespace QuantLibOptionPricer
{
class Program
{
static void Main(string[] args)
{
double underlying = 36;
double strike = 40;
double dividendYield = 0.0;
double riskFreeRate = .06;
double volatility=0.2;
Option.Type type = Option.Type.Put;
Date todaysDate = new Date(27, Month.March,
2007);
Date settlementDate = new Date(27, Month.March,
2007);
Settings.instance().setEvaluationDate(todaysDate);
Date maturity = new Date(17, Month.May, 2007);
DayCounter dayCounter = new Actual365Fixed();
Console.WriteLine("Option Type = ",
type);
Console.WriteLine("Maturity =
",maturity.__str__());
Console.WriteLine("Underlying price =
", underlying);
Console.WriteLine("Strike = ",
strike);
Console.WriteLine("Dividend Yield =
", dividendYield);
Console.WriteLine("Riskfree Rate =
", riskFreeRate);
Console.WriteLine("Volatility = ",
volatility);
EuropeanExercise euroEx = new
EuropeanExercise(maturity);
AmericanExercise ameriEx = new
AmericanExercise(settlementDate, maturity);
QuoteHandle underlyingH = new QuoteHandle(new
SimpleQuote(strike));
YieldTermStructureHandle flatTermStructure = new
YieldTermStructureHandle( new FlatForward(settlementDate,
riskFreeRate,dayCounter));
YieldTermStructureHandle flatDividendTS = new
YieldTermStructureHandle( new FlatForward(settlementDate,
dividendYield,dayCounter));
BlackVolTermStructureHandle flatVolTS = new
BlackVolTermStructureHandle(new
BlackConstantVol(settlementDate, volatility, dayCounter));
PlainVanillaPayoff payoff = new
PlainVanillaPayoff(type,underlying );
BlackScholesProcess stochasticProcess=new
BlackScholesProcess(underlyingH,flatTermStructure,flatVolTS)
;
//Option
VanillaOption euroOption=new
VanillaOption(stochasticProcess,payoff,euroEx);
string method="Black-Scholes";
euroOption.setPricingEngine(new
AnalyticDividendEuropeanEngine());
Console.WriteLine("The price of the
European Option using
is: ", method,euroOption.NPV());
method = "CRRTree";
uint timeSteps=1000;
euroOption.setPricingEngine(new
BinomialVanillaEngine("CRR",
timeSteps));
Console.WriteLine("The price of the
European Option using
is: ", method, euroOption.NPV());
}
}
}
This gives a price of 4.37. The C++ version givew 3.79 which
is the
correct value. Any ideas of what may be wrong
Niels Nygaard
------------------------------------------------------------
-------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the
chance to share your
opinions on IT & business topics through brief
surveys-and earn cash
http://www.techsay.com/default.
php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
QuantLib-users mailing list
QuantLib-users lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/quantlib
-users
|