public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 1574023291: // securityId this.securityId_Renamed = (SecurityId)newValue; break; case 575402001: // currency this.currency_Renamed = (Currency)newValue; break; case 1585636160: // notional this.notional_Renamed = (double?)newValue.Value; break; case -1540322338: // accrualFactor this.accrualFactor_Renamed = (double?)newValue.Value; break; case -1621804100: // iborRate this.iborRate_Renamed = (IborRateComputation)newValue; break; case -142444: // rounding this.rounding_Renamed = (Rounding)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(ResolvedIborFuture beanToCopy) { this.securityId_Renamed = beanToCopy.SecurityId; this.currency_Renamed = beanToCopy.Currency; this.notional_Renamed = beanToCopy.Notional; this.accrualFactor_Renamed = beanToCopy.AccrualFactor; this.iborRate_Renamed = beanToCopy.IborRate; this.rounding_Renamed = beanToCopy.Rounding; }
public virtual void test_rate_IborRateComputation() { RateComputationFn <IborRateComputation> mockIbor = mock(typeof(RateComputationFn)); IborRateComputation ro = IborRateComputation.of(GBP_LIBOR_3M, FIXING_DATE, REF_DATA); when(mockIbor.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)).thenReturn(0.0123d); DispatchingRateComputationFn test = new DispatchingRateComputationFn(mockIbor, 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); assertEquals(test.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV), 0.0123d, 0d); }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(ResolvedIborFixingDeposit beanToCopy) { this.currency_Renamed = beanToCopy.Currency; this.notional_Renamed = beanToCopy.Notional; 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; }
// calculate the last fixing date private LocalDate calculateLastFixingDate(LocalDate valuationDate, ReferenceData refData) { SwapTrade trade = template.createTrade(valuationDate, BuySell.BUY, 1, 1, refData); SwapLeg iborLeg = trade.Product.getLegs(SwapLegType.IBOR).get(0); ResolvedSwapLeg iborLegExpanded = iborLeg.resolve(refData); IList <SwapPaymentPeriod> periods = iborLegExpanded.PaymentPeriods; int nbPeriods = periods.Count; RatePaymentPeriod lastPeriod = (RatePaymentPeriod)periods[nbPeriods - 1]; IList <RateAccrualPeriod> accruals = lastPeriod.AccrualPeriods; int nbAccruals = accruals.Count; IborRateComputation ibor = (IborRateComputation)accruals[nbAccruals - 1].RateComputation; return(ibor.FixingDate); }
/// <summary> /// Creates an instance. </summary> /// <param name="securityId"> the value of the property, not null </param> /// <param name="currency"> the value of the property, not null </param> /// <param name="notional"> the value of the property </param> /// <param name="accrualFactor"> the value of the property </param> /// <param name="iborRate"> the value of the property, not null </param> /// <param name="rounding"> the value of the property, not null </param> internal ResolvedIborFuture(SecurityId securityId, Currency currency, double notional, double accrualFactor, IborRateComputation iborRate, Rounding rounding) { JodaBeanUtils.notNull(securityId, "securityId"); JodaBeanUtils.notNull(currency, "currency"); ArgChecker.notNegativeOrZero(notional, "notional"); ArgChecker.notNegativeOrZero(accrualFactor, "accrualFactor"); JodaBeanUtils.notNull(iborRate, "iborRate"); JodaBeanUtils.notNull(rounding, "rounding"); this.securityId = securityId; this.currency = currency; this.notional = notional; this.accrualFactor = accrualFactor; this.iborRate = iborRate; this.rounding = rounding; }
private ResolvedIborFixingDeposit(Currency currency, double notional, LocalDate startDate, LocalDate endDate, double yearFraction, double fixedRate, IborRateComputation floatingRate) { JodaBeanUtils.notNull(currency, "currency"); JodaBeanUtils.notNull(startDate, "startDate"); JodaBeanUtils.notNull(endDate, "endDate"); ArgChecker.notNegative(yearFraction, "yearFraction"); JodaBeanUtils.notNull(floatingRate, "floatingRate"); this.currency = currency; this.notional = notional; this.startDate = startDate; this.endDate = endDate; this.yearFraction = yearFraction; this.fixedRate = fixedRate; this.floatingRate = floatingRate; validate(); }
//------------------------------------------------------------------------- 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)); }
//------------------------------------------------------------------------- /// <summary> /// Test explain. /// </summary> public virtual void test_explainPresentValue_ISDA() { ResolvedFra fraExp = RFRA; SimpleRatesProvider prov = createProvider(fraExp); DiscountingFraProductPricer test = DiscountingFraProductPricer.DEFAULT; CurrencyAmount fvExpected = test.forecastValue(fraExp, prov); CurrencyAmount pvExpected = test.presentValue(fraExp, prov); ExplainMap explain = test.explainPresentValue(fraExp, prov); Currency currency = fraExp.Currency; int daysBetween = (int) DAYS.between(fraExp.StartDate, fraExp.EndDate); assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "FRA"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), fraExp.PaymentDate); assertEquals(explain.get(ExplainKey.START_DATE).get(), fraExp.StartDate); assertEquals(explain.get(ExplainKey.END_DATE).get(), fraExp.EndDate); assertEquals(explain.get(ExplainKey.ACCRUAL_YEAR_FRACTION).Value, fraExp.YearFraction); assertEquals(explain.get(ExplainKey.DAYS).Value, (int?)(int) daysBetween); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), currency); assertEquals(explain.get(ExplainKey.NOTIONAL).get().Amount, fraExp.Notional, TOLERANCE); assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().Amount, fraExp.Notional, TOLERANCE); assertEquals(explain.get(ExplainKey.OBSERVATIONS).get().size(), 1); ExplainMap explainObs = explain.get(ExplainKey.OBSERVATIONS).get().get(0); IborRateComputation floatingRate = (IborRateComputation) fraExp.FloatingRate; assertEquals(explainObs.get(ExplainKey.INDEX).get(), floatingRate.Index); assertEquals(explainObs.get(ExplainKey.FIXING_DATE).get(), floatingRate.FixingDate); assertEquals(explainObs.get(ExplainKey.INDEX_VALUE).Value, FORWARD_RATE, TOLERANCE); assertEquals(explainObs.get(ExplainKey.FROM_FIXING_SERIES).HasValue, false); assertEquals(explain.get(ExplainKey.DISCOUNT_FACTOR).Value, DISCOUNT_FACTOR, TOLERANCE); assertEquals(explain.get(ExplainKey.FIXED_RATE).Value, fraExp.FixedRate, TOLERANCE); assertEquals(explain.get(ExplainKey.PAY_OFF_RATE).Value, FORWARD_RATE, TOLERANCE); assertEquals(explain.get(ExplainKey.COMBINED_RATE).Value, FORWARD_RATE, TOLERANCE); assertEquals(explain.get(ExplainKey.UNIT_AMOUNT).Value, fvExpected.Amount / fraExp.Notional, TOLERANCE); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Currency, currency); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Amount, fvExpected.Amount, TOLERANCE); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Currency, currency); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Amount, pvExpected.Amount, TOLERANCE); // test via FraTrade DiscountingFraTradePricer testTrade = new DiscountingFraTradePricer(test); assertEquals(testTrade.explainPresentValue(RFRA_TRADE, prov), test.explainPresentValue(RFRA, prov)); }
//------------------------------------------------------------------------- /// <summary> /// Creates the {@code RateComputation} for the stub. /// </summary> /// <param name="fixingDate"> the fixing date </param> /// <param name="defaultIndex"> the default index to use if the stub has no rules </param> /// <param name="refData"> the reference data </param> /// <returns> the rate observation </returns> internal RateComputation createRateComputation(LocalDate fixingDate, IborIndex defaultIndex, ReferenceData refData) { if (Interpolated) { return(IborInterpolatedRateComputation.of(index, indexInterpolated, fixingDate, refData)); } else if (FloatingRate) { return(IborRateComputation.of(index, fixingDate, refData)); } else if (FixedRate) { return(FixedRateComputation.of(fixedRate.Value)); } else if (KnownAmount) { return(KnownAmountRateComputation.of(knownAmount)); } else { return(IborRateComputation.of(defaultIndex, fixingDate, refData)); } }
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 -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 = (IborRateComputation)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
//------------------------------------------------------------------------- public ResolvedIborCapFloorLeg resolve(ReferenceData refData) { Schedule adjustedSchedule = paymentSchedule.createSchedule(refData); DoubleArray cap = CapSchedule.Present ? capSchedule.resolveValues(adjustedSchedule) : null; DoubleArray floor = FloorSchedule.Present ? floorSchedule.resolveValues(adjustedSchedule) : null; DoubleArray notionals = notional.resolveValues(adjustedSchedule); DateAdjuster fixingDateAdjuster = calculation.FixingDateOffset.resolve(refData); DateAdjuster paymentDateAdjuster = paymentDateOffset.resolve(refData); System.Func <LocalDate, IborIndexObservation> obsFn = calculation.Index.resolve(refData); ImmutableList.Builder <IborCapletFloorletPeriod> periodsBuild = ImmutableList.builder(); for (int i = 0; i < adjustedSchedule.size(); i++) { SchedulePeriod period = adjustedSchedule.getPeriod(i); LocalDate paymentDate = paymentDateAdjuster.adjust(period.EndDate); LocalDate fixingDate = fixingDateAdjuster.adjust((calculation.FixingRelativeTo.Equals(FixingRelativeTo.PERIOD_START)) ? period.StartDate : period.EndDate); double signedNotional = payReceive.normalize(notionals.get(i)); periodsBuild.add(IborCapletFloorletPeriod.builder().unadjustedStartDate(period.UnadjustedStartDate).unadjustedEndDate(period.UnadjustedEndDate).startDate(period.StartDate).endDate(period.EndDate).iborRate(IborRateComputation.of(obsFn(fixingDate))).paymentDate(paymentDate).notional(signedNotional).currency(currency).yearFraction(period.yearFraction(calculation.DayCount, adjustedSchedule)).caplet(cap != null ? cap.get(i) : null).floorlet(floor != null ? floor.get(i) : null).build()); } return(ResolvedIborCapFloorLeg.builder().capletFloorletPeriods(periodsBuild.build()).payReceive(payReceive).build()); }
public virtual void test_resolve_cap() { IborRateCalculation rateCalc = IborRateCalculation.builder().index(EUR_EURIBOR_3M).fixingRelativeTo(FixingRelativeTo.PERIOD_END).fixingDateOffset(EUR_EURIBOR_3M.FixingDateOffset).build(); IborCapFloorLeg @base = IborCapFloorLeg.builder().calculation(rateCalc).capSchedule(CAP).notional(NOTIONAL).paymentDateOffset(PAYMENT_OFFSET).paymentSchedule(SCHEDULE).payReceive(RECEIVE).build(); LocalDate[] unadjustedDates = new LocalDate[] { START, START.plusMonths(3), START.plusMonths(6), START.plusMonths(9), START.plusMonths(12) }; IborCapletFloorletPeriod[] periods = new IborCapletFloorletPeriod[4]; for (int i = 0; i < 4; ++i) { LocalDate start = BUSS_ADJ.adjust(unadjustedDates[i], REF_DATA); LocalDate end = BUSS_ADJ.adjust(unadjustedDates[i + 1], REF_DATA); double yearFraction = EUR_EURIBOR_3M.DayCount.relativeYearFraction(start, end); periods[i] = IborCapletFloorletPeriod.builder().caplet(CAP.InitialValue).currency(EUR).startDate(start).endDate(end).unadjustedStartDate(unadjustedDates[i]).unadjustedEndDate(unadjustedDates[i + 1]).paymentDate(PAYMENT_OFFSET.adjust(end, REF_DATA)).notional(NOTIONALS[i]).iborRate(IborRateComputation.of(EUR_EURIBOR_3M, rateCalc.FixingDateOffset.adjust(end, REF_DATA), REF_DATA)).yearFraction(yearFraction).build(); } ResolvedIborCapFloorLeg expected = ResolvedIborCapFloorLeg.builder().capletFloorletPeriods(periods).payReceive(RECEIVE).build(); ResolvedIborCapFloorLeg computed = @base.resolve(REF_DATA); assertEquals(computed, expected); }
/// <summary> /// Sets the Ibor rate observation. /// <para> /// The future is based on this index. /// It will be a well known market index such as 'USD-LIBOR-3M'. /// </para> /// </summary> /// <param name="iborRate"> the new value, not null </param> /// <returns> this, for chaining, not null </returns> public Builder iborRate(IborRateComputation iborRate) { JodaBeanUtils.notNull(iborRate, "iborRate"); this.iborRate_Renamed = iborRate; return(this); }
public virtual void test_resolve_floor() { IborCapFloorLeg @base = IborCapFloorLeg.builder().calculation(RATE_CALCULATION).floorSchedule(FLOOR).currency(GBP).notional(NOTIONAL).paymentDateOffset(PAYMENT_OFFSET).paymentSchedule(SCHEDULE).payReceive(PAY).build(); LocalDate[] unadjustedDates = new LocalDate[] { START, START.plusMonths(3), START.plusMonths(6), START.plusMonths(9), START.plusMonths(12) }; IborCapletFloorletPeriod[] periods = new IborCapletFloorletPeriod[4]; for (int i = 0; i < 4; ++i) { LocalDate start = BUSS_ADJ.adjust(unadjustedDates[i], REF_DATA); LocalDate end = BUSS_ADJ.adjust(unadjustedDates[i + 1], REF_DATA); double yearFraction = EUR_EURIBOR_3M.DayCount.relativeYearFraction(start, end); LocalDate fixingDate = RATE_CALCULATION.FixingDateOffset.adjust(start, REF_DATA); periods[i] = IborCapletFloorletPeriod.builder().floorlet(STRIKES[i]).currency(GBP).startDate(start).endDate(end).unadjustedStartDate(unadjustedDates[i]).unadjustedEndDate(unadjustedDates[i + 1]).paymentDate(PAYMENT_OFFSET.adjust(end, REF_DATA)).notional(-NOTIONALS[i]).iborRate(IborRateComputation.of(EUR_EURIBOR_3M, fixingDate, REF_DATA)).yearFraction(yearFraction).build(); } ResolvedIborCapFloorLeg expected = ResolvedIborCapFloorLeg.builder().capletFloorletPeriods(periods).payReceive(PAY).build(); ResolvedIborCapFloorLeg computed = @base.resolve(REF_DATA); assertEquals(computed, expected); }
//------------------------------------------------------------------------- public ResolvedIborFuture resolve(ReferenceData refData) { IborRateComputation iborRate = IborRateComputation.of(index, lastTradeDate, refData); return(new ResolvedIborFuture(securityId, currency, notional, accrualFactor, iborRate, rounding)); }
/// <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(IborRateComputation floatingRate) { JodaBeanUtils.notNull(floatingRate, "floatingRate"); this.floatingRate_Renamed = floatingRate; return(this); }