在计算债券收益率时,我试图使用OpenGamma开发的Strata软件包复制使用excel的YIELD函数计算的结果。然而,比较使用excel和strata计算的数字,我注意到当债券的持续时间更长时,存在一个小的差异。
这是我在excel中计算的一个例子: Excel Calculation
计算结果为6.5%
当我在Strata中做同样的计算时:
DiscountingFixedCouponBondPaymentPeriodPricer paymentPeriodPricer = new DiscountingFixedCouponBondPaymentPeriodPricer();
DiscountingPaymentPricer discountingPaymentPricer = new DiscountingPaymentPricer();
DiscountingFixedCouponBondProductPricer pricer = new DiscountingFixedCouponBondProductPricer(paymentPeriodPricer,discountingPaymentPricer);
LocalDate settlementDate = LocalDate.of(2008, 2, 15);
LocalDate maturityDate = LocalDate.of(2016,11,15);
double couponRate = 0.0575;
double dirtyPrice=0.9504287;
com.opengamma.strata.basics.currency.Currency bondcurrency = com.opengamma.strata.basics.currency.Currency.of("USD");
BusinessDayAdjustment businessDayAdj =
BusinessDayAdjustment.of(BusinessDayConventions.FOLLOWING, HolidayCalendarIds.USNY );
PeriodicSchedule definition = PeriodicSchedule.builder()
.startDate(settlementDate)
.endDate(maturityDate)
.businessDayAdjustment(businessDayAdj)
.frequency(Frequency.P6M)
.stubConvention(StubConvention.SHORT_INITIAL)
.rollConvention(RollConventions.EOM)
.build();
FixedCouponBond bond = FixedCouponBond.builder()
.currency(bondcurrency)
.notional(1)
.fixedRate(couponRate)
.accrualSchedule(definition)
.securityId(SecurityId.of("WHATISTHIS","FOR"))
.dayCount(DayCounts.THIRTY_360_ISDA)
.yieldConvention(FixedCouponBondYieldConvention.JP_SIMPLE)
.legalEntityId(StandardId.of("WHATISTHIS","FOR"))
.settlementDateOffset(DaysAdjustment.ofBusinessDays(2,HolidayCalendarIds.SAT_SUN))
.build();
double yieldOfBond = pricer.yieldFromDirtyPrice(bond.resolve(ReferenceData.standard()),settlementDate,dirtyPrice);
System.out.println(String.valueOf(yieldOfBond*100));
印刷的收益率数据为6.645978959660144%。
我可能知道我是否可能错误地配置了任何参数,因为分层屈服函数会带来一些其他参数。
谢谢。
答案 0 :(得分:0)
看起来你可能会以干净的价格开始?试试这个:
DiscountingFixedCouponBondProductPricer pricer =
DiscountingFixedCouponBondProductPricer.DEFAULT;
LocalDate settlementDate = LocalDate.of(2008, 2, 15);
LocalDate startDate = LocalDate.of(2007, 11, 15);
LocalDate maturityDate = LocalDate.of(2016, 11, 15);
double couponRate = 0.0575;
double cleanPrice = 0.9504287;
Currency bondcurrency = Currency.USD;
BusinessDayAdjustment businessDayAdj = BusinessDayAdjustment.of(
BusinessDayConventions.FOLLOWING, HolidayCalendarIds.USNY);
PeriodicSchedule definition = PeriodicSchedule.builder()
.startDate(startDate)
.endDate(maturityDate)
.businessDayAdjustment(businessDayAdj)
.frequency(Frequency.P6M)
.stubConvention(StubConvention.SHORT_INITIAL)
.rollConvention(RollConventions.DAY_15)
.build();
FixedCouponBond bond = FixedCouponBond.builder()
.currency(bondcurrency)
.notional(1)
.fixedRate(couponRate)
.accrualSchedule(definition)
.securityId(SecurityId.of("WHATISTHIS", "FOR"))
.dayCount(DayCounts.THIRTY_360_ISDA)
.yieldConvention(FixedCouponBondYieldConvention.US_STREET)
.legalEntityId(StandardId.of("WHATISTHIS", "FOR"))
.settlementDateOffset(DaysAdjustment.ofBusinessDays(2, HolidayCalendarIds.USNY))
.build();
double dirtyPrice = pricer.dirtyPriceFromCleanPrice(bond.resolve(ReferenceData.standard()), settlementDate, cleanPrice);
double yield = pricer.yieldFromDirtyPrice(bond.resolve(ReferenceData.standard()), settlementDate, dirtyPrice);
System.out.println(String.valueOf(yield * 100d));
与商店或参考和市场数据互动时使用securityId
和legalEntityId
。