I modified my code for the DayCountConvention and rollConvention boolean value as follows:
import java.time.LocalDate;
import com.opengamma.strata.basics.ReferenceData;
import com.opengamma.strata.basics.StandardId;
import com.opengamma.strata.basics.currency.Currency;
import com.opengamma.strata.basics.date.BusinessDayAdjustment;
import com.opengamma.strata.basics.date.BusinessDayConventions;
import com.opengamma.strata.basics.date.DayCount;
import com.opengamma.strata.basics.date.DayCounts;
import com.opengamma.strata.basics.date.DaysAdjustment;
import com.opengamma.strata.basics.date.HolidayCalendarId;
import com.opengamma.strata.basics.date.HolidayCalendarIds;
import com.opengamma.strata.basics.schedule.Frequency;
import com.opengamma.strata.basics.schedule.PeriodicSchedule;
import com.opengamma.strata.basics.schedule.StubConvention;
import com.opengamma.strata.pricer.bond.DiscountingFixedCouponBondProductPricer;
import com.opengamma.strata.product.SecurityId;
import com.opengamma.strata.product.bond.FixedCouponBond;
import com.opengamma.strata.product.bond.FixedCouponBondYieldConvention;
import com.opengamma.strata.product.bond.ResolvedFixedCouponBond;
public class Pricer {
private static final ReferenceData REF_DATA = ReferenceData.standard();
private static final StandardId ISSUER_ID = StandardId.of("OG-Ticker", "GOVT1");
private static final FixedCouponBondYieldConvention YIELD_CONVENTION = FixedCouponBondYieldConvention.US_STREET;
private static final double NOTIONAL = 1000;
private static final HolidayCalendarId USNY_CALENDAR = HolidayCalendarIds.USNY;
private static final DaysAdjustment DATE_OFFSET = DaysAdjustment.ofBusinessDays(1, USNY_CALENDAR);
private static final DayCount DAY_COUNT = DayCounts.ACT_ACT_ICMA;
private static final LocalDate START_DATE = LocalDate.of(2016, 06, 30);
private static final BusinessDayAdjustment BUSINESS_ADJUST = BusinessDayAdjustment.of(BusinessDayConventions.NO_ADJUST, USNY_CALENDAR);
private static final DiscountingFixedCouponBondProductPricer PRICER = DiscountingFixedCouponBondProductPricer.DEFAULT;
private static final ResolvedFixedCouponBond _912828S27 = FixedCouponBond.builder()
.securityId(SecurityId.of(StandardId.of("OG-Ticker", "912828S27")))
.dayCount(DAY_COUNT)
.fixedRate(1.125)
.legalEntityId(ISSUER_ID)
.currency(Currency.USD)
.notional(NOTIONAL)
.accrualSchedule(PeriodicSchedule.of(START_DATE, LocalDate.of(2021, 6, 30), Frequency.P6M, BUSINESS_ADJUST, StubConvention.NONE, true))
.settlementDateOffset(DATE_OFFSET)
.yieldConvention(YIELD_CONVENTION)
.build()
.resolve(REF_DATA);
private static final ResolvedFixedCouponBond _912828S35 = FixedCouponBond.builder()
.securityId(SecurityId.of(StandardId.of("OG-Ticker", "912828S35")))
.dayCount(DAY_COUNT)
.fixedRate(1.375)
.legalEntityId(ISSUER_ID)
.currency(Currency.USD)
.notional(NOTIONAL)
.accrualSchedule(PeriodicSchedule.of(START_DATE, LocalDate.of(2023, 6, 30), Frequency.P6M, BUSINESS_ADJUST, StubConvention.NONE, true))
.settlementDateOffset(DATE_OFFSET)
.yieldConvention(YIELD_CONVENTION)
.build()
.resolve(REF_DATA);
private static final ResolvedFixedCouponBond _912828R36 = FixedCouponBond.builder()
.securityId(SecurityId.of(StandardId.of("OG-Ticker", "912828R36")))
.dayCount(DAY_COUNT)
.fixedRate(1.625)
.legalEntityId(ISSUER_ID)
.currency(Currency.USD)
.notional(NOTIONAL)
.accrualSchedule(PeriodicSchedule.of(START_DATE, LocalDate.of(2026, 5, 15), Frequency.P6M, BUSINESS_ADJUST, StubConvention.SHORT_INITIAL, true))
.settlementDateOffset(DATE_OFFSET)
.yieldConvention(YIELD_CONVENTION)
.build()
.resolve(REF_DATA);
public static void main(String[] args) {
openGammaCalc(_912828S27, 99.921875);
openGammaCalc(_912828S35, 100.109);
openGammaCalc(_912828R36, 100.8125);
}
public static void openGammaCalc(ResolvedFixedCouponBond bond, double cleanPrice){
LocalDate settlementDate = LocalDate.of(2016, 7, 18);
double accruedInterest = PRICER.accruedInterest(bond, settlementDate);
double dirtyPrice = PRICER.dirtyPriceFromCleanPrice(bond, settlementDate, cleanPrice);
double yield = PRICER.yieldFromDirtyPrice(bond, settlementDate, dirtyPrice);
double modifiedDuration = PRICER.modifiedDurationFromYield(bond, settlementDate, yield);
double macaulayDuration = PRICER.macaulayDurationFromYield(bond, settlementDate, yield);
System.out.println(bond.toString());
System.out.println("accruedInterest = "+accruedInterest);
System.out.println("dirtyPrice = "+dirtyPrice);
System.out.println("yield = "+yield);
System.out.println("modifiedDuration = "+modifiedDuration);
System.out.println("macaulayDuration = "+macaulayDuration);
}
}
Both yield and duration (modified & Macaulay) seem to be different from BBG terminal. Am I building the fixed coupon bond correctly ?