Ejemplo n.º 1
0
        //-------------------------------------------------------------------------
        public virtual void test_presentValue()
        {
            CurrencyAmount computedRec = PRICER.presentValue(SWAPTION_REC_LONG, RATE_PROVIDER, HW_PROVIDER);
            CurrencyAmount computedPay = PRICER.presentValue(SWAPTION_PAY_SHORT, RATE_PROVIDER, HW_PROVIDER);
            SwapPaymentEventPricer <SwapPaymentEvent> paymentEventPricer = SwapPaymentEventPricer.standard();
            ResolvedSwapLeg cashFlowEquiv = CashFlowEquivalentCalculator.cashFlowEquivalentSwap(RSWAP_REC, RATE_PROVIDER);
            LocalDate       expiryDate    = MATURITY.toLocalDate();
            int             nPayments     = cashFlowEquiv.PaymentEvents.size();

            double[] alpha = new double[nPayments];
            double[] discountedCashFlow = new double[nPayments];
            for (int loopcf = 0; loopcf < nPayments; loopcf++)
            {
                SwapPaymentEvent payment = cashFlowEquiv.PaymentEvents.get(loopcf);
                alpha[loopcf] = HW_PROVIDER.alpha(RATE_PROVIDER.ValuationDate, expiryDate, expiryDate, payment.PaymentDate);
                discountedCashFlow[loopcf] = paymentEventPricer.presentValue(payment, RATE_PROVIDER);
            }
            double omegaPay    = -1d;
            double kappa       = HW_PROVIDER.Model.kappa(DoubleArray.copyOf(discountedCashFlow), DoubleArray.copyOf(alpha));
            double expectedRec = 0.0;
            double expectedPay = 0.0;

            for (int loopcf = 0; loopcf < nPayments; loopcf++)
            {
                expectedRec += discountedCashFlow[loopcf] * NORMAL.getCDF((kappa + alpha[loopcf]));
                expectedPay += discountedCashFlow[loopcf] * NORMAL.getCDF(omegaPay * (kappa + alpha[loopcf]));
            }
            assertEquals(computedRec.Currency, EUR);
            assertEquals(computedRec.Amount, expectedRec, NOTIONAL * TOL);
            assertEquals(computedPay.Currency, EUR);
            assertEquals(computedPay.Amount, expectedPay, NOTIONAL * TOL);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates an instance.
 /// </summary>
 /// <param name="paymentPeriodPricer">  the pricer for <seealso cref="SwapPaymentPeriod"/> </param>
 /// <param name="paymentEventPricer">  the pricer for <seealso cref="SwapPaymentEvent"/> </param>
 public DiscountingSwapLegPricer(SwapPaymentPeriodPricer <SwapPaymentPeriod> paymentPeriodPricer, SwapPaymentEventPricer <SwapPaymentEvent> paymentEventPricer)
 {
     this.paymentPeriodPricer = ArgChecker.notNull(paymentPeriodPricer, "paymentPeriodPricer");
     this.paymentEventPricer  = ArgChecker.notNull(paymentEventPricer, "paymentEventPricer");
 }