1
$\begingroup$

I'm trying to implement a simple calculation module to calculate fixed rate bond yield given the price (and then price based on yield to verify the calculation). I've looked at a number of examples (including Bonds example) but in some cases I'm seeing difference from the numbers future users currently retrieve from Bloomberg. Here's my code (BondData class defines bond attributes that I load from a .csv file). In most examples I'm matching yield numbers (in some cases I'm off by 1-2bps) but having hard time matching price. Also, yields don't match when redemption value is different from face value. Is there something obvious that I'm missing?

Thank you,

Jim

int fixingDays = 1;
Date todaysDate = calendar.advance(bond.SettlementDate, -fixingDays, TimeUnit.Days);
Settings.setEvaluationDate(todaysDate);

// Rate
Schedule fixedBondSchedule = new Schedule(
   bond.IssueDate,
   bond.Maturity,
   new Period(bond.Frequency),
   new UnitedStates(UnitedStates.Market.GovernmentBond),
   BusinessDayConvention.ModifiedFollowing,
   BusinessDayConvention.Unadjusted,
   DateGeneration.Rule.Backward,
   false);

FixedRateBond fixedRateBond = new FixedRateBond(
   1,
   bond.FaceAmount,
   fixedBondSchedule,
   new List<double>() { bond.CouponRate }, // { 1, couponRate }
   bond.DayCounter,
   BusinessDayConvention.ModifiedFollowing,
   bond.Redemption,
   bond.IssueDate);

bond.YieldCalc = fixedRateBond.yield(
   bond.Price,
   bond.DayCounter,
   Compounding.Compounded,
   bond.Frequency,
   bond.SettlementDate);

RelinkableHandle<FlatTermStructure> discountingTermStructure = new RelinkableHandle<FlatTermStructure>();
Handle<FlatTermStructure> flatTermStructure = new Handle<FlatTermStructure>(
      new FlatForward(
         bond.SettlementDate,
         bond.Yield,
         bond.DayCounter,
         Compounding.Compounded,
         bond.Frequency));

discountingTermStructure.linkTo(flatTermStructure);

// Pricing engine
IPricingEngine bondEngine = new DiscountingBondEngine(discountingTermStructure);
fixedRateBond.setPricingEngine(bondEngine);

bond.CleanPriceCalc = fixedRateBond.cleanPrice();
bond.DirtyPriceCalc = fixedRateBond.dirtyPrice();
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.