Skip to content

Commit

Permalink
Accommodate old QL releases (such as 1.25) in src/vanilla.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Jul 24, 2024
1 parent b4b4c28 commit e26307c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2024-07-24 Dirk Eddelbuettel <[email protected]>

* 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 <[email protected]>

* DESCRIPTION (Version, Date): New release 0.4.23
Expand Down
21 changes: 20 additions & 1 deletion src/vanilla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@ Rcpp::List europeanOptionEngine(std::string type,
QuantLib::Handle<QuantLib::YieldTermStructure>(rTS),
QuantLib::Handle<QuantLib::BlackVolTermStructure>(volTS));

#if QL_HEX_VERSION >= 0x013500c0
auto engine = qlext::make_shared<QuantLib::AnalyticDividendEuropeanEngine>(stochProcess, QuantLib::DividendVector(discDivDates, discDividends));

QuantLib::VanillaOption option(payoff, exercise);
#else
QL_DEPRECATED_DISABLE_WARNING
auto qlext::shared_ptr<QuantLib::AnalyticDividendEuropeanEngine>(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(),
Expand Down Expand Up @@ -143,16 +149,29 @@ 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");
engine = "CrankNicolson";
}

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<QuantLib::PricingEngine>
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(),
Expand Down

0 comments on commit e26307c

Please sign in to comment.