Skip to content

Commit

Permalink
Add several small new C++ methods and classes (#674)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio authored Oct 3, 2024
2 parents bcaffb1 + 9fce7a2 commit feeb392
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 7 deletions.
8 changes: 8 additions & 0 deletions SWIG/blackformula.i
Original file line number Diff line number Diff line change
Expand Up @@ -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;
%}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions SWIG/calendars.i
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions SWIG/cashflows.i
Original file line number Diff line number Diff line change
Expand Up @@ -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;
%}
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions SWIG/date.i
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
48 changes: 43 additions & 5 deletions SWIG/fittedbondcurve.i
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
%include termstructures.i
%include interpolation.i
%include ratehelpers.i
%include optimizers.i

%{
using QuantLib::FittedBondDiscountCurve;
Expand Down Expand Up @@ -86,51 +87,88 @@ 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(),
const Array& l2 = Array(),
Real minCutoffTime = 0.0,
Real maxCutoffTime = QL_MAX_REAL,
Size numCoeffs = 9,
Real fixedKappa = Null<Real>());
Real fixedKappa = Null<Real>(),
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>& 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>& 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<Time>& knotVector,
bool constrainAtZero = true,
const Array& weights = Array());
const Array& weights = Array(),
const Array& l2 = Array(),
Real minCutoffTime = 0.0,
Real maxCutoffTime = QL_MAX_REAL,
Constraint constraint = NoConstraint());
Real basisFunction(Integer i, Time t);
};

%shared_ptr(SimplePolynomialFitting)
class SimplePolynomialFitting : public FittingMethod {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") SimplePolynomialFitting;
#endif
public:
#if defined(SWIGJAVA)
SimplePolynomialFitting(Natural degree);
#else
SimplePolynomialFitting(Natural degree,
bool constrainAtZero = true,
const Array& weights = Array());
const Array& weights = Array(),
const Array& l2 = Array(),
Real minCutoffTime = 0.0,
Real maxCutoffTime = QL_MAX_REAL,
Constraint constraint = NoConstraint());
#endif
};

%shared_ptr(SpreadFittingMethod)
class SpreadFittingMethod : public FittingMethod {
#if !defined(SWIGJAVA) && !defined(SWIGCSHARP)
%feature("kwargs") SpreadFittingMethod;
#endif
public:
SpreadFittingMethod(const ext::shared_ptr<FittingMethod>& method,
Handle<YieldTermStructure> discountCurve,
Expand Down
3 changes: 3 additions & 0 deletions SWIG/inflation.i
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class ZeroInflationIndex : public InflationIndex {
Date lastFixingDate() const;
Handle<ZeroInflationTermStructure> zeroInflationTermStructure() const;
ext::shared_ptr<ZeroInflationIndex> clone(const Handle<ZeroInflationTermStructure>& h) const;
bool needsForecast(const Date& fixingDate) const;
};

%inline %{
Expand Down Expand Up @@ -196,11 +197,13 @@ class YoYInflationIndex : public InflationIndex {
const Currency& currency,
Handle<YoYInflationTermStructure> ts = {});

Date lastFixingDate() const;
bool ratio() const;
bool interpolated() const;
ext::shared_ptr<ZeroInflationIndex> underlyingIndex() const;
Handle<YoYInflationTermStructure> yoyInflationTermStructure() const;
ext::shared_ptr<YoYInflationIndex> clone(const Handle<YoYInflationTermStructure>& h) const;
bool needsForecast(const Date& fixingDate) const;
};

%define export_zii_instance(Name)
Expand Down
6 changes: 4 additions & 2 deletions SWIG/ratehelpers.i
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ class OISRateHelper : public RateHelper {
const Calendar& fixedCalendar = Calendar(),
Natural lookbackDays = Null<Natural>(),
Natural lockoutDays = 0,
bool applyObservationShift = false);
bool applyObservationShift = false,
ext::shared_ptr<FloatingRateCouponPricer> pricer = {});
ext::shared_ptr<OvernightIndexedSwap> swap();
};

Expand Down Expand Up @@ -363,7 +364,8 @@ class DatedOISRateHelper : public RateHelper {
const Calendar& fixedCalendar = Calendar(),
Natural lookbackDays = Null<Natural>(),
Natural lockoutDays = 0,
bool applyObservationShift = false);
bool applyObservationShift = false,
ext::shared_ptr<FloatingRateCouponPricer> pricer = {});
};

%shared_ptr(FxSwapRateHelper)
Expand Down

0 comments on commit feeb392

Please sign in to comment.