Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export more overloads for bond functions #636

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion SWIG/bondfunctions.i
Original file line number Diff line number Diff line change
Expand Up @@ -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<Real>());
BondPrice price = {});
static Rate atmRate(const Bond& bond,
const YieldTermStructure& discountCurve,
Date settlementDate,
Real cleanPrice);

static Real cleanPrice(const Bond& bond,
const InterestRate& yield,
Expand All @@ -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,
Expand Down Expand Up @@ -143,6 +159,31 @@ class BondFunctions {
Compounding compounding,
Frequency frequency,
Date settlementDate = Date());

static Real cleanPrice(const Bond& bond,
const ext::shared_ptr<YieldTermStructure>& discount,
Spread zSpread,
const DayCounter& dayCounter,
Compounding compounding,
Frequency frequency,
Date settlementDate = Date());
static Real dirtyPrice(const Bond& bond,
const ext::shared_ptr<YieldTermStructure>& 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<YieldTermStructure>& 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<YieldTermStructure>& discountCurve,
Expand All @@ -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<SolverType>(
solver,
bond,
price,
dayCounter,
compounding,
frequency,
settlementDate,
accuracy,
guess);
}
static Rate yield ## SolverType(SolverType solver,
const Bond& bond,
Real cleanPrice,
Expand Down
9 changes: 9 additions & 0 deletions SWIG/bonds.i
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class BondPrice {
BondPrice(Real amount, Type type);
Real amount() const;
Type type() const;
bool isValid() const;
};

%shared_ptr(Bond)
Expand Down Expand Up @@ -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,
Expand Down