Skip to content

Commit bd0e09d

Browse files
committed
Support time to expiry or maturity date in BarrierOption
1 parent 89710e7 commit bd0e09d

5 files changed

Lines changed: 25 additions & 12 deletions

File tree

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2026-04-07 Dirk Eddelbuettel <edd@debian.org>
2+
3+
* src/barrier_binary.cpp (barrierOptionEngine): For barrier option,
4+
more careful about use of evaluation date, new parameter daycounter
5+
* R/option.R (BarrierOption.default): Allow fractional year to
6+
expiry as well as date
7+
* src/RcppExports.cpp: Regenerated
8+
* R/RcppExports.R: Idem
9+
110
2026-03-28 Dirk Eddelbuettel <edd@debian.org>
211

312
* src/utils.cpp (getDividendSchedule,getCallabilitySchedule): Remove

R/RcppExports.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ binaryOptionImpliedVolatilityEngine <- function(type, value, underlying, strike,
1717
.Call(`_RQuantLib_binaryOptionImpliedVolatilityEngine`, type, value, underlying, strike, dividendYield, riskFreeRate, maturity, exDate, volatility, cashPayoff, dayCounter)
1818
}
1919

20-
barrierOptionEngine <- function(barrType, type, underlying, strike, dividendYield, riskFreeRate, maturity, volatility, barrier, rebate, dayCounter) {
21-
.Call(`_RQuantLib_barrierOptionEngine`, barrType, type, underlying, strike, dividendYield, riskFreeRate, maturity, volatility, barrier, rebate, dayCounter)
20+
barrierOptionEngine <- function(barrType, type, underlying, strike, dividendYield, riskFreeRate, maturity, exDate, volatility, barrier, rebate, dayCounter) {
21+
.Call(`_RQuantLib_barrierOptionEngine`, barrType, type, underlying, strike, dividendYield, riskFreeRate, maturity, exDate, volatility, barrier, rebate, dayCounter)
2222
}
2323

2424
bermudanFromYieldEngine <- function(rparam, yield, swaptionMat, swapLengths, swaptionVols) {

R/option.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ BarrierOption.default <- function(barrType, type, underlying, strike,
9191
volatility, barrier, rebate=0.0, dayCounter=0) {
9292
type <- match.arg(type, c("call", "put"))
9393
barrType <- match.arg(barrType, c("downin", "upin", "downout", "upout"))
94-
val <- barrierOptionEngine(barrType, type, underlying, strike, dividendYield,
95-
riskFreeRate, maturity, volatility, barrier, rebate, dayCounter)
94+
val <- barrierOptionEngine(barrType, type, underlying, strike, dividendYield, riskFreeRate,
95+
if (inherits(maturity, "numeric")) maturity else NULL,
96+
if (inherits(maturity, "Date")) maturity else NULL,
97+
volatility, barrier, rebate, dayCounter)
9698
class(val) <- c("BarrierOption", "Option")
9799
val
98100
}

src/RcppExports.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ BEGIN_RCPP
9595
END_RCPP
9696
}
9797
// barrierOptionEngine
98-
Rcpp::List barrierOptionEngine(std::string barrType, std::string type, double underlying, double strike, double dividendYield, double riskFreeRate, double maturity, double volatility, double barrier, double rebate, int dayCounter);
99-
RcppExport SEXP _RQuantLib_barrierOptionEngine(SEXP barrTypeSEXP, SEXP typeSEXP, SEXP underlyingSEXP, SEXP strikeSEXP, SEXP dividendYieldSEXP, SEXP riskFreeRateSEXP, SEXP maturitySEXP, SEXP volatilitySEXP, SEXP barrierSEXP, SEXP rebateSEXP, SEXP dayCounterSEXP) {
98+
Rcpp::List barrierOptionEngine(std::string barrType, std::string type, double underlying, double strike, double dividendYield, double riskFreeRate, Rcpp::Nullable<double> maturity, Rcpp::Nullable<QuantLib::Date> exDate, double volatility, double barrier, double rebate, int dayCounter);
99+
RcppExport SEXP _RQuantLib_barrierOptionEngine(SEXP barrTypeSEXP, SEXP typeSEXP, SEXP underlyingSEXP, SEXP strikeSEXP, SEXP dividendYieldSEXP, SEXP riskFreeRateSEXP, SEXP maturitySEXP, SEXP exDateSEXP, SEXP volatilitySEXP, SEXP barrierSEXP, SEXP rebateSEXP, SEXP dayCounterSEXP) {
100100
BEGIN_RCPP
101101
Rcpp::RObject rcpp_result_gen;
102102
Rcpp::RNGScope rcpp_rngScope_gen;
@@ -106,12 +106,13 @@ BEGIN_RCPP
106106
Rcpp::traits::input_parameter< double >::type strike(strikeSEXP);
107107
Rcpp::traits::input_parameter< double >::type dividendYield(dividendYieldSEXP);
108108
Rcpp::traits::input_parameter< double >::type riskFreeRate(riskFreeRateSEXP);
109-
Rcpp::traits::input_parameter< double >::type maturity(maturitySEXP);
109+
Rcpp::traits::input_parameter< Rcpp::Nullable<double> >::type maturity(maturitySEXP);
110+
Rcpp::traits::input_parameter< Rcpp::Nullable<QuantLib::Date> >::type exDate(exDateSEXP);
110111
Rcpp::traits::input_parameter< double >::type volatility(volatilitySEXP);
111112
Rcpp::traits::input_parameter< double >::type barrier(barrierSEXP);
112113
Rcpp::traits::input_parameter< double >::type rebate(rebateSEXP);
113114
Rcpp::traits::input_parameter< int >::type dayCounter(dayCounterSEXP);
114-
rcpp_result_gen = Rcpp::wrap(barrierOptionEngine(barrType, type, underlying, strike, dividendYield, riskFreeRate, maturity, volatility, barrier, rebate, dayCounter));
115+
rcpp_result_gen = Rcpp::wrap(barrierOptionEngine(barrType, type, underlying, strike, dividendYield, riskFreeRate, maturity, exDate, volatility, barrier, rebate, dayCounter));
115116
return rcpp_result_gen;
116117
END_RCPP
117118
}
@@ -1715,7 +1716,7 @@ static const R_CallMethodDef CallEntries[] = {
17151716
{"_RQuantLib_asianOptionEngine", (DL_FUNC) &_RQuantLib_asianOptionEngine, 11},
17161717
{"_RQuantLib_binaryOptionEngine", (DL_FUNC) &_RQuantLib_binaryOptionEngine, 12},
17171718
{"_RQuantLib_binaryOptionImpliedVolatilityEngine", (DL_FUNC) &_RQuantLib_binaryOptionImpliedVolatilityEngine, 11},
1718-
{"_RQuantLib_barrierOptionEngine", (DL_FUNC) &_RQuantLib_barrierOptionEngine, 11},
1719+
{"_RQuantLib_barrierOptionEngine", (DL_FUNC) &_RQuantLib_barrierOptionEngine, 12},
17191720
{"_RQuantLib_bermudanFromYieldEngine", (DL_FUNC) &_RQuantLib_bermudanFromYieldEngine, 5},
17201721
{"_RQuantLib_bermudanWithRebuiltCurveEngine", (DL_FUNC) &_RQuantLib_bermudanWithRebuiltCurveEngine, 6},
17211722
{"_RQuantLib_zeroPriceByYieldEngine", (DL_FUNC) &_RQuantLib_zeroPriceByYieldEngine, 8},

src/barrier_binary.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ Rcpp::List barrierOptionEngine(std::string barrType,
151151
double strike,
152152
double dividendYield,
153153
double riskFreeRate,
154-
double maturity,
154+
Rcpp::Nullable<double> maturity,
155+
Rcpp::Nullable<QuantLib::Date> exDate,
155156
double volatility,
156157
double barrier,
157158
double rebate,
@@ -176,8 +177,8 @@ Rcpp::List barrierOptionEngine(std::string barrType,
176177
// updated again for QuantLib 0.9.0,
177178
// cf QuantLib-0.9.0/test-suite/barrieroption.cpp
178179
QuantLib::Date evalDate = QuantLib::Settings::instance().evaluationDate();
180+
QuantLib::Date expiryDate = getFutureDate(evalDate, maturity, exDate);
179181
QuantLib::DayCounter dc = getDayCounter(dayCounter);
180-
QuantLib::Date exDate = getFutureDate(evalDate, maturity);
181182
auto spot = qlext::make_shared<QuantLib::SimpleQuote>(underlying);
182183
auto qRate = qlext::make_shared<QuantLib::SimpleQuote>(dividendYield);
183184
auto qTS = flatRate(evalDate, qRate, dc);
@@ -186,7 +187,7 @@ Rcpp::List barrierOptionEngine(std::string barrType,
186187
auto vol = qlext::make_shared<QuantLib::SimpleQuote>(volatility);
187188
auto volTS = flatVol(evalDate, vol, dc);
188189

189-
auto exercise = qlext::make_shared<QuantLib::EuropeanExercise>(exDate);
190+
auto exercise = qlext::make_shared<QuantLib::EuropeanExercise>(expiryDate);
190191

191192
auto payoff = qlext::make_shared<QuantLib::PlainVanillaPayoff>(optionType, strike);
192193

0 commit comments

Comments
 (0)