Skip to content

Commit 1b29862

Browse files
committed
Simplify two helper by removing an (ancient) try/catch layer
1 parent 03f3efd commit 1b29862

2 files changed

Lines changed: 37 additions & 40 deletions

File tree

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2026-03-28 Dirk Eddelbuettel <edd@debian.org>
2+
3+
* src/utils.cpp (getDividendSchedule,getCallabilitySchedule): Remove
4+
one old layer of try/catch and rely on the one provided by Rcpp
5+
16
2026-03-09 Dirk Eddelbuettel <edd@debian.org>
27

38
* src/vanilla.cpp (europeanOptionEngine,americanOptionEngine): More

src/utils.cpp

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -535,27 +535,23 @@ Rcpp::DataFrame getCashFlowDataFrame(const QuantLib::Leg &bondCashFlow) {
535535
QuantLib::DividendSchedule getDividendSchedule(Rcpp::DataFrame divScheDF) {
536536

537537
QuantLib::DividendSchedule dividendSchedule;
538-
try {
539-
Rcpp::CharacterVector s0v = divScheDF[0];
540-
Rcpp::NumericVector n1v = divScheDF[1];
541-
Rcpp::NumericVector n2v = divScheDF[2];
542-
Rcpp::NumericVector n3v = divScheDF[3];
543-
int nrow = s0v.size();
544-
545-
for (int row=0; row<nrow; row++){
546-
int type = (s0v[row] == "Fixed") ? 1 : 0; // (table[row][0].getStringValue()=="Fixed") ? 1 : 0;
547-
double amount = n1v[row]; // table[row][1].getDoubleValue();
548-
double rate = n2v[row]; // table[row][2].getDoubleValue();
549-
Rcpp::Date rd = Rcpp::Date(n3v[row]);
550-
QuantLib::Date d(Rcpp::as<QuantLib::Date>(Rcpp::wrap(rd))); //table[row][3].getDateValue()));
551-
if (type==1) {
552-
dividendSchedule.push_back(qlext::make_shared<QuantLib::FixedDividend>(amount, d));
553-
} else {
554-
dividendSchedule.push_back(qlext::make_shared<QuantLib::FractionalDividend>(rate, amount, d));
555-
}
538+
Rcpp::CharacterVector s0v = divScheDF[0];
539+
Rcpp::NumericVector n1v = divScheDF[1];
540+
Rcpp::NumericVector n2v = divScheDF[2];
541+
Rcpp::NumericVector n3v = divScheDF[3];
542+
int nrow = s0v.size();
543+
544+
for (int row=0; row<nrow; row++){
545+
int type = (s0v[row] == "Fixed") ? 1 : 0; // (table[row][0].getStringValue()=="Fixed") ? 1 : 0;
546+
double amount = n1v[row]; // table[row][1].getDoubleValue();
547+
double rate = n2v[row]; // table[row][2].getDoubleValue();
548+
Rcpp::Date rd = Rcpp::Date(n3v[row]);
549+
QuantLib::Date d(Rcpp::as<QuantLib::Date>(Rcpp::wrap(rd))); //table[row][3].getDateValue()));
550+
if (type==1) {
551+
dividendSchedule.push_back(qlext::make_shared<QuantLib::FixedDividend>(amount, d));
552+
} else {
553+
dividendSchedule.push_back(qlext::make_shared<QuantLib::FractionalDividend>(rate, amount, d));
556554
}
557-
} catch (std::exception& ex) {
558-
forward_exception_to_r(ex);
559555
}
560556
return dividendSchedule;
561557
}
@@ -574,27 +570,23 @@ QuantLib::CallabilitySchedule getCallabilitySchedule(Rcpp::DataFrame callScheDF)
574570
typedef QuantLib::Callability::Price QlBondPrice;
575571
#endif
576572

577-
try {
578-
// RcppFrame rcppCallabilitySchedule(callabilityScheduleFrame);
579-
// std::vector<std::vector<ColDatum> > table = rcppCallabilitySchedule.getTableData();
580-
// int nrow = table.size();
581-
Rcpp::NumericVector n0v = callScheDF[0];
582-
Rcpp::CharacterVector s1v = callScheDF[1];
583-
Rcpp::NumericVector n2v = callScheDF[2];
584-
int nrow = n0v.size();
585-
for (int row=0; row<nrow; row++) {
586-
double price = n0v[row]; //table[row][0].getDoubleValue();
587-
int type = (s1v[row]=="P") ? 1 : 0;
588-
Rcpp::Date rd = Rcpp::Date(n2v[row]);
589-
QuantLib::Date d(Rcpp::as<QuantLib::Date>(Rcpp::wrap(rd)));
590-
if (type==1){
591-
callabilitySchedule.push_back(qlext::make_shared<QuantLib::Callability>(QlBondPrice(price, QlBondPrice::Clean), QuantLib::Callability::Put, d));
592-
} else {
593-
callabilitySchedule.push_back(qlext::make_shared<QuantLib::Callability>(QlBondPrice(price, QlBondPrice::Clean), QuantLib::Callability::Call, d));
594-
}
573+
// RcppFrame rcppCallabilitySchedule(callabilityScheduleFrame);
574+
// std::vector<std::vector<ColDatum> > table = rcppCallabilitySchedule.getTableData();
575+
// int nrow = table.size();
576+
Rcpp::NumericVector n0v = callScheDF[0];
577+
Rcpp::CharacterVector s1v = callScheDF[1];
578+
Rcpp::NumericVector n2v = callScheDF[2];
579+
int nrow = n0v.size();
580+
for (int row=0; row<nrow; row++) {
581+
double price = n0v[row]; //table[row][0].getDoubleValue();
582+
int type = (s1v[row]=="P") ? 1 : 0;
583+
Rcpp::Date rd = Rcpp::Date(n2v[row]);
584+
QuantLib::Date d(Rcpp::as<QuantLib::Date>(Rcpp::wrap(rd)));
585+
if (type==1){
586+
callabilitySchedule.push_back(qlext::make_shared<QuantLib::Callability>(QlBondPrice(price, QlBondPrice::Clean), QuantLib::Callability::Put, d));
587+
} else {
588+
callabilitySchedule.push_back(qlext::make_shared<QuantLib::Callability>(QlBondPrice(price, QlBondPrice::Clean), QuantLib::Callability::Call, d));
595589
}
596-
} catch (std::exception& ex){
597-
forward_exception_to_r(ex);
598590
}
599591
return callabilitySchedule;
600592
}

0 commit comments

Comments
 (0)