Bonds - Calculate yield from price contributions or prices from yields

Having ask/bid price contribution for bonds but no yields or vice-versa (ask/bid yields) - how would I calculate the missing values having

  • Price (or Yield)
  • par value,
  • coupon rate
  • number of coupons / Year
  • maturity date and
  • issue date

New to Strata (first post) and willing to learn :slight_smile:

Thanks!

Refer to the bond pricer API to learn about the different things you can do.
Here is an example to calculate the accruedInterest function. Similar you can call other functions. Hope it helps.

TkNeo’s response is a great place to start. Feel free to ask if you can’t find something. (I’d recommend starting by setting up a FixedCouponBond object to see what data it needs, and then examining the DiscountingFixedCouponBondProductPricer API to see what methods can be invoked.

Thanks for the feedback
I looked at the links you sent and after writing a small testbed I found a post similar to mine here

However I cannot match the yield… For the value of yieldFromDirtyPrice I would have expected 1.981424 but I get -0.34982041294362526 instead

Why is the result so OFF the real value? I must be doing something wrong in the code (see below)

CleanPrice=141.505,
coupon=0.0575,
issueDate=1998-02-02,
maturityDate=2029-06-01,
settlementDate=2016-12-06,

dirtyPriceFromCleanPrice: 141.50578767123287
yieldFromDirtyPrice: -0.34982041294362526

	PeriodicSchedule accrualSchedule = PeriodicSchedule
	.builder()
		.startDate(issueDate)
		.endDate(maturityDate)
		.lastRegularEndDate(maturityDate)
		.businessDayAdjustment(businessDayAdj)
		.frequency(Frequency.P6M)
		.stubConvention(StubConvention.SHORT_INITIAL)
		.rollConvention(RollConventions.EOM)
			.build();

	FixedCouponBond fcb = FixedCouponBond
	.builder()
		.accrualSchedule(accrualSchedule)
		.currency(Currency.CAD)
		.securityId(SecurityId.of("CUSIP", "135087WL4"))
		.notional(1000)
		.fixedRate(coupon)
		.dayCount(DayCounts.ACT_365_ACTUAL)
		.yieldConvention(FixedCouponBondYieldConvention.US_STREET)
		.legalEntityId(StandardId.of("LegalEntity", "DUMMY"))
		.settlementDateOffset(DaysAdjustment.ofBusinessDays(3, HolidayCalendarIds.CATO))
			.build();

	ResolvedFixedCouponBond resolvedBond = fcb.resolve(ReferenceData.standard());

		dirty = DiscountingFixedCouponBondProductPricer.DEFAULT.dirtyPriceFromCleanPrice(resolvedBond, settlementDate, initialPrice);
		yield = DiscountingFixedCouponBondProductPricer.DEFAULT.yieldFromDirtyPrice(resolvedBond, settlementDate, dirty);

Note that Strata uses decimal prices for bonds in the trade model, pricers and market data, thus a price of 99.32% is represented in Strata by 0.9932. Perhaps if you divide the clean price by 100 you will get closer?

Thanks Stephen!

I managed to make it work a couple of days ago but I was ‘in the zone’ and wanted to finish what I started that’s why my post only comes today…

Strata calculates the price/yield of a single bond!

I was expecting it to do it for the whole lot (par 100) (coupon above was already divided by par)

In order to get the right yield all I had to do was to divide the clean price by the par value (initialPrice in my code), then multiply the resulting yield with the par (duh)

yield: 1.9824303513080652
and back to clean 141.50500000000002

Thanks for all your help!

to clarify:

	dirty = DiscountingFixedCouponBondProductPricer.DEFAULT.dirtyPriceFromCleanPrice(resolvedBond, settlementDate, initialPrice/par);
	yield = DiscountingFixedCouponBondProductPricer.DEFAULT.yieldFromDirtyPrice(resolvedBond, settlementDate, dirty)*par;

Great that you succeeded. And yes, DiscountingFixedCouponBondProductPricer is pricing one bond, while DiscountingFixedCouponBondTradePricer prices the whole trade (but exposes less methods).

Good day, is the computation of the price based on Yield to Maturity?

Thanks?

Several pricing methods are involved in DiscountingFixedCouponBondProductPricer and DiscountingFixedCouponBondTradePricer. For example, dirtyPriceFromCurves in DiscountingFixedCouponBondProductPricer computes the bond price using a calibrated discounting curve, whereas the price is computed from yield to maturity by dirtyPriceFromYield in DiscountingFixedCouponBondProductPricer.