I apologize for the garbage from Cut-Paste in my previous
post. Here it is again in plain text.
I built EquityOption example in C# (sample code attached).
However, Binomial methods throw exception “null conversion ratio”.
Your thoughts and ideas on this are greatly appreciated.
Cheers,
Mike A.
using System;
using QuantLib;
namespace EquityOption
{
class Run
{
[STAThread]
static void
{
Option.Type type = Option.Type.Put;
double underlying = 36;
double strike = 40;
double dividendYield = 0.0;
double riskFreeRate = 0.06;
double volatility = 0.2;
Date todaysDate = new Date(15, Month.May, 1998);
Date settlementDate = new Date(17, Month.May, 1998);
Settings.instance().setEvaluationDate(todaysDate);
Date maturity = new Date(17, Month.May, 1999);
DayCounter dayCounter = new Actual365Fixed();
// write column headings
int[] width = { 35, 14, 14, 14 };
Console.Write(String.Format("Method").PadRight(width[0]));
Console.Write(String.Format("European").PadRight(width[1]));
Console.Write(String.Format("Bermudan").PadRight(width[2]));
Console.WriteLine(String.Format("American").PadRight(width[3]));
DateVector exerciseDates = new DateVector(4);
exerciseDates.Insert(0, new QuantLib.Date(17, Month.August,
1998));
exerciseDates.Insert(0, new QuantLib.Date(17,
Month.November, 1998));
exerciseDates.Insert(0, new QuantLib.Date(17,
Month.February, 1999));
exerciseDates.Insert(0, new QuantLib.Date(17, Month.May,
1999));
EuropeanExercise europeanExercise = new
EuropeanExercise(maturity);
BermudanExercise bermudanExercise = new
BermudanExercise(exerciseDates);
AmericanExercise americanExercise = new AmericanExercise(settlementDate,
maturity);
Quote quote = new SimpleQuote(underlying);
QuoteHandle underlyingH = new QuoteHandle(quote);
// bootstrap the yield/dividend/vol curves
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,
strike);
BlackScholesMertonProcess stochasticProcess = new
BlackScholesMertonProcess(underlyingH, flatDividendTS, flatTermStructure,
flatVolTS);
// options
VanillaOption europeanOption = new
VanillaOption(stochasticProcess, payoff, europeanExercise);
VanillaOption bermudanOption = new
VanillaOption(stochasticProcess, payoff, bermudanExercise);
VanillaOption americanOption = new VanillaOption(stochasticProcess,
payoff, americanExercise);
string method = String.Empty;
string strNA = "N/A";
uint timeSteps = 801;
try
{
method = "Binomial Jarrow-Rudd";
europeanOption.setPricingEngine(new
BinomialConvertibleEngine("jarrowrudd", timeSteps));
bermudanOption.setPricingEngine(new
BinomialConvertibleEngine("jarrowrudd", timeSteps));
americanOption.setPricingEngine(new
BinomialConvertibleEngine("jarrowrudd", timeSteps));
Console.Write(method.PadRight(width[0]));
Console.Write(String.Format("{0:N6}",
europeanOption.NPV()).PadRight(width[1]));
Console.Write(String.Format("{0:N6}",
bermudanOption.NPV()).PadRight(width[2]));
Console.WriteLine("{0:N6}", americanOption.NPV());
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
| Free forum by Nabble | Edit this page |