Skip to content

Commit 3adfc21

Browse files
committed
QPR-12302 update python test
1 parent 4987f4b commit 3adfc21

2 files changed

Lines changed: 66 additions & 52 deletions

File tree

OREAnalytics-SWIG/Python/test/test_instruments.py

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -580,73 +580,71 @@ def setUp(self):
580580
self.day_counter = Actual365Fixed()
581581
self.nominal = 1000000.0
582582
self.maturity_date = self.calendar.advance(self.settlement_date, 5, Years)
583-
self.pay_long_index = False
584-
self.short_index_pay_tenor = Period(6, Months)
585-
self.long_index_pay_tenor = Period(6, Months)
586-
self.short_index_leg_spread = 0.0
587-
self.long_index_leg_spread = 0.01
583+
self.receiveFrequency = Period(6, Months)
584+
self.payFrequency = Period(6, Months)
585+
self.receive_index_leg_spread = 0.00
586+
self.pay_index_leg_spread = 0.00
588587
self.bdc = ModifiedFollowing
589588
self.date_generation = DateGeneration.Forward
590589
self.end_of_month = False
591590
self.include_spread = False
592-
self.spreadOnShort = True
591+
self.spreadOnRec = True
593592
self.sub_periods_type = SubPeriodsCoupon1.Compounding
594593
self.ois_term_structure = RelinkableYieldTermStructureHandle()
595-
self.short_index_term_structure = RelinkableYieldTermStructureHandle()
596-
self.long_index_term_structure = RelinkableYieldTermStructureHandle()
597-
self.short_index = Euribor3M(self.short_index_term_structure)
598-
self.long_index = Euribor6M(self.long_index_term_structure)
599-
self.short_index_schedule = Schedule(self.settlement_date, self.maturity_date,
600-
self.short_index_pay_tenor, self.calendar,
594+
self.rec_index_term_structure = RelinkableYieldTermStructureHandle()
595+
self.pay_index_term_structure = RelinkableYieldTermStructureHandle()
596+
self.rec_index = Euribor3M(self.rec_index_term_structure)
597+
self.pay_index = Euribor6M(self.pay_index_term_structure)
598+
self.telescopicValueDates = False
599+
self.rec_index_schedule = Schedule(self.settlement_date, self.maturity_date,
600+
self.receiveFrequency, self.calendar,
601601
self.bdc, self.bdc, self.date_generation,
602602
self.end_of_month)
603-
self.long_index_schedule = Schedule(self.settlement_date, self.maturity_date,
604-
self.long_index_pay_tenor, self.calendar,
603+
self.pay_index_schedule = Schedule(self.settlement_date, self.maturity_date,
604+
self.payFrequency, self.calendar,
605605
self.bdc, self.bdc, self.date_generation,
606606
self.end_of_month)
607-
self.tenor_basis_swap = TenorBasisSwap(self.nominal, self.pay_long_index, self.long_index_schedule,
608-
self.long_index, self.long_index_leg_spread,
609-
self.short_index_schedule, self.short_index,
610-
self.short_index_leg_spread, self.include_spread,
611-
self.spreadOnShort, self.sub_periods_type)
612-
self.short_index_flat_forward = FlatForward(self.todays_date, 0.02, self.short_index.dayCounter())
613-
self.long_index_flat_forward = FlatForward(self.todays_date, 0.03, self.long_index.dayCounter())
607+
self.tenor_basis_swap = TenorBasisSwap(self.nominal, self.pay_index_schedule,
608+
self.pay_index, self.pay_index_leg_spread,
609+
self.rec_index_schedule, self.rec_index,
610+
self.receive_index_leg_spread, self.include_spread,
611+
self.spreadOnRec, self.sub_periods_type, self.telescopicValueDates)
612+
self.rec_index_flat_forward = FlatForward(self.todays_date, 0.02, self.rec_index.dayCounter())
613+
self.pay_index_flat_forward = FlatForward(self.todays_date, 0.03, self.pay_index.dayCounter())
614614
self.ois_flat_forward = FlatForward(self.todays_date, 0.01, self.day_counter)
615-
self.short_index_term_structure.linkTo(self.short_index_flat_forward)
616-
self.long_index_term_structure.linkTo(self.long_index_flat_forward)
615+
self.rec_index_term_structure.linkTo(self.rec_index_flat_forward)
616+
self.pay_index_term_structure.linkTo(self.pay_index_flat_forward)
617617
self.ois_term_structure.linkTo(self.ois_flat_forward)
618618
self.engine = DiscountingSwapEngine(self.ois_term_structure)
619619
self.tenor_basis_swap.setPricingEngine(self.engine)
620620

621621
def testSimpleInspectors(self):
622622
""" Test TenorBasisSwap simple inspectors. """
623623
self.assertEqual(self.tenor_basis_swap.nominal(), self.nominal)
624-
self.assertEqual(self.tenor_basis_swap.payLongIndex(), self.pay_long_index)
625-
self.assertEqual(self.tenor_basis_swap.longSpread(), self.long_index_leg_spread)
626-
self.assertEqual(self.tenor_basis_swap.shortSpread(), self.short_index_leg_spread)
624+
self.assertEqual(self.tenor_basis_swap.paySpread(), self.pay_index_leg_spread)
625+
self.assertEqual(self.tenor_basis_swap.recSpread(), self.receive_index_leg_spread)
627626
self.assertEqual(self.tenor_basis_swap.type(), self.sub_periods_type)
628-
self.assertEqual(self.tenor_basis_swap.shortPayTenor(), self.short_index_pay_tenor)
629627
self.assertEqual(self.tenor_basis_swap.includeSpread(), self.include_spread)
630628

631629
def testSchedules(self):
632630
""" Test TenorBasisSwap schedules. """
633-
for i, d in enumerate(self.long_index_schedule):
634-
self.assertEqual(self.tenor_basis_swap.longSchedule()[i], d)
635-
for i, d in enumerate(self.short_index_schedule):
636-
self.assertEqual(self.tenor_basis_swap.shortSchedule()[i], d)
631+
for i, d in enumerate(self.pay_index_schedule):
632+
self.assertEqual(self.tenor_basis_swap.paySchedule()[i], d)
633+
for i, d in enumerate(self.rec_index_schedule):
634+
self.assertEqual(self.tenor_basis_swap.recSchedule()[i], d)
637635

638636
def testConsistency(self):
639637
""" Test consistency of fair price and NPV() """
640638
tolerance = 1.0e-10
641-
fair_short_leg_spread = self.tenor_basis_swap.fairShortLegSpread()
642-
tenor_basis_swap = TenorBasisSwap(self.nominal, self.pay_long_index, self.long_index_schedule,
643-
self.long_index, self.long_index_leg_spread,
644-
self.short_index_schedule, self.short_index,
645-
fair_short_leg_spread, self.include_spread,
646-
self.spreadOnShort, self.sub_periods_type)
639+
fair_rec_leg_spread = self.tenor_basis_swap.fairRecLegSpread()
640+
tenor_basis_swap = TenorBasisSwap(self.nominal, self.pay_index_schedule,
641+
self.pay_index, self.pay_index_leg_spread,
642+
self.rec_index_schedule, self.rec_index,
643+
fair_rec_leg_spread, self.include_spread,
644+
self.spreadOnRec, self.sub_periods_type,
645+
self.telescopicValueDates)
647646
tenor_basis_swap.setPricingEngine(self.engine)
648647
self.assertFalse(abs(tenor_basis_swap.NPV()) > tolerance)
649-
650648

651649
class FxForwardTest(unittest.TestCase):
652650
def setUp(self):

QuantExt-SWIG/SWIG/qle_tenorbasisswap.i

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,44 @@ class SubPeriodsCoupon1 : public FloatingRateCoupon {
6868
%shared_ptr(TenorBasisSwap)
6969
class TenorBasisSwap : public Swap {
7070
public:
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,
71+
TenorBasisSwap(const QuantLib::Date & effectiveDate,
72+
QuantLib::Real nominal,
73+
const QuantLib::Period& swapTenor,
74+
const ext::shared_ptr<QuantLib::IborIndex>& payIndex,
75+
QuantLib::Spread paySpread,
76+
const QuantLib::Period& payFrequency,
77+
const ext::shared_ptr<QuantLib::IborIndex>& recIndex,
78+
QuantLib::Spread recSpread,
79+
const QuantLib::Period& recFrequency,
80+
QuantLib::DateGeneration::Rule rule = DateGeneration::Backward,
81+
bool includeSpread = false,
7682
bool spreadOnRec = true,
7783
QuantExt::SubPeriodsCoupon1::Type type = QuantExt::SubPeriodsCoupon1::Compounding,
7884
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,
85+
TenorBasisSwap(QuantLib::Real nominal,
86+
const QuantLib::Schedule& paySchedule,
87+
const ext::shared_ptr<QuantLib::IborIndex>& payIndex,
88+
QuantLib::Spread paySpread,
89+
const QuantLib::Schedule& recSchedule,
90+
const ext::shared_ptr<QuantLib::IborIndex>& recIndex,
91+
QuantLib::Spread recSpread,
92+
bool includeSpread = false,
93+
bool spreadOnRec = true,
8394
QuantExt::SubPeriodsCoupon1::Type type = QuantExt::SubPeriodsCoupon1::Compounding,
8495
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,
96+
TenorBasisSwap(const std::vector<QuantLib::Real>& nominals,
97+
const QuantLib::Schedule& paySchedule,
98+
const ext::shared_ptr<QuantLib::IborIndex>& payIndex,
99+
QuantLib::Spread paySpread,
100+
const QuantLib::Schedule& recSchedule,
101+
const ext::shared_ptr<QuantLib::IborIndex>& recIndex,
102+
QuantLib::Spread recSpread,
103+
bool includeSpread = false,
104+
bool spreadOnRec = true,
89105
QuantExt::SubPeriodsCoupon1::Type type = QuantExt::SubPeriodsCoupon1::Compounding,
90106
const bool telescopicValueDates = false);
91107
QuantLib::Real nominal() const;
92-
std::vector<QuantLib::Real> nominals() const;
108+
const std::vector<QuantLib::Real> nominals() const;
93109
const QuantLib::Schedule& paySchedule() const;
94110
const ext::shared_ptr<IborIndex> payIndex() const;
95111
QuantLib::Spread paySpread() const;

0 commit comments

Comments
 (0)