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 20b554c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ jobs:
- name: Test
run: ./run.sh run_tests

- name: Logs
if: failure()
run: ./run.sh dump_logs

#- name: Coverage
# if: ${{ matrix.os == 'ubuntu-latest' }}
# run: ./run.sh coverage
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
19 changes: 18 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 || defined(__APPLE__)
auto engine = qlext::make_shared<QuantLib::AnalyticDividendEuropeanEngine>(stochProcess, QuantLib::DividendVector(discDivDates, discDividends));

QuantLib::VanillaOption option(payoff, exercise);
#else
QL_DEPRECATED_DISABLE_WARNING
auto engine = qlext::make_shared<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,27 @@ Rcpp::List americanOptionEngine(std::string type,
discDividends[i] = divvalues[i];
}

#if QL_HEX_VERSION >= 0x013500c0 || defined(__APPLE__)
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 || defined(__APPLE__)
// see eg test-suite/americanoption.cc
option.setPricingEngine(QuantLib::MakeFdBlackScholesVanillaEngine(stochProcess).withCashDividends(discDivDates, discDividends));
#else
auto fdcengine = qlext::make_shared<QuantLib::FdBlackScholesVanillaEngine>(stochProcess, timeSteps, gridPoints);
option.setPricingEngine(fdcengine);
#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 20b554c

Please sign in to comment.