EquityOption in C#

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

EquityOption in C#

Mike Allen-4

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 Main(string[] args)

{

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());

}

}

}

}


___________________________________________________
NOTE: The information in this email is confidential and may be
legally privileged. If you are not the intended recipient, please
delete this email without reading, using or disseminating it, and
notify us immediately. All emails sent to and from VDM Specialists
are recorded and archived, monitored, and/or disclosed to
someone other than the recipient. Although this email and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received
and opened, it is the responsibility of the recipient to ensure
that it is virus free and no responsibility is accepted by VDM
Specialists for any loss or damage arising in any way from its use.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users