internal static FxSwap sut2() { FxSingle nearLeg = FxSingle.of(CurrencyAmount.of(GBP, 1_100), CurrencyAmount.of(USD, -1_650), DATE_2011_11_21); FxSingle farLeg = FxSingle.of(CurrencyAmount.of(GBP, -1_100), CurrencyAmount.of(USD, 1_750), DATE_2011_12_21); return(FxSwap.of(nearLeg, farLeg)); }
public virtual void test_presentValue_ended() { ResolvedFxSingle fwd = ResolvedFxSingle.of(CurrencyAmount.of(USD, NOMINAL_USD), FxRate.of(USD, KRW, FX_RATE), PAYMENT_DATE_PAST); MultiCurrencyAmount computed = PRICER.presentValue(fwd, PROVIDER); assertEquals(computed, MultiCurrencyAmount.empty()); }
//------------------------------------------------------------------------- public virtual void explainPresentValue(KnownAmountSwapPaymentPeriod period, RatesProvider provider, ExplainMapBuilder builder) { Currency currency = period.Currency; LocalDate paymentDate = period.PaymentDate; builder.put(ExplainKey.ENTRY_TYPE, "KnownAmountPaymentPeriod"); builder.put(ExplainKey.PAYMENT_DATE, paymentDate); builder.put(ExplainKey.PAYMENT_CURRENCY, currency); builder.put(ExplainKey.START_DATE, period.StartDate); builder.put(ExplainKey.UNADJUSTED_START_DATE, period.UnadjustedStartDate); builder.put(ExplainKey.END_DATE, period.EndDate); builder.put(ExplainKey.UNADJUSTED_END_DATE, period.UnadjustedEndDate); builder.put(ExplainKey.DAYS, (int)DAYS.between(period.StartDate, period.EndDate)); if (paymentDate.isBefore(provider.ValuationDate)) { builder.put(ExplainKey.COMPLETED, true); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency)); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency)); } else { builder.put(ExplainKey.DISCOUNT_FACTOR, provider.discountFactor(currency, paymentDate)); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(period, provider))); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.of(currency, presentValue(period, provider))); } }
/// <summary> /// Calculates the present value of the fixed coupon bond trade with z-spread from the /// clean price of the underlying product. /// <para> /// The present value of the trade is the value on the valuation date. /// The result is expressed using the payment currency of the bond. /// </para> /// <para> /// The z-spread is a parallel shift applied to continuously compounded rates or periodic /// compounded rates of the discounting curve. /// </para> /// <para> /// Coupon payments of the underlying product are considered based on the settlement date of the trade. /// /// </para> /// </summary> /// <param name="trade"> the trade </param> /// <param name="provider"> the discounting provider </param> /// <param name="refData"> the reference data used to calculate the settlement date </param> /// <param name="cleanPrice"> the clean price </param> /// <param name="zSpread"> the z-spread </param> /// <param name="compoundedRateType"> the compounded rate type </param> /// <param name="periodsPerYear"> the number of periods per year </param> /// <returns> the present value of the fixed coupon bond trade </returns> public virtual CurrencyAmount presentValueFromCleanPriceWithZSpread(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, ReferenceData refData, double cleanPrice, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { ResolvedFixedCouponBond product = trade.Product; LocalDate standardSettlementDate = this.standardSettlementDate(product, provider, refData); LocalDate tradeSettlementDate = settlementDate(trade, provider.ValuationDate); Currency currency = product.Currency; RepoCurveDiscountFactors repoDf = DiscountingFixedCouponBondProductPricer.repoCurveDf(product, provider); double df = repoDf.discountFactor(standardSettlementDate); double pvStandard = (cleanPrice * product.Notional + productPricer.accruedInterest(product, standardSettlementDate)) * df; if (standardSettlementDate.isEqual(tradeSettlementDate)) { return(presentValueFromProductPresentValue(trade, provider, CurrencyAmount.of(currency, pvStandard))); } // check coupon payment between two settlement dates IssuerCurveDiscountFactors issuerDf = DiscountingFixedCouponBondProductPricer.issuerCurveDf(product, provider); double pvDiff = 0d; if (standardSettlementDate.isAfter(tradeSettlementDate)) { pvDiff = productPricer.presentValueCouponWithZSpread(product, issuerDf, tradeSettlementDate, standardSettlementDate, zSpread, compoundedRateType, periodsPerYear); } else { pvDiff = -productPricer.presentValueCouponWithZSpread(product, issuerDf, standardSettlementDate, tradeSettlementDate, zSpread, compoundedRateType, periodsPerYear); } return(presentValueFromProductPresentValue(trade, provider, CurrencyAmount.of(currency, pvStandard + pvDiff))); }
public virtual void test_parSpread_ended() { ResolvedFxSwap product = ResolvedFxSwap.ofForwardPoints(CurrencyAmount.of(USD, NOMINAL_USD), KRW, FX_RATE, FX_FWD_POINTS, PAYMENT_DATE_LONG_PAST, PAYMENT_DATE_PAST); double parSpread = PRICER.parSpread(product, PROVIDER); assertEquals(parSpread, 0d, TOL); }
public virtual void test_presentValueSensitivity_ended() { ResolvedFxSwap product = ResolvedFxSwap.ofForwardPoints(CurrencyAmount.of(USD, NOMINAL_USD), KRW, FX_RATE, FX_FWD_POINTS, PAYMENT_DATE_LONG_PAST, PAYMENT_DATE_PAST); PointSensitivities computed = PRICER.presentValueSensitivity(product, PROVIDER); assertEquals(computed, PointSensitivities.empty()); }
public virtual void test_resolve() { FixedCouponBond @base = sut(); ResolvedFixedCouponBond resolved = @base.resolve(REF_DATA); assertEquals(resolved.LegalEntityId, LEGAL_ENTITY); assertEquals(resolved.SettlementDateOffset, DATE_OFFSET); assertEquals(resolved.YieldConvention, YIELD_CONVENTION); ImmutableList <FixedCouponBondPaymentPeriod> periodicPayments = resolved.PeriodicPayments; int expNum = 20; assertEquals(periodicPayments.size(), expNum); LocalDate unadjustedEnd = END_DATE; Schedule unadjusted = PERIOD_SCHEDULE.createSchedule(REF_DATA).toUnadjusted(); for (int i = 0; i < expNum; ++i) { FixedCouponBondPaymentPeriod payment = periodicPayments.get(expNum - 1 - i); assertEquals(payment.Currency, EUR); assertEquals(payment.Notional, NOTIONAL); assertEquals(payment.FixedRate, FIXED_RATE); assertEquals(payment.UnadjustedEndDate, unadjustedEnd); assertEquals(payment.EndDate, BUSINESS_ADJUST.adjust(unadjustedEnd, REF_DATA)); assertEquals(payment.PaymentDate, payment.EndDate); LocalDate unadjustedStart = unadjustedEnd.minusMonths(6); assertEquals(payment.UnadjustedStartDate, unadjustedStart); assertEquals(payment.StartDate, BUSINESS_ADJUST.adjust(unadjustedStart, REF_DATA)); assertEquals(payment.YearFraction, unadjusted.getPeriod(expNum - 1 - i).yearFraction(DAY_COUNT, unadjusted)); assertEquals(payment.DetachmentDate, EX_COUPON.adjust(payment.PaymentDate, REF_DATA)); unadjustedEnd = unadjustedStart; } Payment expectedPayment = Payment.of(CurrencyAmount.of(EUR, NOTIONAL), BUSINESS_ADJUST.adjust(END_DATE, REF_DATA)); assertEquals(resolved.NominalPayment, expectedPayment); }
//------------------------------------------------------------------------- /// <summary> /// Explains the present value of the FRA product. /// <para> /// This returns explanatory information about the calculation. /// /// </para> /// </summary> /// <param name="fra"> the FRA product for which present value should be computed </param> /// <param name="provider"> the rates provider </param> /// <returns> the explanatory information </returns> public virtual ExplainMap explainPresentValue(ResolvedFra fra, RatesProvider provider) { ExplainMapBuilder builder = ExplainMap.builder(); Currency currency = fra.Currency; builder.put(ExplainKey.ENTRY_TYPE, "FRA"); builder.put(ExplainKey.PAYMENT_DATE, fra.PaymentDate); builder.put(ExplainKey.START_DATE, fra.StartDate); builder.put(ExplainKey.END_DATE, fra.EndDate); builder.put(ExplainKey.ACCRUAL_YEAR_FRACTION, fra.YearFraction); builder.put(ExplainKey.DAYS, (int)DAYS.between(fra.StartDate, fra.EndDate)); builder.put(ExplainKey.PAYMENT_CURRENCY, currency); builder.put(ExplainKey.NOTIONAL, CurrencyAmount.of(currency, fra.Notional)); builder.put(ExplainKey.TRADE_NOTIONAL, CurrencyAmount.of(currency, fra.Notional)); if (fra.PaymentDate.isBefore(provider.ValuationDate)) { builder.put(ExplainKey.COMPLETED, true); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency)); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency)); } else { double rate = rateComputationFn.explainRate(fra.FloatingRate, fra.StartDate, fra.EndDate, provider, builder); builder.put(ExplainKey.FIXED_RATE, fra.FixedRate); builder.put(ExplainKey.DISCOUNT_FACTOR, provider.discountFactor(currency, fra.PaymentDate)); builder.put(ExplainKey.PAY_OFF_RATE, rate); builder.put(ExplainKey.UNIT_AMOUNT, unitAmount(fra, provider)); builder.put(ExplainKey.FORECAST_VALUE, forecastValue(fra, provider)); builder.put(ExplainKey.PRESENT_VALUE, presentValue(fra, provider)); } return(builder.build()); }
/// <summary> /// Explains the present value of a single payment period with z-spread. /// <para> /// This adds information to the <seealso cref="ExplainMapBuilder"/> to aid understanding of the calculation. /// /// </para> /// </summary> /// <param name="period"> the period to price </param> /// <param name="ratesProvider"> the rates provider, used to determine price index values </param> /// <param name="issuerDiscountFactors"> the discount factor provider </param> /// <param name="zSpread"> the z-spread </param> /// <param name="compoundedRateType"> the compounded rate type </param> /// <param name="periodsPerYear"> the number of periods per year </param> /// <param name="builder"> the builder to populate </param> public virtual void explainPresentValueWithZSpread(CapitalIndexedBondPaymentPeriod period, RatesProvider ratesProvider, IssuerCurveDiscountFactors issuerDiscountFactors, ExplainMapBuilder builder, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { Currency currency = period.Currency; LocalDate paymentDate = period.PaymentDate; builder.put(ExplainKey.ENTRY_TYPE, "CapitalIndexedBondPaymentPeriod"); builder.put(ExplainKey.PAYMENT_DATE, paymentDate); builder.put(ExplainKey.PAYMENT_CURRENCY, currency); builder.put(ExplainKey.START_DATE, period.StartDate); builder.put(ExplainKey.UNADJUSTED_START_DATE, period.UnadjustedStartDate); builder.put(ExplainKey.END_DATE, period.EndDate); builder.put(ExplainKey.UNADJUSTED_END_DATE, period.UnadjustedEndDate); builder.put(ExplainKey.DAYS, (int)DAYS.between(period.UnadjustedStartDate, period.UnadjustedEndDate)); if (paymentDate.isBefore(ratesProvider.ValuationDate)) { builder.put(ExplainKey.COMPLETED, true); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency)); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency)); } else { builder.put(ExplainKey.DISCOUNT_FACTOR, issuerDiscountFactors.discountFactor(paymentDate)); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(period, ratesProvider))); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.of(currency, presentValueWithZSpread(period, ratesProvider, issuerDiscountFactors, zSpread, compoundedRateType, periodsPerYear))); } }
//------------------------------------------------------------------------- public virtual void explainPresentValue(FxResetNotionalExchange @event, RatesProvider provider, ExplainMapBuilder builder) { Currency currency = @event.Currency; LocalDate paymentDate = @event.PaymentDate; builder.put(ExplainKey.ENTRY_TYPE, "FxResetNotionalExchange"); builder.put(ExplainKey.PAYMENT_DATE, paymentDate); builder.put(ExplainKey.PAYMENT_CURRENCY, currency); builder.put(ExplainKey.TRADE_NOTIONAL, @event.NotionalAmount); if (paymentDate.isBefore(provider.ValuationDate)) { builder.put(ExplainKey.COMPLETED, true); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency)); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency)); } else { builder.addListEntry(ExplainKey.OBSERVATIONS, child => { child.put(ExplainKey.ENTRY_TYPE, "FxObservation"); child.put(ExplainKey.INDEX, @event.Observation.Index); child.put(ExplainKey.FIXING_DATE, @event.Observation.FixingDate); child.put(ExplainKey.INDEX_VALUE, fxRate(@event, provider)); }); builder.put(ExplainKey.DISCOUNT_FACTOR, provider.discountFactor(currency, paymentDate)); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(@event, provider))); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.of(currency, presentValue(@event, provider))); } }
//------------------------------------------------------------------------- public virtual void test_presentValueSensitivity() { for (int i = 0; i < NB_STRIKES; ++i) { ResolvedFxVanillaOption option = CALLS[i]; PointSensitivityBuilder point = PRICER.presentValueSensitivityRatesStickyStrike(option, RATES_PROVIDER, VOLS); CurrencyParameterSensitivities sensiComputed = RATES_PROVIDER.parameterSensitivity(point.build()); double timeToExpiry = VOLS.relativeTime(EXPIRY); double forwardRate = FX_PRICER.forwardFxRate(UNDERLYING[i], RATES_PROVIDER).fxRate(CURRENCY_PAIR); double strikeRate = option.Strike; SmileDeltaParameters smileAtTime = VOLS.Smile.smileForExpiry(timeToExpiry); double[] vols = smileAtTime.Volatility.toArray(); double df = RATES_PROVIDER.discountFactor(USD, PAY); CurrencyParameterSensitivities sensiExpected = FD_CAL.sensitivity(RATES_PROVIDER, p => PRICER.presentValue(option, p, VOLS)); CurrencyParameterSensitivities sensiRes = FD_CAL.sensitivity(RATES_PROVIDER, (ImmutableRatesProvider p) => { double fwd = FX_PRICER.forwardFxRate(option.Underlying, p).fxRate(CURRENCY_PAIR); double[] strs = smileAtTime.strike(fwd).toArray(); double[] wghts = weights(fwd, strikeRate, strs, timeToExpiry, vols[1]); double res = 0d; for (int j = 0; j < 3; ++j) { res += wghts[j] * (BlackFormulaRepository.price(forwardRate, strs[j], timeToExpiry, vols[j], true) - BlackFormulaRepository.price(forwardRate, strs[j], timeToExpiry, vols[1], true)); } return(CurrencyAmount.of(USD, -res * df * NOTIONAL)); }); assertTrue(sensiComputed.equalWithTolerance(sensiExpected.combinedWith(sensiRes), FD_EPS * NOTIONAL * 10d)); } }
public virtual void test_parSpread_ended() { ResolvedFxSingle fwd = ResolvedFxSingle.of(CurrencyAmount.of(USD, NOMINAL_USD), FxRate.of(USD, KRW, FX_RATE), PAYMENT_DATE_PAST); double spread = PRICER.parSpread(fwd, PROVIDER); assertEquals(spread, 0d, TOL); }
//------------------------------------------------------------------------- public virtual void test_parSpread_beforeStart() { double parSpread = PRICER.parSpread(SWAP_PRODUCT, PROVIDER); ResolvedFxSwap product = ResolvedFxSwap.ofForwardPoints(CurrencyAmount.of(USD, NOMINAL_USD), KRW, FX_RATE, FX_FWD_POINTS + parSpread, PAYMENT_DATE_NEAR, PAYMENT_DATE_FAR); MultiCurrencyAmount pv = PRICER.presentValue(product, PROVIDER); assertEquals(pv.convertedTo(USD, PROVIDER).Amount, 0d, NOMINAL_USD * TOL); }
public virtual void test_parSpreadSensitivity_ended() { ResolvedFxSwap product = ResolvedFxSwap.ofForwardPoints(CurrencyAmount.of(USD, NOMINAL_USD), KRW, FX_RATE, FX_FWD_POINTS, PAYMENT_DATE_LONG_PAST, PAYMENT_DATE_PAST); PointSensitivities pts = PRICER.parSpreadSensitivity(product, PROVIDER); CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(pts); assertTrue(computed.equalWithTolerance(CurrencyParameterSensitivities.empty(), TOLERANCE_SPREAD_DELTA)); }
public virtual void test_parSpread() { double spread = PRICER.parSpread(FWD, PROVIDER); ResolvedFxSingle fwdSp = ResolvedFxSingle.of(CurrencyAmount.of(USD, NOMINAL_USD), FxRate.of(USD, KRW, FX_RATE + spread), PAYMENT_DATE); MultiCurrencyAmount pv = PRICER.presentValue(fwdSp, PROVIDER); assertEquals(pv.convertedTo(USD, PROVIDER).Amount, 0d, NOMINAL_USD * TOL); }
internal virtual CurrencyAmount forecastValueStandardFromCleanPrice(ResolvedCapitalIndexedBond product, RatesProvider ratesProvider, LocalDate standardSettlementDate, double realCleanPrice) { double notional = product.Notional; double netAmountReal = realCleanPrice * notional + product.accruedInterest(standardSettlementDate); double indexRatio = product.YieldConvention.Equals(CapitalIndexedBondYieldConvention.GB_IL_FLOAT) ? 1d : productPricer.indexRatio(product, ratesProvider, standardSettlementDate); return(CurrencyAmount.of(product.Currency, indexRatio * netAmountReal)); }
//------------------------------------------------------------------------- public virtual void test_adjustPaymentDate() { FxResetNotionalExchange test = FxResetNotionalExchange.of(CurrencyAmount.of(USD, 1000d), DATE_2014_06_30, FxIndexObservation.of(GBP_USD_WM, DATE_2014_03_28, REF_DATA)); FxResetNotionalExchange expected = FxResetNotionalExchange.of(CurrencyAmount.of(USD, 1000d), DATE_2014_06_30.plusDays(2), FxIndexObservation.of(GBP_USD_WM, DATE_2014_03_28, REF_DATA)); assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(0))), test); assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d => d.plusDays(2))), expected); }
//------------------------------------------------------------------------- /// <summary> /// Calculates the present value of the FRA product. /// <para> /// The present value of the product is the value on the valuation date. /// This is the discounted forecast value. /// /// </para> /// </summary> /// <param name="fra"> the product </param> /// <param name="provider"> the rates provider </param> /// <returns> the present value of the product </returns> public virtual CurrencyAmount presentValue(ResolvedFra fra, RatesProvider provider) { // forecastValue * discountFactor double df = provider.discountFactor(fra.Currency, fra.PaymentDate); double pv = forecastValue0(fra, provider) * df; return(CurrencyAmount.of(fra.Currency, pv)); }
public virtual void test_ofCurrencyMinorUnit_GBP() { SecurityPriceInfo test = SecurityPriceInfo.ofCurrencyMinorUnit(GBP); assertEquals(test.TickSize, 0.01); assertEquals(test.TickValue, CurrencyAmount.of(GBP, 0.01)); assertEquals(test.ContractSize, 1d); assertEquals(test.Currency, GBP); }
public virtual void test_currentCash_onPaymentDate() { LocalDate paymentDate = RFRA.PaymentDate; double publishedRate = 0.025; ResolvedFraTrade trade = FraTrade.builder().info(TradeInfo.builder().tradeDate(paymentDate).build()).product(FRA).build().resolve(REF_DATA); ImmutableRatesProvider ratesProvider = RatesProviderDataSets.multiGbp(paymentDate).toBuilder().timeSeries(GBP_LIBOR_3M, LocalDateDoubleTimeSeries.of(paymentDate, publishedRate)).build(); assertEquals(PRICER_TRADE.currentCash(trade, ratesProvider), CurrencyAmount.of(FRA.Currency, (publishedRate - FRA.FixedRate) / (1d + publishedRate * RFRA.YearFraction) * RFRA.YearFraction * RFRA.Notional)); }
//------------------------------------------------------------------------- public virtual void coverage() { NotionalExchange test = NotionalExchange.of(GBP_1000, DATE_2014_06_30); coverImmutableBean(test); NotionalExchange test2 = NotionalExchange.of(CurrencyAmount.of(GBP, 200d), date(2014, 1, 15)); coverBeanEquals(test, test2); }
//------------------------------------------------------------------------- public virtual void coverage() { FxResetNotionalExchange test = FxResetNotionalExchange.of(CurrencyAmount.of(USD, 1000d), DATE_2014_03_28, FxIndexObservation.of(GBP_USD_WM, DATE_2014_03_28, REF_DATA)); coverImmutableBean(test); FxResetNotionalExchange test2 = FxResetNotionalExchange.of(CurrencyAmount.of(EUR, 2000d), DATE_2014_06_30, FxIndexObservation.of(EUR_USD_ECB, DATE_2014_06_30, REF_DATA)); coverBeanEquals(test, test2); }
public virtual void test_of() { FxResetNotionalExchange test = FxResetNotionalExchange.of(CurrencyAmount.of(USD, 1000d), DATE_2014_06_30, FxIndexObservation.of(GBP_USD_WM, DATE_2014_03_28, REF_DATA)); assertEquals(test.PaymentDate, DATE_2014_06_30); assertEquals(test.ReferenceCurrency, USD); assertEquals(test.NotionalAmount, CurrencyAmount.of(USD, 1000d)); assertEquals(test.Notional, 1000d, 0d); }
public virtual void test_of_fail() { CurrencyAmount negative = CurrencyAmount.of(USD, -5.0e4); assertThrowsIllegalArg(() => FxSingleBarrierOption.of(VANILLA_OPTION, BARRIER, negative)); CurrencyAmount other = CurrencyAmount.of(GBP, 5.0e4); assertThrowsIllegalArg(() => FxSingleBarrierOption.of(VANILLA_OPTION, BARRIER, other)); }
//------------------------------------------------------------------------- public virtual void coverage() { SwapLegAmount la1 = SwapLegAmount.builder().amount(CURRENCY_AMOUNT).payReceive(PayReceive.PAY).type(SwapLegType.FIXED).currency(Currency.EUR).build(); coverImmutableBean(la1); SwapLegAmount la2 = SwapLegAmount.builder().amount(CurrencyAmount.of(Currency.GBP, 10000)).payReceive(PayReceive.RECEIVE).type(SwapLegType.IBOR).currency(Currency.GBP).build(); coverBeanEquals(la1, la2); }
//------------------------------------------------------------------------- /// <summary> /// Calculates the present value of the Ibor future trade from the current price. /// <para> /// The present value of the product is the value on the valuation date. /// </para> /// <para> /// The calculation is performed against a reference price. The reference price /// must be the last settlement price used for margining, except on the trade date, /// when it must be the trade price. /// /// </para> /// </summary> /// <param name="trade"> the trade </param> /// <param name="currentPrice"> the current price, in decimal form </param> /// <param name="referencePrice"> the reference price to margin against, typically the last settlement price, in decimal form </param> /// <returns> the present value </returns> internal virtual CurrencyAmount presentValue(ResolvedIborFutureTrade trade, double currentPrice, double referencePrice) { ResolvedIborFuture future = trade.Product; double priceIndex = productPricer.marginIndex(future, currentPrice); double referenceIndex = productPricer.marginIndex(future, referencePrice); double pv = (priceIndex - referenceIndex) * trade.Quantity; return(CurrencyAmount.of(future.Currency, pv)); }
//------------------------------------------------------------------------- public virtual void test_currencyExposure() { ImmutableRatesProvider prov = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(GBP, DISCOUNT_CURVE_GBP).build(); MultiCurrencyAmount computed = PRICER.currencyExposure(PERIOD, prov); PointSensitivities point = PRICER.presentValueSensitivity(PERIOD, prov).build(); MultiCurrencyAmount expected = prov.currencyExposure(point).plus(CurrencyAmount.of(GBP, PRICER.presentValue(PERIOD, prov))); assertEquals(computed, expected); }
public virtual void test_currentCash_onPayment() { double rate = 1111.2; LocalDate paymentDate = NDF.PaymentDate; RatesProvider provider = RatesProviderFxDataSets.createProvider(paymentDate, NDF.Index, rate); CurrencyAmount computed = PRICER.currentCash(NDF, provider); assertEquals(computed, CurrencyAmount.of(NDF.SettlementCurrency, NOMINAL_USD * (1d - FX_RATE / rate))); }
public virtual void test_parSpreadSensitivity_started() { ResolvedFxSwap product = ResolvedFxSwap.ofForwardPoints(CurrencyAmount.of(USD, NOMINAL_USD), KRW, FX_RATE, FX_FWD_POINTS, PAYMENT_DATE_PAST, PAYMENT_DATE_NEAR); PointSensitivities pts = PRICER.parSpreadSensitivity(product, PROVIDER); CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(pts); CurrencyParameterSensitivities expected = CAL_FD.sensitivity(PROVIDER, (p) => CurrencyAmount.of(KRW, PRICER.parSpread(product, p))); assertTrue(computed.equalWithTolerance(expected, TOLERANCE_SPREAD_DELTA)); }
public virtual void test_ofCurrencyMinorUnit_JPY() { SecurityPriceInfo test = SecurityPriceInfo.ofCurrencyMinorUnit(JPY); assertEquals(test.TickSize, 1d); assertEquals(test.TickValue, CurrencyAmount.of(JPY, 1)); assertEquals(test.ContractSize, 1d); assertEquals(test.Currency, JPY); }