Attribute Function
Inputs:
- Fixed Income Contract
- an object that contains the details of the contract that is being attributed
- curves
a list of items, each with a name and curve, that represents the changes in the curve
for each factor.
def attribute(bond,items):
results = {}
current = None
for name,curve in items:
term_structure_handle = ql.YieldTermStructureHandle(curve)
bond_engine = ql.DiscountingBondEngine(term_structure_handle)
bond.setPricingEngine(bond_engine)
dirty_price = bond.NPV()
accrued_amount = bond.accruedAmount()
clean_price = dirty_price - accrued_amount
if current != None:
results[name] = dirty_price - current
pass
current = dirty_price
pass
return results
Simplified Curves Input Example
bond = ct.fixed_rate_bond(settlement_days=2, face_amount=100, coupons=0.05,day_count= ct.DayCounts.Actual360,schedule=ct.schedule_obj(
start_date='2026-03-10',
end_date='2027-03-10',
frequency=ct.Frequency.Semiannual,
calendar=ct.Calendar.USNyse,
convention=ct.Convention.Following,
dateroll=ct.DateRoll.Backward
))
data1 = ty.data(date='2026-03-03')
data2 = ty.data('2026-03-04')
curve1 = cv.curve(data1,spread=0.01)
curve2 = cv.curve(data2, spread=0.01)
curve3 = cv.curve(data2, spread=0.012)
attribution = attribute(bond, [
('today', curve1),('time', curve2),('spread', curve3)
])
The result of calling the attribute method will be two numbers, the first labeled "time" which represents the effect of
the underlying curve changing, and the second labeled "spread" which represents the effect of changing the spread from
the first day to the second.
(Note, the name associated with the first curve is not used, but should be included)