public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 122345516: // observation this.observation = (FxIndexObservation)newValue; break; case 727652476: // referenceCurrency this.referenceCurrency = (Currency)newValue; break; case 575402001: // currency this.currency = (Currency)newValue; break; case 564403871: // sensitivity this.sensitivity = (double?)newValue.Value; 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(ResolvedFxNdf beanToCopy) { this.settlementCurrencyNotional_Renamed = beanToCopy.SettlementCurrencyNotional; this.agreedFxRate_Renamed = beanToCopy.AgreedFxRate; this.observation_Renamed = beanToCopy.Observation; this.paymentDate_Renamed = beanToCopy.PaymentDate; }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 594670010: // settlementCurrencyNotional this.settlementCurrencyNotional_Renamed = (CurrencyAmount)newValue; break; case 1040357930: // agreedFxRate this.agreedFxRate_Renamed = (FxRate)newValue; break; case 122345516: // observation this.observation_Renamed = (FxIndexObservation)newValue; break; case -1540873516: // paymentDate this.paymentDate_Renamed = (LocalDate)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
private FxReset(FxIndexObservation observation, Currency referenceCurrency) { JodaBeanUtils.notNull(observation, "observation"); JodaBeanUtils.notNull(referenceCurrency, "referenceCurrency"); this.observation = observation; this.referenceCurrency = referenceCurrency; validate(); }
//------------------------------------------------------------------------- /// <summary> /// Obtains an instance from the observation, reference currency and sensitivity value. /// <para> /// The sensitivity currency is defaulted to be the counter currency of queried currency pair. /// /// </para> /// </summary> /// <param name="observation"> the rate observation, including the fixing date </param> /// <param name="referenceCurrency"> the reference currency </param> /// <param name="sensitivity"> the value of the sensitivity </param> /// <returns> the point sensitivity object </returns> public static FxIndexSensitivity of(FxIndexObservation observation, Currency referenceCurrency, double sensitivity) { CurrencyPair obsPair = observation.CurrencyPair; bool inverse = referenceCurrency.Equals(obsPair.Counter); CurrencyPair queriedPair = inverse ? obsPair.inverse() : obsPair; Currency sensiCurrency = queriedPair.Counter; return(new FxIndexSensitivity(observation, referenceCurrency, sensiCurrency, sensitivity)); }
//------------------------------------------------------------------------- public double rate(FxIndexObservation observation, Currency baseCurrency) { ArgChecker.isTrue(index.CurrencyPair.contains(baseCurrency), "Currency {} invalid for FxIndex {}", baseCurrency, index); LocalDate fixingDate = observation.FixingDate; double fxIndexRate = !fixingDate.isAfter(ValuationDate) ? historicRate(observation) : forwardRate(observation); bool inverse = baseCurrency.Equals(index.CurrencyPair.Counter); return(inverse ? 1d / fxIndexRate : fxIndexRate); }
private FxIndexSensitivity(FxIndexObservation observation, Currency referenceCurrency, Currency currency, double sensitivity) { JodaBeanUtils.notNull(observation, "observation"); JodaBeanUtils.notNull(referenceCurrency, "referenceCurrency"); JodaBeanUtils.notNull(currency, "currency"); this.observation = observation; this.referenceCurrency = referenceCurrency; this.currency = currency; this.sensitivity = sensitivity; }
private FxResetNotionalExchange(CurrencyAmount notionalAmount, LocalDate paymentDate, FxIndexObservation observation) { JodaBeanUtils.notNull(notionalAmount, "notionalAmount"); JodaBeanUtils.notNull(paymentDate, "paymentDate"); JodaBeanUtils.notNull(observation, "observation"); this.notionalAmount = notionalAmount; this.paymentDate = paymentDate; this.observation = observation; validate(); }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(KnownAmountNotionalSwapPaymentPeriod beanToCopy) { this.payment_Renamed = beanToCopy.Payment; this.startDate_Renamed = beanToCopy.StartDate; this.endDate_Renamed = beanToCopy.EndDate; this.unadjustedStartDate_Renamed = beanToCopy.UnadjustedStartDate; this.unadjustedEndDate_Renamed = beanToCopy.UnadjustedEndDate; this.notionalAmount_Renamed = beanToCopy.NotionalAmount; this.fxResetObservation_Renamed = beanToCopy.fxResetObservation; }
//------------------------------------------------------------------------- public PointSensitivityBuilder ratePointSensitivity(FxIndexObservation observation, Currency baseCurrency) { ArgChecker.isTrue(index.CurrencyPair.contains(baseCurrency), "Currency {} invalid for FxIndex {}", baseCurrency, index); LocalDate fixingDate = observation.FixingDate; if (fixingDate.isBefore(ValuationDate) || (fixingDate.Equals(ValuationDate) && fixings.get(fixingDate).HasValue)) { return(PointSensitivityBuilder.none()); } return(FxIndexSensitivity.of(observation, baseCurrency, 1d)); }
private ResolvedFxNdf(CurrencyAmount settlementCurrencyNotional, FxRate agreedFxRate, FxIndexObservation observation, LocalDate paymentDate) { JodaBeanUtils.notNull(settlementCurrencyNotional, "settlementCurrencyNotional"); JodaBeanUtils.notNull(agreedFxRate, "agreedFxRate"); JodaBeanUtils.notNull(observation, "observation"); JodaBeanUtils.notNull(paymentDate, "paymentDate"); this.settlementCurrencyNotional = settlementCurrencyNotional; this.agreedFxRate = agreedFxRate; this.observation = observation; this.paymentDate = paymentDate; validate(); }
private KnownAmountNotionalSwapPaymentPeriod(Payment payment, LocalDate startDate, LocalDate endDate, LocalDate unadjustedStartDate, LocalDate unadjustedEndDate, CurrencyAmount notionalAmount, FxIndexObservation fxResetObservation) { JodaBeanUtils.notNull(payment, "payment"); JodaBeanUtils.notNull(startDate, "startDate"); JodaBeanUtils.notNull(endDate, "endDate"); JodaBeanUtils.notNull(unadjustedStartDate, "unadjustedStartDate"); JodaBeanUtils.notNull(unadjustedEndDate, "unadjustedEndDate"); this.payment = payment; this.startDate = startDate; this.endDate = endDate; this.unadjustedStartDate = unadjustedStartDate; this.unadjustedEndDate = unadjustedEndDate; this.notionalAmount = notionalAmount; this.fxResetObservation = fxResetObservation; validate(); }
// create notional exchange events when FxReset specified private static ImmutableList <SwapPaymentEvent> createFxResetEvents(IList <NotionalPaymentPeriod> payPeriods, LocalDate initialExchangeDate, bool initialExchange, bool intermediateExchange, bool finalExchange) { ImmutableList.Builder <SwapPaymentEvent> events = ImmutableList.builder(); for (int i = 0; i < payPeriods.Count; i++) { NotionalPaymentPeriod period = payPeriods[i]; LocalDate startPaymentDate = (i == 0 ? initialExchangeDate : payPeriods[i - 1].PaymentDate); bool includeStartPayment = i == 0 ? initialExchange : intermediateExchange; bool includeEndPayment = i == payPeriods.Count - 1 ? finalExchange : intermediateExchange; if (period.FxResetObservation.Present) { FxIndexObservation observation = period.FxResetObservation.get(); // notional out at start of period if (includeStartPayment) { events.add(FxResetNotionalExchange.of(period.NotionalAmount.negated(), startPaymentDate, observation)); } // notional in at end of period if (includeEndPayment) { events.add(FxResetNotionalExchange.of(period.NotionalAmount, period.PaymentDate, observation)); } } else { // handle weird swap where only some periods have FX reset // notional out at start of period if (includeStartPayment) { events.add(NotionalExchange.of(CurrencyAmount.of(period.Currency, -period.NotionalAmount.Amount), startPaymentDate)); } // notional in at end of period if (includeEndPayment) { events.add(NotionalExchange.of(CurrencyAmount.of(period.Currency, period.NotionalAmount.Amount), period.PaymentDate)); } } } return(events.build()); }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case -902123592: // notionalAmount this.notionalAmount = (CurrencyAmount)newValue; break; case -1540873516: // paymentDate this.paymentDate = (LocalDate)newValue; break; case 122345516: // observation this.observation = (FxIndexObservation)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
public virtual void pointAndParameterFx() { ImmutableRatesProvider test = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build(); ImmutableRatesProvider test_gbp_up = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP_UP).discountCurve(USD, DISCOUNT_CURVE_USD).build(); ImmutableRatesProvider test_gbp_dw = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP_DOWN).discountCurve(USD, DISCOUNT_CURVE_USD).build(); ImmutableRatesProvider test_usd_up = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD_UP).build(); ImmutableRatesProvider test_usd_dw = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD_DOWN).build(); LocalDate matuirtyDate = GBP_USD_WM.calculateMaturityFromFixing(VAL_DATE, REF_DATA); double maturityTime = DAY_COUNT.relativeYearFraction(VAL_DATE, matuirtyDate); // GBP based FxIndexObservation obs = FxIndexObservation.of(GBP_USD_WM, VAL_DATE, REF_DATA); PointSensitivityBuilder sensiBuildCmpGBP = test.fxIndexRates(GBP_USD_WM).ratePointSensitivity(obs, GBP); FxIndexSensitivity sensiBuildExpGBP = FxIndexSensitivity.of(obs, GBP, USD, 1.0); assertTrue(sensiBuildCmpGBP.Equals(sensiBuildExpGBP)); double sense_gbp1 = 0.5 * (test_gbp_up.fxIndexRates(GBP_USD_WM).rate(obs, GBP) - test_gbp_dw.fxIndexRates(GBP_USD_WM).rate(obs, GBP)) / EPS_FD * (-maturityTime * GBP_DSC); double sense_usd1 = 0.5 * (test_usd_up.fxIndexRates(GBP_USD_WM).rate(obs, GBP) - test_usd_dw.fxIndexRates(GBP_USD_WM).rate(obs, GBP)) / EPS_FD * (-maturityTime * USD_DSC); PointSensitivityBuilder sensiBuildDecGBP = ZeroRateSensitivity.of(GBP, maturityTime, USD, sense_gbp1); sensiBuildDecGBP = sensiBuildDecGBP.combinedWith(ZeroRateSensitivity.of(USD, maturityTime, USD, sense_usd1)); CurrencyParameterSensitivities paramSensiCmpGBP = test.parameterSensitivity(sensiBuildCmpGBP.build().normalized()); CurrencyParameterSensitivities paramSensiExpGBP = test.parameterSensitivity(sensiBuildDecGBP.build().normalized()); assertTrue(paramSensiCmpGBP.equalWithTolerance(paramSensiExpGBP, EPS_FD)); // USD based PointSensitivityBuilder sensiBuildCmpUSD = test.fxIndexRates(GBP_USD_WM).ratePointSensitivity(obs, USD); FxIndexSensitivity sensiBuildExpUSD = FxIndexSensitivity.of(obs, USD, GBP, 1.0); assertTrue(sensiBuildCmpUSD.Equals(sensiBuildExpUSD)); double sense_gbp2 = 0.5 * (test_gbp_up.fxIndexRates(GBP_USD_WM).rate(obs, USD) - test_gbp_dw.fxIndexRates(GBP_USD_WM).rate(obs, USD)) / EPS_FD * (-maturityTime * GBP_DSC); double sense_usd2 = 0.5 * (test_usd_up.fxIndexRates(GBP_USD_WM).rate(obs, USD) - test_usd_dw.fxIndexRates(GBP_USD_WM).rate(obs, USD)) / EPS_FD * (-maturityTime * USD_DSC); PointSensitivityBuilder sensiBuildDecUSD = ZeroRateSensitivity.of(GBP, maturityTime, GBP, sense_gbp2); sensiBuildDecUSD = sensiBuildDecUSD.combinedWith(ZeroRateSensitivity.of(USD, maturityTime, GBP, sense_usd2)); CurrencyParameterSensitivities paramSensiCmpUSD = test.parameterSensitivity(sensiBuildCmpUSD.build().normalized()); CurrencyParameterSensitivities paramSensiExpUSD = test.parameterSensitivity(sensiBuildDecUSD.build().normalized()); assertTrue(paramSensiCmpUSD.equalWithTolerance(paramSensiExpUSD, EPS_FD)); }
// historic rate private double historicRate(FxIndexObservation observation) { LocalDate fixingDate = observation.FixingDate; double? fixedRate = fixings.get(fixingDate); if (fixedRate.HasValue) { return(fixedRate.Value); } else if (fixingDate.isBefore(ValuationDate)) { // the fixing is required if (fixings.Empty) { throw new System.ArgumentException(Messages.format("Unable to get fixing for {} on date {}, no time-series supplied", index, fixingDate)); } throw new System.ArgumentException(Messages.format("Unable to get fixing for {} on date {}", index, fixingDate)); } else { return(forwardRate(observation)); } }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case -786681338: // payment this.payment_Renamed = (Payment)newValue; 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 -902123592: // notionalAmount this.notionalAmount_Renamed = (CurrencyAmount)newValue; break; case 1301329999: // fxResetObservation this.fxResetObservation_Renamed = (FxIndexObservation)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
// forward rate private double forwardRate(FxIndexObservation observation) { return(fxForwardRates.rate(index.CurrencyPair.Base, observation.MaturityDate)); }
/// <summary> /// Sets the FX index observation. /// <para> /// This defines the observation of the index used to settle the trade. /// The value of the trade is based on the difference between the actual rate and the agreed rate. /// </para> /// <para> /// An FX index is a daily rate of exchange between two currencies. /// Note that the order of the currencies in the index does not matter, as the /// conversion direction is fully defined by the currency of the reference amount. /// </para> /// </summary> /// <param name="observation"> the new value, not null </param> /// <returns> this, for chaining, not null </returns> public Builder observation(FxIndexObservation observation) { JodaBeanUtils.notNull(observation, "observation"); this.observation_Renamed = observation; return(this); }
//------------------------------------------------------------------------- /// <summary> /// Obtains an instance from the amount, date and FX index observation. /// </summary> /// <param name="notionalAmount"> the notional amount that will be FX converted </param> /// <param name="paymentDate"> the date that the payment is made </param> /// <param name="observation"> the FX observation to perform </param> /// <returns> the FX reset notional exchange </returns> public static FxResetNotionalExchange of(CurrencyAmount notionalAmount, LocalDate paymentDate, FxIndexObservation observation) { return(new FxResetNotionalExchange(notionalAmount, paymentDate, observation)); }
//------------------------------------------------------------------------- public ResolvedFxNdf resolve(ReferenceData refData) { LocalDate fixingDate = index.calculateFixingFromMaturity(paymentDate, refData); return(ResolvedFxNdf.builder().settlementCurrencyNotional(settlementCurrencyNotional).agreedFxRate(agreedFxRate).observation(FxIndexObservation.of(index, fixingDate, refData)).paymentDate(paymentDate).build()); }
public virtual void test_currencyExposureOnFixing_noTimeSeries() { double eps = 1.0e-14; LocalDate valuationDate = date(2014, 6, 27); LocalDate paymentDate = date(2014, 7, 1); LocalDate fixingDate = date(2014, 6, 27); FxResetNotionalExchange resetNotionalUSD = FxResetNotionalExchange.of(CurrencyAmount.of(USD, NOTIONAL), paymentDate, FxIndexObservation.of(GBP_USD_WM, fixingDate, REF_DATA)); FxResetNotionalExchange resetNotionalGBP = FxResetNotionalExchange.of(CurrencyAmount.of(GBP, -NOTIONAL), paymentDate, FxIndexObservation.of(GBP_USD_WM, fixingDate, REF_DATA)); ImmutableRatesProvider prov = ImmutableRatesProvider.builder(valuationDate).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build(); DiscountingFxResetNotionalExchangePricer test = new DiscountingFxResetNotionalExchangePricer(); // USD MultiCurrencyAmount computedUSD = test.currencyExposure(resetNotionalUSD, prov); PointSensitivities pointUSD = test.presentValueSensitivity(resetNotionalUSD, prov).build(); MultiCurrencyAmount expectedUSD = prov.currencyExposure(pointUSD.convertedTo(USD, prov)).plus(CurrencyAmount.of(resetNotionalUSD.Currency, test.presentValue(resetNotionalUSD, prov))); assertFalse(computedUSD.contains(GBP)); // 0 GBP assertEquals(computedUSD.getAmount(USD).Amount, expectedUSD.getAmount(USD).Amount, eps * NOTIONAL); // GBP MultiCurrencyAmount computedGBP = test.currencyExposure(resetNotionalGBP, prov); PointSensitivities pointGBP = test.presentValueSensitivity(resetNotionalGBP, prov).build(); MultiCurrencyAmount expectedGBP = prov.currencyExposure(pointGBP.convertedTo(GBP, prov)).plus(CurrencyAmount.of(resetNotionalGBP.Currency, test.presentValue(resetNotionalGBP, prov))); assertFalse(computedGBP.contains(USD)); // 0 USD assertEquals(computedGBP.getAmount(GBP).Amount, expectedGBP.getAmount(GBP).Amount, eps * NOTIONAL); // FD approximation FxMatrix fxMatrixUp = FxMatrix.of(GBP, USD, FX_RATE + EPS_FD); ImmutableRatesProvider provUp = ImmutableRatesProvider.builder(valuationDate).fxRateProvider(fxMatrixUp).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build(); double expectedFdUSD = -(test.presentValue(resetNotionalUSD, provUp) - test.presentValue(resetNotionalUSD, prov)) * FX_RATE * FX_RATE / EPS_FD; assertEquals(computedUSD.getAmount(USD).Amount, expectedFdUSD, EPS_FD * NOTIONAL); double expectedFdGBP = (test.presentValue(resetNotionalGBP, provUp) - test.presentValue(resetNotionalGBP, prov)) / EPS_FD; assertEquals(computedGBP.getAmount(GBP).Amount, expectedFdGBP, EPS_FD * NOTIONAL); }
/// <summary> /// Sets the FX reset definition, optional. /// <para> /// This property is used when the defined amount of the notional is specified in /// a currency other than the currency of the swap leg. When this occurs, the notional /// amount has to be converted using an FX rate to the swap leg currency. /// </para> /// <para> /// The FX reset definition must be valid. The payment currency and the currency /// of the notional must differ, and the currency pair must be that of the observation. /// </para> /// </summary> /// <param name="fxResetObservation"> the new value </param> /// <returns> this, for chaining, not null </returns> public Builder fxResetObservation(FxIndexObservation fxResetObservation) { this.fxResetObservation_Renamed = fxResetObservation; return(this); }
/// <summary> /// Obtains an instance from the observation, reference currency and sensitivity value, /// specifying the currency of the value. /// </summary> /// <param name="observation"> the rate observation, including the fixing date </param> /// <param name="referenceCurrency"> the reference currency </param> /// <param name="sensitivityCurrency"> the currency of the sensitivity </param> /// <param name="sensitivity"> the value of the sensitivity </param> /// <returns> the point sensitivity object </returns> public static FxIndexSensitivity of(FxIndexObservation observation, Currency referenceCurrency, Currency sensitivityCurrency, double sensitivity) { return(new FxIndexSensitivity(observation, referenceCurrency, sensitivityCurrency, sensitivity)); }
/// <summary> /// Obtains an instance based on a payment, schedule period, notional and FX reset. /// </summary> /// <param name="payment"> the payment </param> /// <param name="period"> the schedule period </param> /// <param name="notional"> the notional </param> /// <param name="fxResetObservation"> the FX reset observation </param> /// <returns> the period </returns> public static KnownAmountNotionalSwapPaymentPeriod of(Payment payment, SchedulePeriod period, CurrencyAmount notional, FxIndexObservation fxResetObservation) { return(KnownAmountNotionalSwapPaymentPeriod.builder().payment(payment).startDate(period.StartDate).endDate(period.EndDate).unadjustedStartDate(period.UnadjustedStartDate).unadjustedEndDate(period.UnadjustedEndDate).notionalAmount(notional).fxResetObservation(fxResetObservation).build()); }
//------------------------------------------------------------------------- /// <summary> /// Obtains an instance from the observation and reference currency. /// </summary> /// <param name="observation"> the FX index observation </param> /// <param name="referenceCurrency"> the reference currency </param> /// <returns> the FX reset </returns> /// <exception cref="IllegalArgumentException"> if the currency is not one of those in the index </exception> public static FxReset of(FxIndexObservation observation, Currency referenceCurrency) { return(new FxReset(observation, referenceCurrency)); }