public ResolvedCapitalIndexedBondTrade resolve(ReferenceData refData) { ResolvedCapitalIndexedBond resolvedProduct = product.resolve(refData); LocalDate settlementDate = calculateSettlementDate(refData); double accruedInterest = resolvedProduct.accruedInterest(settlementDate) / product.Notional; if (settlementDate.isBefore(resolvedProduct.StartDate)) { throw new System.ArgumentException("Settlement date must not be before bond starts"); } BondPaymentPeriod settlePeriod; if (product.YieldConvention.Equals(CapitalIndexedBondYieldConvention.GB_IL_FLOAT)) { settlePeriod = KnownAmountBondPaymentPeriod.of(Payment.of(product.Currency, -product.Notional * quantity * (price + accruedInterest), settlementDate), SchedulePeriod.of(resolvedProduct.StartDate, settlementDate, product.AccrualSchedule.StartDate, settlementDate)); } else { RateComputation rateComputation = product.RateCalculation.createRateComputation(settlementDate); settlePeriod = CapitalIndexedBondPaymentPeriod.builder().startDate(resolvedProduct.StartDate).unadjustedStartDate(product.AccrualSchedule.StartDate).endDate(settlementDate).rateComputation(rateComputation).currency(product.Currency).notional(-product.Notional * quantity * (price + accruedInterest)).realCoupon(1d).build(); } return(ResolvedCapitalIndexedBondTrade.builder().info(info).product(resolvedProduct).quantity(quantity).settlement(ResolvedCapitalIndexedBondSettlement.of(settlementDate, price, settlePeriod)).build()); }
// collect the set of indices, validating they are IborIndex private static ImmutableSet <IborIndex> buildIndices(RateComputation floatingRate) { ImmutableSet.Builder <Index> builder = ImmutableSet.builder(); floatingRate.collectIndices(builder); //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: return(builder.build().Select(index => typeof(IborIndex).cast(index)).collect(toImmutableSet())); }
public virtual void test_rate_unknownType() { RateComputation mockComputation = mock(typeof(RateComputation)); DispatchingRateComputationFn test = DispatchingRateComputationFn.DEFAULT; assertThrowsIllegalArg(() => test.rate(mockComputation, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)); }
/// <summary> /// Calculates the strike. /// </summary> /// <param name="fixedLeg"> the fixed leg </param> /// <returns> the strike </returns> protected internal virtual double calculateStrike(ResolvedSwapLeg fixedLeg) { SwapPaymentPeriod paymentPeriod = fixedLeg.PaymentPeriods.get(0); ArgChecker.isTrue(paymentPeriod is RatePaymentPeriod, "Payment period must be RatePaymentPeriod"); RatePaymentPeriod ratePaymentPeriod = (RatePaymentPeriod)paymentPeriod; // compounding is caught when par rate is computed RateComputation rateComputation = ratePaymentPeriod.AccrualPeriods.get(0).RateComputation; ArgChecker.isTrue(rateComputation is FixedRateComputation, "Swap leg must be fixed leg"); return(((FixedRateComputation)rateComputation).Rate); }
// trusted constructor internal RateAccrualPeriod(SchedulePeriod period, double yearFraction, RateComputation rateComputation, double gearing, double spread, NegativeRateMethod negativeRateMethod) { this.startDate = period.StartDate; this.endDate = period.EndDate; this.unadjustedStartDate = period.UnadjustedStartDate; this.unadjustedEndDate = period.UnadjustedEndDate; this.yearFraction = yearFraction; this.rateComputation = rateComputation; this.gearing = gearing; this.spread = spread; this.negativeRateMethod = negativeRateMethod; }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(RateAccrualPeriod beanToCopy) { this.startDate_Renamed = beanToCopy.StartDate; this.endDate_Renamed = beanToCopy.EndDate; this.unadjustedStartDate_Renamed = beanToCopy.UnadjustedStartDate; this.unadjustedEndDate_Renamed = beanToCopy.UnadjustedEndDate; this.yearFraction_Renamed = beanToCopy.YearFraction; this.rateComputation_Renamed = beanToCopy.RateComputation; this.gearing_Renamed = beanToCopy.Gearing; this.spread_Renamed = beanToCopy.Spread; this.negativeRateMethod_Renamed = beanToCopy.NegativeRateMethod; }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(ResolvedFra beanToCopy) { this.currency_Renamed = beanToCopy.Currency; this.notional_Renamed = beanToCopy.Notional; this.paymentDate_Renamed = beanToCopy.PaymentDate; this.startDate_Renamed = beanToCopy.StartDate; this.endDate_Renamed = beanToCopy.EndDate; this.yearFraction_Renamed = beanToCopy.YearFraction; this.fixedRate_Renamed = beanToCopy.FixedRate; this.floatingRate_Renamed = beanToCopy.FloatingRate; this.discounting_Renamed = beanToCopy.Discounting; }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(CapitalIndexedBondPaymentPeriod beanToCopy) { this.currency_Renamed = beanToCopy.Currency; this.notional_Renamed = beanToCopy.Notional; this.realCoupon_Renamed = beanToCopy.RealCoupon; this.startDate_Renamed = beanToCopy.StartDate; this.endDate_Renamed = beanToCopy.EndDate; this.unadjustedStartDate_Renamed = beanToCopy.UnadjustedStartDate; this.unadjustedEndDate_Renamed = beanToCopy.UnadjustedEndDate; this.detachmentDate_Renamed = beanToCopy.DetachmentDate; this.rateComputation_Renamed = beanToCopy.RateComputation; }
private readonly ImmutableSet <IborIndex> indices; // not a property, derived and cached from input data //------------------------------------------------------------------------- //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableConstructor private ResolvedFra(com.opengamma.strata.basics.currency.Currency currency, double notional, java.time.LocalDate paymentDate, java.time.LocalDate startDate, java.time.LocalDate endDate, double yearFraction, double fixedRate, com.opengamma.strata.product.rate.RateComputation floatingRate, FraDiscountingMethod discounting) private ResolvedFra(Currency currency, double notional, LocalDate paymentDate, LocalDate startDate, LocalDate endDate, double yearFraction, double fixedRate, RateComputation floatingRate, FraDiscountingMethod discounting) { this.currency = ArgChecker.notNull(currency, "currency"); this.notional = notional; this.paymentDate = ArgChecker.notNull(paymentDate, "paymentDate"); ArgChecker.inOrderNotEqual(startDate, endDate, "startDate", "endDate"); this.startDate = startDate; this.endDate = endDate; this.yearFraction = ArgChecker.notNegative(yearFraction, "yearFraction"); this.fixedRate = fixedRate; this.floatingRate = ArgChecker.notNull(floatingRate, "floatingRate"); this.discounting = ArgChecker.notNull(discounting, "discounting"); this.indices = buildIndices(floatingRate); }
// could use @ImmutablePreBuild and @ImmutableValidate but faster inline //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableConstructor private RateAccrualPeriod(java.time.LocalDate startDate, java.time.LocalDate endDate, java.time.LocalDate unadjustedStartDate, java.time.LocalDate unadjustedEndDate, double yearFraction, com.opengamma.strata.product.rate.RateComputation rateComputation, double gearing, double spread, NegativeRateMethod negativeRateMethod) private RateAccrualPeriod(LocalDate startDate, LocalDate endDate, LocalDate unadjustedStartDate, LocalDate unadjustedEndDate, double yearFraction, RateComputation rateComputation, double gearing, double spread, NegativeRateMethod negativeRateMethod) { this.startDate = ArgChecker.notNull(startDate, "startDate"); this.endDate = ArgChecker.notNull(endDate, "endDate"); this.unadjustedStartDate = firstNonNull(unadjustedStartDate, startDate); this.unadjustedEndDate = firstNonNull(unadjustedEndDate, endDate); this.yearFraction = ArgChecker.notNegative(yearFraction, "yearFraction"); this.rateComputation = ArgChecker.notNull(rateComputation, "rateComputation"); this.gearing = gearing; this.spread = spread; this.negativeRateMethod = ArgChecker.notNull(negativeRateMethod, "negativeRateMethod"); // check for unadjusted must be after firstNonNull ArgChecker.inOrderNotEqual(startDate, endDate, "startDate", "endDate"); ArgChecker.inOrderNotEqual(this.unadjustedStartDate, this.unadjustedEndDate, "unadjustedStartDate", "unadjustedEndDate"); }
//------------------------------------------------------------------------- //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableConstructor private CapitalIndexedBondPaymentPeriod(com.opengamma.strata.basics.currency.Currency currency, double notional, double realCoupon, java.time.LocalDate startDate, java.time.LocalDate endDate, java.time.LocalDate unadjustedStartDate, java.time.LocalDate unadjustedEndDate, java.time.LocalDate detachmentDate, com.opengamma.strata.product.rate.RateComputation rateComputation) private CapitalIndexedBondPaymentPeriod(Currency currency, double notional, double realCoupon, LocalDate startDate, LocalDate endDate, LocalDate unadjustedStartDate, LocalDate unadjustedEndDate, LocalDate detachmentDate, RateComputation rateComputation) { this.currency = ArgChecker.notNull(currency, "currency"); this.notional = ArgChecker.notZero(notional, 0d, "notional"); this.realCoupon = ArgChecker.notNegative(realCoupon, "realCoupon"); this.startDate = ArgChecker.notNull(startDate, "startDate"); this.endDate = ArgChecker.notNull(endDate, "endDate"); this.unadjustedStartDate = firstNonNull(unadjustedStartDate, startDate); this.unadjustedEndDate = firstNonNull(unadjustedEndDate, endDate); this.detachmentDate = firstNonNull(detachmentDate, endDate); this.rateComputation = ArgChecker.notNull(rateComputation, "rateComputation"); ArgChecker.inOrderNotEqual(startDate, endDate, "startDate", "endDate"); ArgChecker.inOrderNotEqual(this.unadjustedStartDate, this.unadjustedEndDate, "unadjustedStartDate", "unadjustedEndDate"); ArgChecker.inOrderOrEqual(this.detachmentDate, this.endDate, "detachmentDate", "endDate"); ArgChecker.isTrue(rateComputation is InflationEndInterpolatedRateComputation || rateComputation is InflationEndMonthRateComputation, "rateComputation must be inflation rate observation"); }
public ImmutableList <RateAccrualPeriod> createAccrualPeriods(Schedule accrualSchedule, Schedule paymentSchedule, ReferenceData refData) { // resolve data by schedule DoubleArray resolvedGearings = firstNonNull(gearing, ALWAYS_1).resolveValues(accrualSchedule); DoubleArray resolvedSpreads = firstNonNull(spread, ALWAYS_0).resolveValues(accrualSchedule); // build accrual periods ImmutableList.Builder <RateAccrualPeriod> accrualPeriods = ImmutableList.builder(); for (int i = 0; i < accrualSchedule.size(); i++) { SchedulePeriod period = accrualSchedule.getPeriod(i); double yearFraction = period.yearFraction(dayCount, accrualSchedule); RateComputation rateComputation = createRateComputation(period, paymentSchedule, refData); accrualPeriods.add(new RateAccrualPeriod(period, yearFraction, rateComputation, resolvedGearings.get(i), resolvedSpreads.get(i), negativeRateMethod)); } return(accrualPeriods.build()); }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 575402001: // currency this.currency_Renamed = (Currency)newValue; break; case 1585636160: // notional this.notional_Renamed = (double?)newValue.Value; break; case -1540873516: // paymentDate this.paymentDate_Renamed = (LocalDate)newValue; break; case -2129778896: // startDate this.startDate_Renamed = (LocalDate)newValue; break; case -1607727319: // endDate this.endDate_Renamed = (LocalDate)newValue; break; case -1731780257: // yearFraction this.yearFraction_Renamed = (double?)newValue.Value; break; case 747425396: // fixedRate this.fixedRate_Renamed = (double?)newValue.Value; break; case -2130225658: // floatingRate this.floatingRate_Renamed = (RateComputation)newValue; break; case -536441087: // discounting this.discounting_Renamed = (FraDiscountingMethod)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case -2129778896: // startDate this.startDate_Renamed = (LocalDate)newValue; break; case -1607727319: // endDate this.endDate_Renamed = (LocalDate)newValue; break; case 1457691881: // unadjustedStartDate this.unadjustedStartDate_Renamed = (LocalDate)newValue; break; case 31758114: // unadjustedEndDate this.unadjustedEndDate_Renamed = (LocalDate)newValue; break; case -1731780257: // yearFraction this.yearFraction_Renamed = (double?)newValue.Value; break; case 625350855: // rateComputation this.rateComputation_Renamed = (RateComputation)newValue; break; case -91774989: // gearing this.gearing_Renamed = (double?)newValue.Value; break; case -895684237: // spread this.spread_Renamed = (double?)newValue.Value; break; case 1969081334: // negativeRateMethod this.negativeRateMethod_Renamed = (NegativeRateMethod)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
//------------------------------------------------------------------------- public virtual void coverage() { DispatchingRateComputationFn test = new DispatchingRateComputationFn(MOCK_IBOR_EMPTY, MOCK_IBOR_INT_EMPTY, MOCK_IBOR_AVE_EMPTY, MOCK_ON_CPD_EMPTY, MOCK_ON_AVE_EMPTY, MOCK_ON_AVE_DLY_EMPTY, MOCK_INF_MON_EMPTY, MOCK_INF_INT_EMPTY, MOCK_INF_BOND_MON_EMPTY, MOCK_INF_BOND_INT_EMPTY); FixedRateComputation @fixed = FixedRateComputation.of(0.0123d); IborRateComputation ibor = IborRateComputation.of(GBP_LIBOR_3M, FIXING_DATE, REF_DATA); IborInterpolatedRateComputation iborInt = IborInterpolatedRateComputation.of(GBP_LIBOR_3M, GBP_LIBOR_6M, FIXING_DATE, REF_DATA); IborAveragedRateComputation iborAvg = IborAveragedRateComputation.of(ImmutableList.of(IborAveragedFixing.of(ibor.Observation))); OvernightCompoundedRateComputation onCpd = OvernightCompoundedRateComputation.of(USD_FED_FUND, ACCRUAL_START_DATE, ACCRUAL_END_DATE, 0, REF_DATA); OvernightAveragedRateComputation onAvg = OvernightAveragedRateComputation.of(USD_FED_FUND, ACCRUAL_START_DATE, ACCRUAL_END_DATE, 0, REF_DATA); OvernightAveragedDailyRateComputation onAvgDly = OvernightAveragedDailyRateComputation.of(USD_FED_FUND, ACCRUAL_START_DATE, ACCRUAL_END_DATE, REF_DATA); InflationMonthlyRateComputation inflationMonthly = InflationMonthlyRateComputation.of(US_CPI_U, ACCRUAL_START_MONTH, ACCRUAL_END_MONTH); InflationInterpolatedRateComputation inflationInterp = InflationInterpolatedRateComputation.of(US_CPI_U, ACCRUAL_START_MONTH, ACCRUAL_END_MONTH, 0.3); InflationEndMonthRateComputation inflationEndMonth = InflationEndMonthRateComputation.of(US_CPI_U, 234d, ACCRUAL_END_MONTH); InflationEndInterpolatedRateComputation inflationEndInterp = InflationEndInterpolatedRateComputation.of(US_CPI_U, 1234d, ACCRUAL_END_MONTH, 0.3); RateComputation mock = mock(typeof(RateComputation)); ignoreThrows(() => test.rateSensitivity(@fixed, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)); ignoreThrows(() => test.rateSensitivity(ibor, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)); ignoreThrows(() => test.rateSensitivity(iborInt, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)); ignoreThrows(() => test.rateSensitivity(iborAvg, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)); ignoreThrows(() => test.rateSensitivity(onCpd, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)); ignoreThrows(() => test.rateSensitivity(onAvg, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)); ignoreThrows(() => test.rateSensitivity(onAvgDly, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)); ignoreThrows(() => test.rateSensitivity(inflationMonthly, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)); ignoreThrows(() => test.rateSensitivity(inflationInterp, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)); ignoreThrows(() => test.rateSensitivity(inflationEndMonth, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)); ignoreThrows(() => test.rateSensitivity(inflationEndInterp, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)); ignoreThrows(() => test.rateSensitivity(mock, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)); ExplainMapBuilder explain = ExplainMap.builder(); ignoreThrows(() => test.explainRate(@fixed, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain)); ignoreThrows(() => test.explainRate(ibor, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain)); ignoreThrows(() => test.explainRate(iborInt, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain)); ignoreThrows(() => test.explainRate(iborAvg, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain)); ignoreThrows(() => test.explainRate(onCpd, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain)); ignoreThrows(() => test.explainRate(onAvg, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain)); ignoreThrows(() => test.explainRate(onAvgDly, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain)); ignoreThrows(() => test.explainRate(inflationMonthly, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain)); ignoreThrows(() => test.explainRate(inflationInterp, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain)); ignoreThrows(() => test.explainRate(inflationEndMonth, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain)); ignoreThrows(() => test.explainRate(inflationEndInterp, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain)); ignoreThrows(() => test.explainRate(mock, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV, explain)); }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 575402001: // currency this.currency_Renamed = (Currency)newValue; break; case 1585636160: // notional this.notional_Renamed = (double?)newValue.Value; break; case 1842278244: // realCoupon this.realCoupon_Renamed = (double?)newValue.Value; break; case -2129778896: // startDate this.startDate_Renamed = (LocalDate)newValue; break; case -1607727319: // endDate this.endDate_Renamed = (LocalDate)newValue; break; case 1457691881: // unadjustedStartDate this.unadjustedStartDate_Renamed = (LocalDate)newValue; break; case 31758114: // unadjustedEndDate this.unadjustedEndDate_Renamed = (LocalDate)newValue; break; case -878940481: // detachmentDate this.detachmentDate_Renamed = (LocalDate)newValue; break; case 625350855: // rateComputation this.rateComputation_Renamed = (RateComputation)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
public virtual void test_resolve() { CapitalIndexedBond @base = sut(); LocalDate[] unAdjDates = new LocalDate[] { LocalDate.of(2008, 1, 13), LocalDate.of(2008, 7, 13), LocalDate.of(2009, 1, 13), LocalDate.of(2009, 7, 13), LocalDate.of(2010, 1, 13) }; CapitalIndexedBondPaymentPeriod[] periodic = new CapitalIndexedBondPaymentPeriod[4]; for (int i = 0; i < 4; ++i) { LocalDate start = SCHEDULE_ADJ.adjust(unAdjDates[i], REF_DATA); LocalDate end = SCHEDULE_ADJ.adjust(unAdjDates[i + 1], REF_DATA); LocalDate detachment = EX_COUPON.adjust(end, REF_DATA); RateComputation comp = RATE_CALC.createRateComputation(end); periodic[i] = CapitalIndexedBondPaymentPeriod.builder().currency(USD).startDate(start).endDate(end).unadjustedStartDate(unAdjDates[i]).unadjustedEndDate(unAdjDates[i + 1]).detachmentDate(detachment).realCoupon(COUPONS[i]).rateComputation(comp).notional(NOTIONAL).build(); } CapitalIndexedBondPaymentPeriod nominalExp = periodic[3].withUnitCoupon(periodic[0].StartDate, periodic[0].UnadjustedStartDate); ResolvedCapitalIndexedBond expected = ResolvedCapitalIndexedBond.builder().securityId(SECURITY_ID).dayCount(ACT_ACT_ISDA).legalEntityId(LEGAL_ENTITY).nominalPayment(nominalExp).periodicPayments(periodic).frequency(SCHEDULE.Frequency).rollConvention(SCHEDULE.calculatedRollConvention()).settlementDateOffset(SETTLE_OFFSET).yieldConvention(US_IL_REAL).rateCalculation(@base.RateCalculation).build(); assertEquals(@base.resolve(REF_DATA), expected); }
// trusted constructor internal RateAccrualPeriod(SchedulePeriod period, double yearFraction, RateComputation rateComputation) : this(period, yearFraction, rateComputation, 1d, 0d, NegativeRateMethod.ALLOW_NEGATIVE) { }
/// <summary> /// Sets the rate to be computed. /// <para> /// The value of the period is based on this rate. /// Different implementations of the {@code RateComputation} interface have different /// approaches to computing the rate, including averaging, overnight and interpolation. /// For example, it might be a well known market index such as 'GBP-LIBOR-3M'. /// </para> /// </summary> /// <param name="rateComputation"> the new value, not null </param> /// <returns> this, for chaining, not null </returns> public Builder rateComputation(RateComputation rateComputation) { JodaBeanUtils.notNull(rateComputation, "rateComputation"); this.rateComputation_Renamed = rateComputation; return(this); }
/// <summary> /// Sets the floating rate of interest. /// <para> /// The floating rate to be paid is based on this index. /// It will be a well known market index such as 'GBP-LIBOR-3M'. /// </para> /// </summary> /// <param name="floatingRate"> the new value, not null </param> /// <returns> this, for chaining, not null </returns> public Builder floatingRate(RateComputation floatingRate) { JodaBeanUtils.notNull(floatingRate, "floatingRate"); this.floatingRate_Renamed = floatingRate; return(this); }