(no subject)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

(no subject)

Niels Nygaard
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 = {0}", type);
            Console.WriteLine("Maturity = {0}",maturity.__str__());
            Console.WriteLine("Underlying price = {0}", underlying);
            Console.WriteLine("Strike = {0}", strike);
            Console.WriteLine("Dividend Yield = {0}", dividendYield);
            Console.WriteLine("Riskfree Rate = {0}", riskFreeRate);
            Console.WriteLine("Volatility = {0}", 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 {0}
is: {1}", method,euroOption.NPV());

            method = "CRRTree";

            uint timeSteps=1000;

            euroOption.setPricingEngine(new BinomialVanillaEngine("CRR",
timeSteps));

            Console.WriteLine("The price of the European Option using {0}
is: {1}", 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users