コード例 #1
0
        /// <summary>
        /// Calculates the present value sensitivity of the FX swap product.
        /// <para>
        /// The present value sensitivity of the product is the sensitivity of the present value to
        /// the underlying curves.
        ///
        /// </para>
        /// </summary>
        /// <param name="swap">  the product </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the present value sensitivity </returns>
        public virtual PointSensitivities presentValueSensitivity(ResolvedFxSwap swap, RatesProvider provider)
        {
            PointSensitivities nearSens = fxPricer.presentValueSensitivity(swap.NearLeg, provider);
            PointSensitivities farSens  = fxPricer.presentValueSensitivity(swap.FarLeg, provider);

            return(nearSens.combinedWith(farSens));
        }
        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_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);
        }
コード例 #4
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));
        }
コード例 #5
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));
        }
        //-------------------------------------------------------------------------
        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_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_presentValueSensitivity_started()
        {
            ResolvedFxSwap                 product     = ResolvedFxSwap.ofForwardPoints(CurrencyAmount.of(USD, NOMINAL_USD), KRW, FX_RATE, FX_FWD_POINTS, PAYMENT_DATE_PAST, PAYMENT_DATE_NEAR);
            PointSensitivities             point       = PRICER.presentValueSensitivity(product, PROVIDER);
            CurrencyParameterSensitivities computed    = PROVIDER.parameterSensitivity(point);
            CurrencyParameterSensitivities expectedUsd = CAL_FD.sensitivity(PROVIDER, (p) => PRICER.presentValue(product, (p)).getAmount(USD));
            CurrencyParameterSensitivities expectedKrw = CAL_FD.sensitivity(PROVIDER, (p) => PRICER.presentValue(product, (p)).getAmount(KRW));

            assertTrue(computed.equalWithTolerance(expectedUsd.combinedWith(expectedKrw), NOMINAL_USD * FX_RATE * EPS_FD));
        }
コード例 #10
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the par spread.
        /// <para>
        /// The par spread is the spread that should be added to the FX forward points to have a zero value.
        ///
        /// </para>
        /// </summary>
        /// <param name="swap">  the product </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the spread </returns>
        public virtual double parSpread(ResolvedFxSwap swap, RatesProvider provider)
        {
            Payment             counterPaymentNear = swap.NearLeg.CounterCurrencyPayment;
            MultiCurrencyAmount pv = presentValue(swap, provider);
            double pvCounterCcy    = pv.convertedTo(counterPaymentNear.Currency, provider).Amount;
            double dfEnd           = provider.discountFactor(counterPaymentNear.Currency, swap.FarLeg.PaymentDate);
            double notionalBaseCcy = swap.NearLeg.BaseCurrencyPayment.Amount;

            return(-pvCounterCcy / (notionalBaseCcy * dfEnd));
        }
        public virtual void test_presentValue_ended()
        {
            ResolvedFxSwap      product  = ResolvedFxSwap.ofForwardPoints(CurrencyAmount.of(USD, NOMINAL_USD), KRW, FX_RATE, FX_FWD_POINTS, PAYMENT_DATE_LONG_PAST, PAYMENT_DATE_PAST);
            MultiCurrencyAmount computed = PRICER.presentValue(product, PROVIDER);

            assertEquals(computed, MultiCurrencyAmount.empty());

            // currency exposure
            MultiCurrencyAmount exposure = PRICER.currencyExposure(product, PROVIDER);

            assertEquals(exposure, computed);
        }
        public virtual void test_presentValue_started()
        {
            ResolvedFxSwap      product  = ResolvedFxSwap.ofForwardPoints(CurrencyAmount.of(USD, NOMINAL_USD), KRW, FX_RATE, FX_FWD_POINTS, PAYMENT_DATE_PAST, PAYMENT_DATE_NEAR);
            MultiCurrencyAmount computed = PRICER.presentValue(product, PROVIDER);
            double expected_usd          = -NOMINAL_USD *PROVIDER.discountFactor(USD, PAYMENT_DATE_NEAR);

            double expected_krw = NOMINAL_USD * (FX_RATE + FX_FWD_POINTS) * PROVIDER.discountFactor(KRW, PAYMENT_DATE_NEAR);

            assertEquals(computed.getAmount(USD).Amount, expected_usd, NOMINAL_USD * TOL);
            assertEquals(computed.getAmount(KRW).Amount, expected_krw, NOMINAL_USD * FX_RATE * TOL);

            // currency exposure
            MultiCurrencyAmount exposure = PRICER.currencyExposure(product, PROVIDER);

            assertEquals(exposure, computed);
        }
コード例 #13
0
        /// <summary>
        /// Calculates the par spread sensitivity to the curves.
        /// <para>
        /// The sensitivity is reported in the counter currency of the product, but is actually dimensionless.
        ///
        /// </para>
        /// </summary>
        /// <param name="swap">  the product </param>
        /// <param name="provider">  the rates provider </param>
        /// <returns> the spread curve sensitivity </returns>
        public virtual PointSensitivities parSpreadSensitivity(ResolvedFxSwap swap, RatesProvider provider)
        {
            Payment             counterPaymentNear = swap.NearLeg.CounterCurrencyPayment;
            MultiCurrencyAmount pv = presentValue(swap, provider);
            double pvCounterCcy    = pv.convertedTo(counterPaymentNear.Currency, provider).Amount;
            double dfEnd           = provider.discountFactor(counterPaymentNear.Currency, swap.FarLeg.PaymentDate);
            double notionalBaseCcy = swap.NearLeg.BaseCurrencyPayment.Amount;
            double ps = -pvCounterCcy / (notionalBaseCcy * dfEnd);
            // backward sweep
            double psBar                       = 1d;
            double pvCounterCcyBar             = -1d / (notionalBaseCcy * dfEnd) * psBar;
            double dfEndBar                    = -ps / dfEnd * psBar;
            ZeroRateSensitivity ddfEnddr       = provider.discountFactors(counterPaymentNear.Currency).zeroRatePointSensitivity(swap.FarLeg.PaymentDate);
            PointSensitivities  result         = ddfEnddr.multipliedBy(dfEndBar).build();
            PointSensitivities  dpvdr          = presentValueSensitivity(swap, provider);
            PointSensitivities  dpvdrConverted = dpvdr.convertedTo(counterPaymentNear.Currency, provider);

            return(result.combinedWith(dpvdrConverted.multipliedBy(pvCounterCcyBar)));
        }
コード例 #14
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Calculates the currency exposure of the FX swap product.
 /// <para>
 /// This discounts each payment on each leg in its own currency.
 ///
 /// </para>
 /// </summary>
 /// <param name="product">  the product </param>
 /// <param name="provider">  the rates provider </param>
 /// <returns> the currency exposure </returns>
 public virtual MultiCurrencyAmount currencyExposure(ResolvedFxSwap product, RatesProvider provider)
 {
     return(presentValue(product, provider));
 }