Example #1
0
        public virtual void test_presentValue_parity()
        {
            CurrencyAmount pvRecLong  = PRICER.presentValue(SWAPTION_REC_LONG, RATE_PROVIDER, VOLS);
            CurrencyAmount pvRecShort = PRICER.presentValue(SWAPTION_REC_SHORT, RATE_PROVIDER, VOLS);
            CurrencyAmount pvPayLong  = PRICER.presentValue(SWAPTION_PAY_LONG, RATE_PROVIDER, VOLS);
            CurrencyAmount pvPayShort = PRICER.presentValue(SWAPTION_PAY_SHORT, RATE_PROVIDER, VOLS);

            assertEquals(pvRecLong.Amount, -pvRecShort.Amount, NOTIONAL * TOL);
            assertEquals(pvPayLong.Amount, -pvPayShort.Amount, NOTIONAL * TOL);
            double forward     = SWAP_PRICER.parRate(RSWAP_REC, RATE_PROVIDER);
            double annuityCash = SWAP_PRICER.LegPricer.annuityCash(RSWAP_REC.getLegs(SwapLegType.FIXED).get(0), forward);
            double discount    = RATE_PROVIDER.discountFactor(EUR, SETTLE);
            double expected    = discount * annuityCash * (forward - RATE);

            assertEquals(pvPayLong.Amount - pvRecLong.Amount, expected, NOTIONAL * TOL);
            assertEquals(pvPayShort.Amount - pvRecShort.Amount, -expected, NOTIONAL * TOL);
        }
        //-------------------------------------------------------------------------
        public virtual void test_presentValue()
        {
            CurrencyAmount        pvRecComputed = PRICER_SWAPTION.presentValue(SWAPTION_REC_LONG, RATE_PROVIDER, VOLS);
            CurrencyAmount        pvPayComputed = PRICER_SWAPTION.presentValue(SWAPTION_PAY_SHORT, RATE_PROVIDER, VOLS);
            double                forward       = PRICER_SWAP.parRate(RSWAP_REC, RATE_PROVIDER);
            double                annuityCash   = PRICER_SWAP.LegPricer.annuityCash(RSWAP_REC.getLegs(SwapLegType.FIXED).get(0), forward);
            double                volatility    = VOLS.volatility(SWAPTION_REC_LONG.Expiry, SWAP_TENOR_YEAR, STRIKE, forward);
            double                discount      = RATE_PROVIDER.discountFactor(USD, SETTLE_DATE);
            NormalFunctionData    normalData    = NormalFunctionData.of(forward, annuityCash * discount, volatility);
            double                expiry        = VOLS.relativeTime(SWAPTION_REC_LONG.Expiry);
            EuropeanVanillaOption optionRec     = EuropeanVanillaOption.of(STRIKE, expiry, PutCall.PUT);
            EuropeanVanillaOption optionPay     = EuropeanVanillaOption.of(STRIKE, expiry, PutCall.CALL);
            double                pvRecExpected = NORMAL.getPriceFunction(optionRec).apply(normalData);
            double                pvPayExpected = -NORMAL.getPriceFunction(optionPay).apply(normalData);

            assertEquals(pvRecComputed.Currency, USD);
            assertEquals(pvRecComputed.Amount, pvRecExpected, NOTIONAL * TOL);
            assertEquals(pvPayComputed.Currency, USD);
            assertEquals(pvPayComputed.Amount, pvPayExpected, NOTIONAL * TOL);
        }