From 9fce7a21300a96c6419714076dcffcd8eb44f3b2 Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Thu, 3 Oct 2024 17:20:34 +0200 Subject: [PATCH] Add several small new C++ methods and classes --- SWIG/blackformula.i | 8 +++++++ SWIG/calendars.i | 2 ++ SWIG/cashflows.i | 20 ++++++++++++++++++ SWIG/date.i | 2 ++ SWIG/fittedbondcurve.i | 48 +++++++++++++++++++++++++++++++++++++----- SWIG/inflation.i | 3 +++ SWIG/ratehelpers.i | 6 ++++-- 7 files changed, 82 insertions(+), 7 deletions(-) diff --git a/SWIG/blackformula.i b/SWIG/blackformula.i index 65def4c8b9..d710da5362 100644 --- a/SWIG/blackformula.i +++ b/SWIG/blackformula.i @@ -29,6 +29,7 @@ using QuantLib::blackFormulaImpliedStdDevLiRS; using QuantLib::blackFormulaCashItmProbability; using QuantLib::blackFormulaAssetItmProbability; using QuantLib::bachelierBlackFormula; +using QuantLib::bachelierBlackFormulaImpliedVolChoi; using QuantLib::bachelierBlackFormulaImpliedVol; using QuantLib::bachelierBlackFormulaAssetItmProbability; %} @@ -112,6 +113,13 @@ Real bachelierBlackFormulaImpliedVol(Option::Type optionType, Real bachelierPrice, Real discount = 1.0); +Real bachelierBlackFormulaImpliedVolChoi(Option::Type optionType, + Real strike, + Real forward, + Real tte, + Real bachelierPrice, + Real discount = 1.0); + Real bachelierBlackFormulaAssetItmProbability( Option::Type optionType, Real strike, diff --git a/SWIG/calendars.i b/SWIG/calendars.i index efb7deff62..f95e38604b 100644 --- a/SWIG/calendars.i +++ b/SWIG/calendars.i @@ -81,10 +81,12 @@ class Calendar { Calendar(); public: bool isWeekend(Weekday w); + Date startOfMonth(const Date&); Date endOfMonth(const Date&); bool isBusinessDay(const Date&); bool isHoliday(const Date&); bool isEndOfMonth(const Date&); + bool isStartOfMonth(const Date&); void addHoliday(const Date&); void removeHoliday(const Date&); void resetAddedAndRemovedHolidays(); diff --git a/SWIG/cashflows.i b/SWIG/cashflows.i index 415ab8f9f3..b84214c230 100644 --- a/SWIG/cashflows.i +++ b/SWIG/cashflows.i @@ -377,6 +377,8 @@ class SubPeriodsCoupon: public FloatingRateCoupon { using QuantLib::IborCouponPricer; using QuantLib::BlackIborCouponPricer; using QuantLib::SubPeriodsPricer; +using QuantLib::CompoundingOvernightIndexedCouponPricer; +using QuantLib::ArithmeticAveragedOvernightIndexedCouponPricer; using QuantLib::CompoundingRatePricer; using QuantLib::AveragingRatePricer; %} @@ -412,6 +414,24 @@ class SubPeriodsPricer: public FloatingRateCouponPricer { SubPeriodsPricer(); }; +%shared_ptr(CompoundingOvernightIndexedCouponPricer) +class CompoundingOvernightIndexedCouponPricer: public FloatingRateCouponPricer { + public: + CompoundingOvernightIndexedCouponPricer(); +}; + +%shared_ptr(ArithmeticAveragedOvernightIndexedCouponPricer) +class ArithmeticAveragedOvernightIndexedCouponPricer: public FloatingRateCouponPricer { + #if !defined(SWIGJAVA) && !defined(SWIGCSHARP) + %feature("kwargs") ArithmeticAveragedOvernightIndexedCouponPricer; + #endif + public: + ArithmeticAveragedOvernightIndexedCouponPricer( + Real meanReversion = 0.03, + Real volatility = 0.00, // NO convexity adjustment by default + bool byApprox = false); // TRUE to use Katsumi Takada approximation +}; + %shared_ptr(CompoundingRatePricer) class CompoundingRatePricer: public SubPeriodsPricer { public: diff --git a/SWIG/date.i b/SWIG/date.i index 4bc5088613..a2e0fc4c70 100644 --- a/SWIG/date.i +++ b/SWIG/date.i @@ -707,7 +707,9 @@ class Date { %#endif } } + static Date startOfMonth(const Date&); static Date endOfMonth(const Date&); + static bool isStartOfMonth(const Date&); static bool isEndOfMonth(const Date&); static Date nextWeekday(const Date&, Weekday); static Date nthWeekday(Size n, Weekday, Month m, Year y); diff --git a/SWIG/fittedbondcurve.i b/SWIG/fittedbondcurve.i index 9dad301ac8..0c34cfabd1 100644 --- a/SWIG/fittedbondcurve.i +++ b/SWIG/fittedbondcurve.i @@ -21,6 +21,7 @@ %include termstructures.i %include interpolation.i %include ratehelpers.i +%include optimizers.i %{ using QuantLib::FittedBondDiscountCurve; @@ -86,6 +87,9 @@ using QuantLib::SpreadFittingMethod; %shared_ptr(ExponentialSplinesFitting) class ExponentialSplinesFitting : public FittingMethod { + #if !defined(SWIGJAVA) && !defined(SWIGCSHARP) + %feature("kwargs") ExponentialSplinesFitting; + #endif public: ExponentialSplinesFitting(bool constrainAtZero = true, const Array& weights = Array(), @@ -93,44 +97,78 @@ class ExponentialSplinesFitting : public FittingMethod { Real minCutoffTime = 0.0, Real maxCutoffTime = QL_MAX_REAL, Size numCoeffs = 9, - Real fixedKappa = Null()); + Real fixedKappa = Null(), + Constraint constraint = NoConstraint()); }; %shared_ptr(NelsonSiegelFitting) class NelsonSiegelFitting : public FittingMethod { + #if !defined(SWIGJAVA) && !defined(SWIGCSHARP) + %feature("kwargs") NelsonSiegelFitting; + #endif public: - NelsonSiegelFitting(const Array& weights = Array()); + NelsonSiegelFitting(const Array& weights = Array(), + const ext::shared_ptr& optimizationMethod = {}, + const Array& l2 = Array(), + Real minCutoffTime = 0.0, + Real maxCutoffTime = QL_MAX_REAL, + Constraint constraint = NoConstraint()); }; %shared_ptr(SvenssonFitting) class SvenssonFitting : public FittingMethod { + #if !defined(SWIGJAVA) && !defined(SWIGCSHARP) + %feature("kwargs") SvenssonFitting; + #endif public: - SvenssonFitting(const Array& weights = Array()); + SvenssonFitting(const Array& weights = Array(), + const ext::shared_ptr& optimizationMethod = {}, + const Array& l2 = Array(), + Real minCutoffTime = 0.0, + Real maxCutoffTime = QL_MAX_REAL, + Constraint constraint = NoConstraint()); }; %shared_ptr(CubicBSplinesFitting) class CubicBSplinesFitting : public FittingMethod { + #if !defined(SWIGJAVA) && !defined(SWIGCSHARP) + %feature("kwargs") CubicBSplinesFitting; + #endif public: CubicBSplinesFitting(const std::vector