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);