diff --git a/ChangeLog b/ChangeLog index bb412d1..a631f42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2024-07-24 Dirk Eddelbuettel + + * src/vanilla.cpp: Accommodate builds on QuantLib versions as old as + 1.25 by retaining the previous dividend treatment under #ifdef + 2024-07-23 Dirk Eddelbuettel * DESCRIPTION (Version, Date): New release 0.4.23 diff --git a/src/vanilla.cpp b/src/vanilla.cpp index 7988314..cee2b37 100644 --- a/src/vanilla.cpp +++ b/src/vanilla.cpp @@ -67,9 +67,15 @@ Rcpp::List europeanOptionEngine(std::string type, QuantLib::Handle(rTS), QuantLib::Handle(volTS)); +#if QL_HEX_VERSION >= 0x013500c0 auto engine = qlext::make_shared(stochProcess, QuantLib::DividendVector(discDivDates, discDividends)); - QuantLib::VanillaOption option(payoff, exercise); +#else + QL_DEPRECATED_DISABLE_WARNING + auto qlext::shared_ptr(stochProcess)); + QuantLib::DividendVanillaOption option(payoff, exercise, discDivDates, discDividends); + QL_DEPRECATED_ENABLE_WARNING +#endif option.setPricingEngine(engine); return Rcpp::List::create(Rcpp::Named("value") = option.NPV(), @@ -143,7 +149,13 @@ Rcpp::List americanOptionEngine(std::string type, discDividends[i] = divvalues[i]; } +#if QL_HEX_VERSION >= 0x013500c0 QuantLib::VanillaOption option(payoff, exercise); +#else + QL_DEPRECATED_DISABLE_WARNING + QuantLib::DividendVanillaOption option(payoff, exercise, discDivDates, discDividends); + QL_DEPRECATED_ENABLE_WARNING +#endif if (engine=="BaroneAdesiWhaley") { Rcpp::warning("Discrete dividends, engine switched to CrankNicolson"); @@ -151,8 +163,15 @@ Rcpp::List americanOptionEngine(std::string type, } if (engine=="CrankNicolson") { // FDDividendAmericanEngine only works with CrankNicolson +#if QL_HEX_VERSION >= 0x013500c0 // see eg test-suite/americanoption.cc option.setPricingEngine(QuantLib::MakeFdBlackScholesVanillaEngine(stochProcess).withCashDividends(discDivDates, discDividends)); +#else + // suggestion by Bryan Lewis: use CrankNicolson for greeks + QuantLib::ext::shared_ptr + fdcnengine(new QuantLib::FdBlackScholesVanillaEngine(stochProcess, timeSteps, gridPoints)); + option.setPricingEngine(fdcnengine); +#endif return Rcpp::List::create(Rcpp::Named("value") = option.NPV(), Rcpp::Named("delta") = option.delta(), Rcpp::Named("gamma") = option.gamma(),