|
| 1 | +import unittest |
| 2 | + |
| 3 | +from quantlib.time.api import Date, Period, Annual, TARGET, Unadjusted, Schedule, DateGeneration, Actual365Fixed, Semiannual, ActualActual, Following |
| 4 | +from quantlib.instruments.api import FixedRateBond, AssetSwap |
| 5 | +from quantlib.pricingengines.api import DiscountingBondEngine, DiscountingSwapEngine |
| 6 | +from quantlib.termstructures.yields.api import HandleYieldTermStructure |
| 7 | +from quantlib.indexes.api import Euribor |
| 8 | +from .utilities import flat_rate |
| 9 | + |
| 10 | +class TestMarketASWSpread(unittest.TestCase): |
| 11 | + def setUp(self): |
| 12 | + self.term_structure = HandleYieldTermStructure() |
| 13 | + self.today = Date(24, 4, 2007) |
| 14 | + self.ibor_index = Euribor(Period(Semiannual), self.term_structure) |
| 15 | + self.term_structure.link_to(flat_rate(0.05, Actual365Fixed(), self.today)) |
| 16 | + self.spread = 0.0 |
| 17 | + self.face_amount = 100.0 |
| 18 | + self.settlement_days = 2 |
| 19 | + |
| 20 | + def test_market_vs_par_asset_swap(self): |
| 21 | + """Testing relationship between market asset swap and par asset swap...""" |
| 22 | + |
| 23 | + pay_fixed_rate = True |
| 24 | + par_asset_swap = True |
| 25 | + mkt_asset_swap = False |
| 26 | + fixed_bond_schedule1 = Schedule.from_rule(Date(4, 1, 2005), |
| 27 | + Date(4, 1, 2037), |
| 28 | + Period(Annual), |
| 29 | + TARGET(), |
| 30 | + Unadjusted, Unadjusted, |
| 31 | + DateGeneration.Backward, False) |
| 32 | + fixed_bond1 = FixedRateBond(self.settlement_days, self.face_amount, fixed_bond_schedule1, |
| 33 | + [0.04], ActualActual(ActualActual.ISDA), Following, |
| 34 | + 100.0, Date(4, 1, 2005)) |
| 35 | + bond_engine = DiscountingBondEngine(self.term_structure) |
| 36 | + swap_engine = DiscountingSwapEngine(self.term_structure) |
| 37 | + fixed_bond1.set_pricing_engine(bond_engine) |
| 38 | + fixed_bond_mkt_price1 = 89.22 # market price observed on June 7th 2007 |
| 39 | + fixed_bond_mkt_full_price1 = fixed_bond_mkt_price1 + fixed_bond1.accrued_amount() |
| 40 | + fixed_bond_par_asset_swap1 = AssetSwap(pay_fixed_rate, |
| 41 | + fixed_bond1, fixed_bond_mkt_price1, |
| 42 | + self.ibor_index, |
| 43 | + self.spread, |
| 44 | + floating_day_counter=self.ibor_index.day_counter, |
| 45 | + par_asset_swap=True) |
| 46 | + fixed_bond_par_asset_swap1.set_pricing_engine(swap_engine) |
| 47 | + fixed_bond_par_asset_swap_spread1 = fixed_bond_par_asset_swap1.fair_spread |
| 48 | + fixed_bond_mkt_asset_swap1 = AssetSwap(pay_fixed_rate, |
| 49 | + fixed_bond1, |
| 50 | + fixed_bond_mkt_price1, |
| 51 | + self.ibor_index, |
| 52 | + self.spread, |
| 53 | + floating_day_counter=self.ibor_index.day_counter, |
| 54 | + par_asset_swap=False) |
| 55 | + fixed_bond_mkt_asset_swap1.set_pricing_engine(swap_engine) |
| 56 | + fixed_bond_mkt_asset_swap_spread1 = fixed_bond_mkt_asset_swap1.fair_spread |
| 57 | + |
| 58 | + self.assertAlmostEqual(fixed_bond_mkt_asset_swap_spread1, |
| 59 | + 100 * fixed_bond_par_asset_swap_spread1 / fixed_bond_mkt_full_price1) |
0 commit comments