public virtual void test_currencyExposureWithZSpread()
        {
            MultiCurrencyAmount ceComputed = TRADE_PRICER.currencyExposureWithZSpread(FUTURE_TRADE, PROVIDER, SETTLE_PRICE, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR);
            CurrencyAmount      pv         = TRADE_PRICER.presentValueWithZSpread(FUTURE_TRADE, PROVIDER, SETTLE_PRICE, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR);

            assertEquals(ceComputed, MultiCurrencyAmount.of(pv));
        }
        //-------------------------------------------------------------------------
        public virtual void test_currencyExposure()
        {
            MultiCurrencyAmount ceComputed = TRADE_PRICER.currencyExposure(FUTURE_TRADE, PROVIDER, SETTLE_PRICE);
            CurrencyAmount      pv         = TRADE_PRICER.presentValue(FUTURE_TRADE, PROVIDER, SETTLE_PRICE);

            assertEquals(ceComputed, MultiCurrencyAmount.of(pv));
        }
        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());
        }
예제 #4
0
        /// <summary>
        /// Calculates the current cash of the FX swap product.
        /// </summary>
        /// <param name="swap">  the product </param>
        /// <param name="valuationDate">  the valuation date </param>
        /// <returns> the current cash </returns>
        public virtual MultiCurrencyAmount currentCash(ResolvedFxSwap swap, LocalDate valuationDate)
        {
            MultiCurrencyAmount farPv  = fxPricer.currentCash(swap.FarLeg, valuationDate);
            MultiCurrencyAmount nearPv = fxPricer.currentCash(swap.NearLeg, valuationDate);

            return(nearPv.plus(farPv));
        }
예제 #5
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the FX swap product.
        /// <para>
        /// This discounts each payment on each leg in its own currency.
        ///
        /// </para>
        /// </summary>
        /// <param name="swap">  the product </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the present value in the two natural currencies </returns>
        public virtual MultiCurrencyAmount presentValue(ResolvedFxSwap swap, RatesProvider provider)
        {
            MultiCurrencyAmount farPv  = fxPricer.presentValue(swap.FarLeg, provider);
            MultiCurrencyAmount nearPv = fxPricer.presentValue(swap.NearLeg, provider);

            return(nearPv.plus(farPv));
        }
        //-------------------------------------------------------------------------
        public virtual void test_currencyExposure()
        {
            MultiCurrencyAmount computed = PRICER.currencyExposure(FWD, PROVIDER);
            MultiCurrencyAmount expected = PRICER.presentValue(FWD, PROVIDER);

            assertEquals(computed, expected);
        }
        public virtual void test_currencyExposure_ended()
        {
            ResolvedFxNdf       ndf      = ResolvedFxNdf.builder().settlementCurrencyNotional(CURRENCY_NOTIONAL).agreedFxRate(FxRate.of(USD, KRW, FX_RATE)).observation(FxIndexObservation.of(INDEX, LocalDate.of(2011, 5, 2), REF_DATA)).paymentDate(LocalDate.of(2011, 5, 4)).build();
            MultiCurrencyAmount computed = PRICER.currencyExposure(ndf, PROVIDER);

            assertEquals(computed.size(), 0);
        }
예제 #8
0
        //-------------------------------------------------------------------------
        public virtual void currency_exposure_premium_forward()
        {
            CurrencyAmount      pv = PRICER_TRADE.presentValue(SWAPTION_PREFWD_LONG_REC, MULTI_USD, NORMAL_VOLS_USD);
            MultiCurrencyAmount ce = PRICER_TRADE.currencyExposure(SWAPTION_PREFWD_LONG_REC, MULTI_USD, NORMAL_VOLS_USD);

            assertEquals(pv.Amount, ce.getAmount(USD).Amount, TOLERANCE_PV);
        }
        /// <summary>
        /// Calculates the currency exposure of the bond future trade with z-spread.
        /// <para>
        /// The z-spread is a parallel shift applied to continuously compounded rates or periodic compounded rates
        /// of the issuer discounting curve.
        /// </para>
        /// <para>
        /// This method calculates based on the difference between the model price and the
        /// last settlement price, or the trade price if traded on the valuation date.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="discountingProvider">  the discounting provider </param>
        /// <param name="lastSettlementPrice">  the last settlement price used for margining, in decimal form </param>
        /// <param name="zSpread">  the z-spread </param>
        /// <param name="compoundedRateType">  the compounded rate type </param>
        /// <param name="periodPerYear">  the number of periods per year </param>
        /// <returns> the currency exposure of the bond future trade </returns>
        public MultiCurrencyAmount currencyExposureWithZSpread(ResolvedBondFutureTrade trade, LegalEntityDiscountingProvider discountingProvider, double lastSettlementPrice, double zSpread, CompoundedRateType compoundedRateType, int periodPerYear)
        {
            double price          = priceWithZSpread(trade, discountingProvider, zSpread, compoundedRateType, periodPerYear);
            double referencePrice = this.referencePrice(trade, discountingProvider.ValuationDate, lastSettlementPrice);

            return(MultiCurrencyAmount.of(presentValue(trade, price, referencePrice)));
        }
예제 #10
0
        //-------------------------------------------------------------------------
        public virtual void currency_exposure_premium_forward()
        {
            CurrencyAmount      pv = PRICER_TRADE.presentValue(SWAPTION_PREFWD_LONG_REC, RATE_PROVIDER, VOLS);
            MultiCurrencyAmount ce = PRICER_TRADE.currencyExposure(SWAPTION_PREFWD_LONG_REC, RATE_PROVIDER, VOLS);

            assertEquals(pv.Amount, ce.getAmount(USD).Amount, NOTIONAL * TOL);
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the currency exposure of the bond future trade.
        /// <para>
        /// This method calculates based on the difference between the model price and the
        /// last settlement price, or the trade price if traded on the valuation date.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the trade </param>
        /// <param name="discountingProvider">  the discounting provider </param>
        /// <param name="lastSettlementPrice">  the last settlement price used for margining, in decimal form </param>
        /// <returns> the currency exposure of the bond future trade </returns>
        public MultiCurrencyAmount currencyExposure(ResolvedBondFutureTrade trade, LegalEntityDiscountingProvider discountingProvider, double lastSettlementPrice)
        {
            double price          = this.price(trade, discountingProvider);
            double referencePrice = this.referencePrice(trade, discountingProvider.ValuationDate, lastSettlementPrice);

            return(MultiCurrencyAmount.of(presentValue(trade, price, referencePrice)));
        }
        // Checks that the NDF present value is coherent with the standard FX forward present value.
        public virtual void test_presentValueVsForex()
        {
            CurrencyAmount      pvNDF = PRICER.presentValue(NDF, PROVIDER);
            MultiCurrencyAmount pvFX  = PRICER_FX.presentValue(FOREX, PROVIDER);

            assertEquals(pvNDF.Amount, pvFX.getAmount(USD).Amount + pvFX.getAmount(KRW).Amount *FX_MATRIX.fxRate(KRW, USD), NOMINAL_USD * 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);
        }
        // Checks that the NDF currency exposure is coherent with the standard FX forward present value.
        public virtual void test_currencyExposureVsForex()
        {
            MultiCurrencyAmount pvNDF = PRICER.currencyExposure(NDF, PROVIDER);
            MultiCurrencyAmount pvFX  = PRICER_FX.currencyExposure(FOREX, PROVIDER);

            assertEquals(pvNDF.getAmount(USD).Amount, pvFX.getAmount(USD).Amount, NOMINAL_USD * TOL);
            assertEquals(pvNDF.getAmount(KRW).Amount, pvFX.getAmount(KRW).Amount, NOMINAL_USD * TOL * FX_MATRIX.fxRate(USD, KRW));
        }
        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);
        }
        public virtual void test_currentCash()
        {
            MultiCurrencyAmount cc1 = PRODUCT_PRICER.currentCash(CMS_ONE_LEG, RATES_PROVIDER, VOLATILITIES);
            MultiCurrencyAmount cc2 = PRODUCT_PRICER.currentCash(CMS_TWO_LEGS, RATES_PROVIDER, VOLATILITIES);

            assertEquals(cc1, MultiCurrencyAmount.of(CurrencyAmount.zero(EUR)));
            assertEquals(cc2, MultiCurrencyAmount.of(CurrencyAmount.zero(EUR)));
        }
        //-------------------------------------------------------------------------

        public virtual void test_currencyExposure()
        {
            CurrencyAmount      pv          = PRICER.presentValue(NDF, PROVIDER);
            MultiCurrencyAmount ce          = PRICER.currencyExposure(NDF, PROVIDER);
            CurrencyAmount      ceConverted = ce.convertedTo(pv.Currency, PROVIDER);

            assertEquals(pv.Amount, ceConverted.Amount, NOMINAL_USD * TOL);
        }
        public virtual void test_currentCash()
        {
            MultiCurrencyAmount cc1 = TRADE_PRICER.currentCash(CMS_TRADE_PREMIUM, RATES_PROVIDER, VOLATILITIES);
            MultiCurrencyAmount cc2 = TRADE_PRICER.currentCash(CMS_TRADE, RATES_PROVIDER, VOLATILITIES);

            assertEquals(cc1, MultiCurrencyAmount.of(PREMIUM.Value));
            assertEquals(cc2, MultiCurrencyAmount.of(CurrencyAmount.zero(EUR)));
        }
예제 #19
0
 /// <summary>
 /// Calculates the current cash.
 /// </summary>
 /// <param name="fx">  the product </param>
 /// <param name="valuationDate">  the valuation date </param>
 /// <returns> the current cash </returns>
 public virtual MultiCurrencyAmount currentCash(ResolvedFxSingle fx, LocalDate valuationDate)
 {
     if (valuationDate.isEqual(fx.PaymentDate))
     {
         return(MultiCurrencyAmount.of(fx.BaseCurrencyPayment.Value, fx.CounterCurrencyPayment.Value));
     }
     return(MultiCurrencyAmount.empty());
 }
예제 #20
0
        public virtual void test_currentCash()
        {
            MultiCurrencyAmount computedWithPayLeg  = PRICER.currentCash(TRADE_PAYLEG, RATES, VOLS);
            MultiCurrencyAmount computedWithPremium = PRICER.currentCash(TRADE_PREMIUM, RATES, VOLS);

            assertEquals(computedWithPayLeg, MultiCurrencyAmount.of(CurrencyAmount.zero(EUR)));
            assertEquals(computedWithPremium, MultiCurrencyAmount.of(PREMIUM.Value));
        }
        public virtual void test_currentCash()
        {
            MultiCurrencyAmount cc1 = PRICER.currentCash(CAP_ONE_LEG, RATES, VOLS);
            MultiCurrencyAmount cc2 = PRICER.currentCash(CAP_TWO_LEGS, RATES, VOLS);

            assertEquals(cc1, MultiCurrencyAmount.of(CurrencyAmount.zero(EUR)));
            assertEquals(cc2, MultiCurrencyAmount.of(CurrencyAmount.zero(EUR)));
        }
예제 #22
0
        public virtual void test_presentValue()
        {
            MultiCurrencyAmount pvSensiTrade   = PRICER_TRADE.presentValue(OPTION_TRADE, RATES_PROVIDER, VOLS);
            CurrencyAmount      pvSensiProduct = PRICER_PRODUCT.presentValue(OPTION_PRODUCT, RATES_PROVIDER, VOLS);
            CurrencyAmount      pvSensiPremium = PRICER_PAYMENT.presentValue(PREMIUM, RATES_PROVIDER);

            assertEquals(pvSensiTrade, MultiCurrencyAmount.of(pvSensiProduct, pvSensiPremium));
        }
예제 #23
0
        public virtual void test_currencyExposure()
        {
            CurrencyAmount      pv       = TRADE_PRICER.presentValue(FUTURE_TRADE, PROVIDER, LASTMARG_PRICE);
            PointSensitivities  point    = TRADE_PRICER.presentValueSensitivity(FUTURE_TRADE, PROVIDER);
            MultiCurrencyAmount expected = PROVIDER.currencyExposure(point).plus(pv);
            MultiCurrencyAmount computed = TRADE_PRICER.currencyExposure(FUTURE_TRADE, PROVIDER, LASTMARG_PRICE);

            assertEquals(computed, expected);
        }
        public virtual void test_presentValueGamma()
        {
            MultiCurrencyAmount computed1 = PRICER.presentValueGamma(CAP_ONE_LEG, RATES, VOLS);
            MultiCurrencyAmount computed2 = PRICER.presentValueGamma(CAP_TWO_LEGS, RATES, VOLS);
            CurrencyAmount      cap       = PRICER_CAP_LEG.presentValueGamma(CAP_LEG, RATES, VOLS);

            assertEquals(computed1, MultiCurrencyAmount.of(cap));
            assertEquals(computed2, MultiCurrencyAmount.of(cap));
        }
예제 #25
0
        //-------------------------------------------------------------------------
        public virtual void test_currencyExposureFromCleanPrice()
        {
            MultiCurrencyAmount computed = PRICER.currencyExposureFromCleanPrice(TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE);
            PointSensitivities  point    = PRICER.presentValueSensitivityFromCleanPrice(TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE);
            MultiCurrencyAmount expected = RATES_PROVIDER.currencyExposure(point).plus(PRICER.presentValueFromCleanPrice(TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE));

            assertEquals(computed.Amounts.size(), 1);
            assertEquals(computed.getAmount(USD).Amount, expected.getAmount(USD).Amount, NOTIONAL * QUANTITY * TOL);
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the FX barrier option trade.
        /// <para>
        /// The present value of the trade is the value on the valuation date.
        /// </para>
        /// <para>
        /// The trinomial tree is first calibrated to Black volatilities,
        /// then the price is computed based on the calibrated tree.
        ///
        /// </para>
        /// </summary>
        /// <param name="trade">  the option trade </param>
        /// <param name="ratesProvider">  the rates provider </param>
        /// <param name="volatilities">  the Black volatility provider </param>
        /// <returns> the present value of the trade </returns>
        public virtual MultiCurrencyAmount presentValue(ResolvedFxSingleBarrierOptionTrade trade, RatesProvider ratesProvider, BlackFxOptionVolatilities volatilities)
        {
            ResolvedFxSingleBarrierOption product = trade.Product;
            CurrencyAmount pvProduct = productPricer.presentValue(product, ratesProvider, volatilities);
            Payment        premium   = trade.Premium;
            CurrencyAmount pvPremium = paymentPricer.presentValue(premium, ratesProvider);

            return(MultiCurrencyAmount.of(pvProduct, pvPremium));
        }
예제 #27
0
        public virtual void test_currencyExposureWithZSpread()
        {
            MultiCurrencyAmount computed = PRICER.currencyExposureWithZSpread(TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR);
            PointSensitivities  point    = PRICER.presentValueSensitivityWithZSpread(TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR);
            MultiCurrencyAmount expected = RATES_PROVIDER.currencyExposure(point).plus(PRICER.presentValueWithZSpread(TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR));

            assertEquals(computed.Amounts.size(), 1);
            assertEquals(computed.getAmount(USD).Amount, expected.getAmount(USD).Amount, NOTIONAL * QUANTITY * TOL);
        }
예제 #28
0
        public virtual void test_currencyExposure()
        {
            PointSensitivities  point    = PRICER.presentValueSensitivityRates(FUTURE_TRADE, RATE_PROVIDER, HW_PROVIDER);
            MultiCurrencyAmount expected = RATE_PROVIDER.currencyExposure(point).plus(PRICER.presentValue(FUTURE_TRADE, RATE_PROVIDER, HW_PROVIDER, LAST_PRICE));
            MultiCurrencyAmount computed = PRICER.currencyExposure(FUTURE_TRADE, RATE_PROVIDER, HW_PROVIDER, LAST_PRICE);

            assertEquals(computed.size(), 1);
            assertEquals(computed.getAmount(EUR).Amount, expected.getAmount(EUR).Amount, NOTIONAL * QUANTITY * TOL);
        }
예제 #29
0
        public virtual void test_currencyExposure()
        {
            MultiCurrencyAmount ceComputed = PRICER_TRADE.currencyExposure(OPTION_TRADE, RATES_PROVIDER, VOLS);
            MultiCurrencyAmount ceExpected = PRICER_PRODUCT.currencyExposure(OPTION_PRODUCT, RATES_PROVIDER, VOLS).plus(PRICER_PAYMENT.presentValue(PREMIUM, RATES_PROVIDER));

            assertEquals(ceComputed.size(), 2);
            assertEquals(ceComputed.getAmount(EUR).Amount, ceExpected.getAmount(EUR).Amount, TOL * NOTIONAL);
            assertEquals(ceComputed.getAmount(USD).Amount, ceExpected.getAmount(USD).Amount, TOL * NOTIONAL);
        }
        public virtual void test_presentValue()
        {
            MultiCurrencyAmount computed = PRICER.presentValue(FWD, PROVIDER);
            double expected1             = NOMINAL_USD * PROVIDER.discountFactor(USD, PAYMENT_DATE);
            double expected2             = -NOMINAL_USD *FX_RATE *PROVIDER.discountFactor(KRW, PAYMENT_DATE);

            assertEquals(computed.getAmount(USD).Amount, expected1, NOMINAL_USD * TOL);
            assertEquals(computed.getAmount(KRW).Amount, expected2, NOMINAL_USD * TOL);
        }