From 6c35a2426f97945ebf68126b445524cfe2e63b0a Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Wed, 3 Apr 2024 13:24:16 +0200 Subject: [PATCH] Export more overloads for bond functions --- SWIG/bondfunctions.i | 63 +++++++++++++++++++++++++++++++++++++++++++- SWIG/bonds.i | 9 +++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/SWIG/bondfunctions.i b/SWIG/bondfunctions.i index 23efa337a4..e38f558eeb 100644 --- a/SWIG/bondfunctions.i +++ b/SWIG/bondfunctions.i @@ -69,13 +69,20 @@ class BondFunctions { static Real cleanPrice(const Bond& bond, const YieldTermStructure& discountCurve, Date settlementDate = Date()); + static Real dirtyPrice(const Bond& bond, + const YieldTermStructure& discountCurve, + Date settlementDate = Date()); static Real bps(const Bond& bond, const YieldTermStructure& discountCurve, Date settlementDate = Date()); static Rate atmRate(const Bond& bond, const YieldTermStructure& discountCurve, Date settlementDate = Date(), - Real cleanPrice = Null()); + BondPrice price = {}); + static Rate atmRate(const Bond& bond, + const YieldTermStructure& discountCurve, + Date settlementDate, + Real cleanPrice); static Real cleanPrice(const Bond& bond, const InterestRate& yield, @@ -95,6 +102,15 @@ class BondFunctions { Compounding compounding, Frequency frequency, Date settlementDate = Date()); + static Rate yield(const Bond& bond, + BondPrice price, + const DayCounter& dayCounter, + Compounding compounding, + Frequency frequency, + Date settlementDate = Date(), + Real accuracy = 1.0e-10, + Size maxIterations = 100, + Rate guess = 0.05); static Rate yield(const Bond& bond, Real cleanPrice, const DayCounter& dayCounter, @@ -143,6 +159,31 @@ class BondFunctions { Compounding compounding, Frequency frequency, Date settlementDate = Date()); + + static Real cleanPrice(const Bond& bond, + const ext::shared_ptr& discount, + Spread zSpread, + const DayCounter& dayCounter, + Compounding compounding, + Frequency frequency, + Date settlementDate = Date()); + static Real dirtyPrice(const Bond& bond, + const ext::shared_ptr& discount, + Spread zSpread, + const DayCounter& dayCounter, + Compounding compounding, + Frequency frequency, + Date settlementDate = Date()); + static Spread zSpread(const Bond& bond, + BondPrice price, + const ext::shared_ptr& discountCurve, + const DayCounter& dayCounter, + Compounding compounding, + Frequency frequency, + Date settlementDate = Date(), + Real accuracy = 1.0e-10, + Size maxIterations = 100, + Rate guess = 0.0); static Spread zSpread(const Bond& bond, Real cleanPrice, const ext::shared_ptr& discountCurve, @@ -157,6 +198,26 @@ class BondFunctions { %extend { %define DefineYieldFunctionSolver(SolverType) + static Rate yield ## SolverType(SolverType solver, + const Bond& bond, + BondPrice price, + const DayCounter& dayCounter, + Compounding compounding, + Frequency frequency, + Date settlementDate = Date(), + Real accuracy = 1.0e-10, + Rate guess = 0.05) { + return QuantLib::BondFunctions::yield( + solver, + bond, + price, + dayCounter, + compounding, + frequency, + settlementDate, + accuracy, + guess); + } static Rate yield ## SolverType(SolverType solver, const Bond& bond, Real cleanPrice, diff --git a/SWIG/bonds.i b/SWIG/bonds.i index 608cc99600..0cdf0514a8 100644 --- a/SWIG/bonds.i +++ b/SWIG/bonds.i @@ -52,6 +52,7 @@ class BondPrice { BondPrice(Real amount, Type type); Real amount() const; Type type() const; + bool isValid() const; }; %shared_ptr(Bond) @@ -103,6 +104,14 @@ class Bond : public Instrument { Frequency freq, Real accuracy = 1.0e-8, Size maxEvaluations = 100); + Real yield(BondPrice price, + const DayCounter& dc, + Compounding compounding, + Frequency freq, + const Date& settlement = Date(), + Real accuracy = 1.0e-8, + Size maxEvaluations = 100, + Real guess = 0.05); Real yield(Real cleanPrice, const DayCounter& dc, Compounding compounding,