Posted by
Jeff Yan on
URL: http://quantlib.414.s1.nabble.com/american-options-via-trinomial-trees-tp6966p6970.html
Hey
I am trying to price American Options with discrete dividends in Java, through SWIG, JNI, to QuantLib (C++ version). Everything goes well until the last step: calling option.NPV() method crashes with JNI error.
I believe my Swig/JNI bridge works because I am able to price American Option with continuous dividend yield successfully. I think the problem is my code calling handling discrete dividends that goes wrong
Please see the following Java code. Any suggestion is greatly appreciated!
// our option
Option.Type type = Option.Type.Put;
double strike = 40.0;
double underlying = 36.0;
double riskFreeRate = 0.06;
double dividendYield = 0.00;
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();
Calendar calendar = new TARGET();
Exercise americanExercise = new AmericanExercise(settlementDate, maturity);
// define the underlying asset and the yield/dividend/volatility curves
QuoteHandle underlyingH = new QuoteHandle(new SimpleQuote(underlying));
YieldTermStructureHandle flatTermStructure =
new YieldTermStructureHandle(new FlatForward(
settlementDate, riskFreeRate, dayCounter));
YieldTermStructureHandle flatDividendYield =
new YieldTermStructureHandle(new FlatForward(
settlementDate, dividendYield, dayCounter));
BlackVolTermStructureHandle flatVolatility =
new BlackVolTermStructureHandle(new BlackConstantVol(
settlementDate, calendar, volatility, dayCounter));
BlackScholesMertonProcess process =
new BlackScholesMertonProcess(underlyingH,
flatDividendYield,
flatTermStructure,
flatVolatility);
// options
Payoff payoff = new PlainVanillaPayoff(type, strike);
DateVector divDates = new DateVector();
DoubleVector divs = new DoubleVector();
divs.add(0.5);
divDates.add(new Date(1, Month.October, 2010));
DividendVanillaOption americanOption = new DividendVanillaOption(payoff, americanExercise, divDates, divs);
FDDividendAmericanEngine engine = new FDDividendAmericanEngine(process);
americanOption.setPricingEngine(engine );
// Binomial method
int timeSteps = 801;
americanOption.setPricingEngine(new BinomialVanillaEngine(process, "CoxRossRubinstein", timeSteps));
System.out.println("before calling npv");
crashes here
System.out.println("npv=" + americanOption.NPV() );
The information contained in this electronic message is confidential and does not constitute investment advice or an offer to sell or the solicitation of an offer to purchase any security or investment product. Offers may only be made by means of delivery of an approved confidential offering memorandum, may be legally privileged and confidential under applicable law, and are intended only for the use of the individual or entity named above. We do not, and will not, effect or attempt to effect transactions in securities, or render personalized investment advice for compensation, through this email. All materials within this email have been provided to you for information purposes only and may not be relied upon by you in evaluating the merits of investing in any securities referenced herein. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. Email transmissions are not secure, and we accept no liability for errors in transmission, delayed transmission, or other transmission-related issues. This message may contain confidential, proprietary or legally privileged information. Neither confidentiality nor any privilege is intended to be waived or lost by any error in transmission. Emails are subject to review and will be archived.
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users