Skip to content

Commit b14db5b

Browse files
committed
QPR-12302 python interface
1 parent 2e7fd3f commit b14db5b

7 files changed

Lines changed: 57 additions & 189 deletions

File tree

Docs/ore-swig.tex

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ \subsection*{QuantExt Interfaces}
184184
\subitem DiscountingFxForward
185185
\subitem Payment
186186
\subitem PaymentDiscountingEngine
187-
\subitem OvernightIndexedBasisSwap
188187
\subitem Deposit
189188
\subitem DepositEngine
190189
\subitem DiscountingSwapEngineMultiCurve
@@ -195,7 +194,6 @@ \subsection*{QuantExt Interfaces}
195194
\subitem SubPeriodsSwapHelper
196195
\subitem SubPeriodsCoupon1
197196
\subitem OICCBSHelper
198-
\subitem OIBSHelper
199197
\subitem BasisTwoSwapHelper
200198
\subitem ImmFraRateHelper
201199
\subitem CrossCcyFixFloatSwapHelper

OREAnalytics-SWIG/Python/test/test_instruments.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -312,68 +312,6 @@ def testConsistency(self):
312312
fair_rec_spread)
313313
swap.setPricingEngine(self.engine)
314314
self.assertFalse(abs(swap.NPV()) > tolerance)
315-
316-
class OvernightIndexedBasisSwapTest(unittest.TestCase):
317-
def setUp(self):
318-
""" Set-up OvernightIndexedBasisSwap"""
319-
self.todays_date = Date(4, October, 2018)
320-
Settings.instance().evaluationDate = self.todays_date
321-
self.settlement_date = Date(6, October, 2018)
322-
self.swap_tenor = Period(10, Years)
323-
self.pay_tenor = Period(3, Months)
324-
self.calendar = UnitedStates(UnitedStates.NYSE)
325-
self.maturity_date = self.calendar.advance(self.settlement_date, self.swap_tenor)
326-
self.type = OvernightIndexedBasisSwap.Payer
327-
self.bdc = ModifiedFollowing
328-
self.day_counter = Actual365Fixed()
329-
self.nominal = 10000000
330-
self.schedule = Schedule(self.settlement_date, self.maturity_date,
331-
self.pay_tenor, self.calendar,
332-
self.bdc, self.bdc, DateGeneration.Forward, False)
333-
self.OIS_flat_forward = FlatForward(self.todays_date, 0.01, self.day_counter)
334-
self.OIS_term_structure = RelinkableYieldTermStructureHandle(self.OIS_flat_forward)
335-
self.OIS_index = FedFunds(self.OIS_term_structure)
336-
self.LIBOR_flat_forward = FlatForward(self.todays_date, 0.03, self.day_counter)
337-
self.LIBOR_term_structure = RelinkableYieldTermStructureHandle(self.LIBOR_flat_forward)
338-
self.LIBOR_index = USDLibor(Period(3, Months), self.LIBOR_term_structure)
339-
self.OIS_spread = 0.005
340-
self.LIBOR_spread = 0.0
341-
self.spreadOnShort = True
342-
self.swap = OvernightIndexedBasisSwap(self.type, self.nominal, self.schedule,
343-
self.OIS_index, self.schedule, self.LIBOR_index,
344-
self.spreadOnShort, self.OIS_spread, self.LIBOR_spread)
345-
self.engine = DiscountingSwapEngine(self.OIS_term_structure)
346-
self.swap.setPricingEngine(self.engine)
347-
348-
def testSimpleInspectors(self):
349-
""" Test OvernightIndexedBasisSwap simple inspectors. """
350-
self.assertEqual(self.swap.nominal(), self.nominal)
351-
self.assertEqual(self.swap.oisSpread(), self.OIS_spread)
352-
self.assertEqual(self.swap.iborSpread(), self.LIBOR_spread)
353-
354-
def testSchedules(self):
355-
""" Test OvernightIndexedBasisSwap schedules. """
356-
for i, d in enumerate(self.schedule):
357-
self.assertEqual(self.swap.oisSchedule()[i], d)
358-
self.assertEqual(self.swap.iborSchedule()[i], d)
359-
360-
def testConsistency(self):
361-
""" Test consistency of fair price and NPV() """
362-
tolerance = 1.0e-8
363-
fair_OIS_spread = self.swap.fairOvernightSpread()
364-
swap = OvernightIndexedBasisSwap(self.type, self.nominal, self.schedule,
365-
self.OIS_index, self.schedule, self.LIBOR_index,
366-
self.spreadOnShort, fair_OIS_spread, self.LIBOR_spread)
367-
swap.setPricingEngine(self.engine)
368-
self.assertFalse(abs(swap.NPV()) > tolerance)
369-
fair_LIBOR_spread = self.swap.fairIborSpread()
370-
swap = OvernightIndexedBasisSwap(self.type, self.nominal, self.schedule,
371-
self.OIS_index, self.schedule, self.LIBOR_index,
372-
self.spreadOnShort, self.OIS_spread, fair_LIBOR_spread)
373-
swap.setPricingEngine(self.engine)
374-
self.assertFalse(abs(swap.NPV()) > tolerance)
375-
376-
377315
class AverageOISTest(unittest.TestCase):
378316
def setUp(self):
379317
""" Set-up AverageOIS and engine """
@@ -885,7 +823,6 @@ def testConsistency(self):
885823
suite.addTest(unittest.makeSuite(EquityForwardTest, 'test'))
886824
suite.addTest(unittest.makeSuite(PaymentTest, 'test'))
887825
suite.addTest(unittest.makeSuite(AverageOISTest, 'test'))
888-
suite.addTest(unittest.makeSuite(OvernightIndexedBasisSwapTest, 'test'))
889826
suite.addTest(unittest.makeSuite(OvernightIndexedCrossCcyBasisSwapTest, 'test'))
890827
suite.addTest(unittest.makeSuite(CreditDefaultSwapTest, 'test'))
891828
suite.addTest(unittest.makeSuite(CDSOptionTest, 'test'))

OREAnalytics-SWIG/Python/test/test_ratehelpers.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,6 @@ def testSimpleInspectors(self):
119119
""" Test SubPeriods Basis Swap Helper simple inspector. """
120120
self.assertEqual(self.subperiodsswaphelper.quote().value(),self.spread.value())
121121

122-
123-
class OIBSHelperTest(unittest.TestCase):
124-
def setUp(self):
125-
""" Test consistency of OIBS Helper"""
126-
self.todays_date=Date(1,October,2018)
127-
Settings.instance().setEvaluationDate(self.todays_date)
128-
self.settlementDays=2
129-
self.tenor=Period(6,Months)
130-
self.oisSpread=QuoteHandle(SimpleQuote(0.02))
131-
self.overnightFloat=FedFunds()
132-
self.floatDayCount=Actual360()
133-
self.flat_forward=FlatForward(self.todays_date, 0.03, self.floatDayCount)
134-
self.discount=RelinkableYieldTermStructureHandle(self.flat_forward)
135-
self.iborFloat=Eonia(self.discount)
136-
self.oibsratehelper=OIBSHelper(self.settlementDays,self.tenor,self.oisSpread,self.overnightFloat,self.iborFloat,self.discount)
137-
138-
def testSimpleInspectors(self):
139-
""" Test OIBS Helper simple inspector. """
140-
self.assertEqual(self.oibsratehelper.quote().value(),self.oisSpread.value())
141-
142-
143122
class BasisTwoSwapHelperTest(unittest.TestCase):
144123
def setUp(self):
145124
""" Test consistency of basis to swap Helper"""
@@ -239,7 +218,6 @@ def testSimpleInspectors(self):
239218
suite.addTest(unittest.makeSuite(CrossCcyBasisSwapHelperTest,'test'))
240219
suite.addTest(unittest.makeSuite(TenorBasisSwapHelperTest,'test'))
241220
suite.addTest(unittest.makeSuite(SubPeriodsSwapHelperTest,'test'))
242-
suite.addTest(unittest.makeSuite(OIBSHelperTest,'test'))
243221
suite.addTest(unittest.makeSuite(BasisTwoSwapHelperTest,'test'))
244222
suite.addTest(unittest.makeSuite(OICCBSHelperTest,'test'))
245223
suite.addTest(unittest.makeSuite(ImmFraRateHelperTest,'test'))

OREData-SWIG/SWIG/ored_conventions.i

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,16 @@ class AverageOisConvention : public Convention {
285285
class TenorBasisSwapConvention : public Convention {
286286
public:
287287
TenorBasisSwapConvention();
288-
TenorBasisSwapConvention(const std::string& id,const std::string& longIndex,
289-
const std::string& shortIndex, const std::string& shortPayTenor = "",
290-
const std::string& spreadOnShort = "", const std::string& includeSpread = "",
291-
const std::string& subPeriodsCouponType = "");
292-
const ext::shared_ptr<IborIndex> longIndex() const;
293-
const ext::shared_ptr<IborIndex> shortIndex() const;
294-
const std::string& longIndexName() const;
295-
const std::string& shortIndexName() const;
296-
const Period& shortPayTenor() const;
297-
bool spreadOnShort() const;
288+
TenorBasisSwapConvention(const string& id, const string& payIndex, const string& receiveIndex,
289+
const string& receiveFrequency = "", const string& payFrequency = "",
290+
const string& spreadOnRec = "", const string& includeSpread = "",
291+
const string& subPeriodsCouponType = "");
292+
const ext::shared_ptr<IborIndex> payIndex() const;
293+
const ext::shared_ptr<IborIndex> receiveIndex() const;
294+
const std::string& payIndexName() const;
295+
const std::string& receiveFrequency() const;
296+
const Period& payFrequency() const;
297+
bool spreadOnRec() const;
298298
bool includeSpread() const;
299299
QuantExt::SubPeriodsCoupon1::Type subPeriodsCouponType() const;
300300
%extend {

QuantExt-SWIG/SWIG/qle_instruments.i

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ using QuantExt::FxForward;
3939
using QuantExt::DiscountingFxForwardEngine;
4040
using QuantExt::Payment;
4141
using QuantExt::PaymentDiscountingEngine;
42-
using QuantExt::OvernightIndexedBasisSwap;
4342
using QuantExt::Deposit;
4443
using QuantExt::DepositEngine;
4544
using QuantExt::DiscountingSwapEngineMultiCurve;
@@ -127,36 +126,6 @@ class DepositEngine : public PricingEngine {
127126
QuantLib::Date npvDate = QuantLib::Date());
128127
};
129128

130-
%shared_ptr(OvernightIndexedBasisSwap)
131-
class OvernightIndexedBasisSwap : public Swap {
132-
public:
133-
enum Type { Receiver = -1, Payer = 1 };
134-
OvernightIndexedBasisSwap(OvernightIndexedBasisSwap::Type type,
135-
QuantLib::Real nominal,
136-
const QuantLib::Schedule& oisSchedule,
137-
const ext::shared_ptr<OvernightIndex>& overnightIndex,
138-
const QuantLib::Schedule& iborSchedule,
139-
const ext::shared_ptr<IborIndex>& iborIndex,
140-
const bool spreadOnShort = true,
141-
QuantLib::Spread oisSpread = 0.0,
142-
QuantLib::Spread iborSpread = 0.0,
143-
const bool telescopicValueDates = false);
144-
QuantLib::Real nominal() const ;
145-
const QuantLib::Schedule& oisSchedule();
146-
const QuantLib::Schedule& iborSchedule();
147-
QuantLib::Spread oisSpread();
148-
QuantLib::Spread iborSpread();
149-
const QuantLib::Leg& iborLeg();
150-
const QuantLib::Leg& overnightLeg();
151-
QuantLib::Real iborLegBPS() const;
152-
QuantLib::Real iborLegNPV() const;
153-
QuantLib::Real fairIborSpread() const;
154-
QuantLib::Real overnightLegBPS() const;
155-
QuantLib::Real overnightLegNPV() const;
156-
QuantLib::Real fairOvernightSpread() const;
157-
};
158-
159-
160129
%shared_ptr(Payment)
161130
class Payment : public Instrument {
162131
public:

QuantExt-SWIG/SWIG/qle_ratehelpers.i

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ using QuantExt::TenorBasisSwapHelper;
3232
using QuantExt::SubPeriodsSwapHelper;
3333
using QuantExt::SubPeriodsCoupon1;
3434
using QuantExt::OICCBSHelper;
35-
using QuantExt::OIBSHelper;
3635
using QuantExt::BasisTwoSwapHelper;
3736
using QuantExt::ImmFraRateHelper;
3837
using QuantExt::CrossCcyFixFloatSwapHelper;
@@ -85,13 +84,15 @@ class TenorBasisSwapHelper : public RateHelper {
8584
public:
8685
TenorBasisSwapHelper(QuantLib::Handle<QuantLib::Quote> spread,
8786
const QuantLib::Period& swapTenor,
88-
const ext::shared_ptr<IborIndex> longIndex,
89-
const ext::shared_ptr<IborIndex> shortIndex,
90-
const QuantLib::Period& shortPayTenor = QuantLib::Period(),
87+
const ext::shared_ptr<IborIndex> payIndex,
88+
const ext::shared_ptr<IborIndex> receiveIndex,
9189
const QuantLib::Handle<QuantLib::YieldTermStructure>& discountingCurve
9290
= QuantLib::Handle<QuantLib::YieldTermStructure>(),
93-
bool spreadOnShort = true,
91+
bool spreadOnRec = true,
9492
bool includeSpread = false,
93+
const QuantLib::Period& payFrequency = QuantLib::Period(),
94+
const QuantLib::Period& recFrequency = QuantLib::Period(),
95+
const bool telescopicValueDates = false,
9596
QuantExt::SubPeriodsCoupon1::Type type = QuantExt::SubPeriodsCoupon1::Compounding);
9697
ext::shared_ptr<TenorBasisSwap> swap();
9798
};
@@ -114,19 +115,6 @@ class SubPeriodsSwapHelper : public RateHelper {
114115
ext::shared_ptr<SubPeriodsSwap> swap();
115116
};
116117

117-
%shared_ptr(OIBSHelper)
118-
class OIBSHelper : public RateHelper {
119-
public:
120-
OIBSHelper(QuantLib::Natural settlementDays,
121-
const QuantLib::Period& tenor,
122-
const QuantLib::Handle<QuantLib::Quote>& oisSpread,
123-
const ext::shared_ptr<OvernightIndex>& overnightIndex,
124-
const ext::shared_ptr<IborIndex>& iborIndex,
125-
const QuantLib::Handle<QuantLib::YieldTermStructure>& discount
126-
= QuantLib::Handle<QuantLib::YieldTermStructure>());
127-
ext::shared_ptr<OvernightIndexedBasisSwap> swap();
128-
};
129-
130118
%shared_ptr(BasisTwoSwapHelper)
131119
class BasisTwoSwapHelper : public RateHelper {
132120
public:

QuantExt-SWIG/SWIG/qle_tenorbasisswap.i

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -68,49 +68,47 @@ class SubPeriodsCoupon1 : public FloatingRateCoupon {
6868
%shared_ptr(TenorBasisSwap)
6969
class TenorBasisSwap : public Swap {
7070
public:
71-
TenorBasisSwap(const QuantLib::Date& effectiveDate,
72-
QuantLib::Real nominal,
73-
const QuantLib::Period& swapTenor,
74-
bool payLongIndex,
75-
const ext::shared_ptr<IborIndex>& longIndex,
76-
QuantLib::Spread longSpread,
77-
const ext::shared_ptr<IborIndex>& shortIndex,
78-
QuantLib::Spread shortSpread,
79-
const QuantLib::Period& shortPayTenor,
80-
QuantLib::DateGeneration::Rule rule = QuantLib::DateGeneration::Backward,
81-
bool includeSpread = false,
82-
bool spreadOnShort = true,
83-
QuantExt::SubPeriodsCoupon1::Type type = QuantExt::SubPeriodsCoupon1::Compounding);
84-
TenorBasisSwap(QuantLib::Real nominal,
85-
bool payLongIndex,
86-
const QuantLib::Schedule& longSchedule,
87-
const ext::shared_ptr<IborIndex>& longIndex,
88-
QuantLib::Spread longSpread,
89-
const QuantLib::Schedule& shortSchedule,
90-
const ext::shared_ptr<IborIndex>& shortIndex,
91-
QuantLib::Spread shortSpread,
92-
bool includeSpread = false,
93-
bool spreadOnShort = true,
94-
QuantExt::SubPeriodsCoupon1::Type type = QuantExt::SubPeriodsCoupon1::Compounding);
95-
QuantLib::Real nominal() const;
96-
bool payLongIndex();
97-
const QuantLib::Schedule& longSchedule() const;
98-
const ext::shared_ptr<IborIndex> longIndex() const;
99-
QuantLib::Spread longSpread() const;
100-
const QuantLib::Leg& longLeg() const;
101-
const QuantLib::Schedule& shortSchedule() const;
102-
const ext::shared_ptr<IborIndex> shortIndex() const;
103-
QuantLib::Spread shortSpread() const;
104-
const QuantLib::Leg& shortLeg() const;
105-
QuantExt::SubPeriodsCoupon1::Type type() const;
106-
const QuantLib::Period& shortPayTenor() const;
107-
bool includeSpread() const;
108-
QuantLib::Real longLegBPS() const;
109-
QuantLib::Real longLegNPV() const;
110-
QuantLib::Rate fairLongLegSpread() const;
111-
QuantLib::Real shortLegBPS() const;
112-
QuantLib::Real shortLegNPV() const;
113-
QuantLib::Rate fairShortLegSpread() const;
71+
TenorBasisSwap(const Date& effectiveDate, QuantLib::Real nominal, const QuantLib::Period& swapTenor,
72+
const boost::shared_ptr<QuantLib::IborIndex>& payIndex, QuantLib::Spread paySpread,
73+
const QuantLib::Period& payFrequency, const boost::shared_ptr<QuantLib::IborIndex>& recIndex,
74+
QuantLib::Spread recSpread, const QuantLib::Period& recFrequency,
75+
QuantLib::DateGeneration::Rule rule = DateGeneration::Backward, bool includeSpread = false,
76+
bool spreadOnRec = true,
77+
QuantExt::SubPeriodsCoupon1::Type type = QuantExt::SubPeriodsCoupon1::Compounding,
78+
const bool telescopicValueDates = false);
79+
TenorBasisSwap(QuantLib::Real nominal, const QuantLib::Schedule& paySchedule,
80+
const boost::shared_ptr<QuantLib::IborIndex>& payIndex, QuantLib::Spread paySpread,
81+
const QuantLib::Schedule& recSchedule, const boost::shared_ptr<QuantLib::IborIndex>& recIndex,
82+
QuantLib::Spread recSpread, bool includeSpread = false, bool spreadOnRec = true,
83+
QuantExt::SubPeriodsCoupon1::Type type = QuantExt::SubPeriodsCoupon1::Compounding,
84+
const bool telescopicValueDates = false);
85+
TenorBasisSwap(std::vector<Real> nominals, const QuantLib::Schedule& paySchedule,
86+
const boost::shared_ptr<QuantLib::IborIndex>& payIndex, QuantLib::Spread paySpread,
87+
const QuantLib::Schedule& recSchedule, const boost::shared_ptr<QuantLib::IborIndex>& recIndex,
88+
QuantLib::Spread recSpread, bool includeSpread = false, bool spreadOnRec = true,
89+
QuantExt::SubPeriodsCoupon1::Type type = QuantExt::SubPeriodsCoupon1::Compounding,
90+
const bool telescopicValueDates = false);
91+
QuantLib::Real nominal() const;
92+
std::vector<QuantLib::Real> nominals() const;
93+
const QuantLib::Schedule& paySchedule() const;
94+
const ext::shared_ptr<IborIndex> payIndex() const;
95+
QuantLib::Spread paySpread() const;
96+
const QuantLib::Leg& payLeg() const;
97+
const QuantLib::Schedule& recSchedule() const;
98+
const ext::shared_ptr<IborIndex> recIndex() const;
99+
QuantLib::Spread recSpread() const;
100+
const QuantLib::Leg& recLeg() const;
101+
QuantExt::SubPeriodsCoupon1::Type type() const;
102+
const QuantLib::Period& recFrequency() const;
103+
const QuantLib::Period& payFrequency() const;
104+
bool includeSpread() const;
105+
bool spreadOnRec() const;
106+
QuantLib::Real payLegBPS() const;
107+
QuantLib::Real payLegNPV() const;
108+
QuantLib::Rate fairPayLegSpread() const;
109+
QuantLib::Real recLegBPS() const;
110+
QuantLib::Real recLegNPV() const;
111+
QuantLib::Rate fairRecLegSpread() const;
114112
};
115113

116114
%shared_ptr(SubPeriodsSwap)

0 commit comments

Comments
 (0)