示例#1
0
 //-------------------------------------------------------------------------
 public virtual void test_price_presentValue()
 {
     for (int i = 0; i < NB_STRIKES; ++i)
     {
         ResolvedFxVanillaOption      call      = CALLS[i];
         ResolvedFxVanillaOptionTrade callTrade = ResolvedFxVanillaOptionTrade.builder().product(call).premium(Payment.of(EUR, 0, VAL_DATE)).build();
         double               computedPriceCall = PRICER.price(call, RATES_PROVIDER, VOLS);
         CurrencyAmount       computedCall      = PRICER.presentValue(call, RATES_PROVIDER, VOLS);
         double               timeToExpiry      = VOLS.relativeTime(EXPIRY);
         FxRate               forward           = FX_PRICER.forwardFxRate(UNDERLYING[i], RATES_PROVIDER);
         double               forwardRate       = forward.fxRate(CURRENCY_PAIR);
         double               strikeRate        = call.Strike;
         SmileDeltaParameters smileAtTime       = VOLS.Smile.smileForExpiry(timeToExpiry);
         double[]             strikes           = smileAtTime.strike(forwardRate).toArray();
         double[]             vols              = smileAtTime.Volatility.toArray();
         double               df                = RATES_PROVIDER.discountFactor(USD, PAY);
         double[]             weights           = this.weights(forwardRate, strikeRate, strikes, timeToExpiry, vols[1]);
         double               expectedPriceCall = BlackFormulaRepository.price(forwardRate, strikeRate, timeToExpiry, vols[1], true);
         for (int j = 0; j < 3; ++j)
         {
             expectedPriceCall += weights[j] * (BlackFormulaRepository.price(forwardRate, strikes[j], timeToExpiry, vols[j], true) - BlackFormulaRepository.price(forwardRate, strikes[j], timeToExpiry, vols[1], true));
         }
         expectedPriceCall *= df;
         assertEquals(computedPriceCall, expectedPriceCall, TOL);
         assertEquals(computedCall.Amount, expectedPriceCall * NOTIONAL, TOL * NOTIONAL);
         // test against trade pricer
         assertEquals(computedCall, TRADE_PRICER.presentValue(callTrade, RATES_PROVIDER, VOLS).getAmount(USD));
     }
 }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Calculates the present value of the FX vanilla option trade.
        /// <para>
        /// The present value of the trade is the value on the valuation date.
        ///
        /// </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(ResolvedFxVanillaOptionTrade trade, RatesProvider ratesProvider, BlackFxOptionSmileVolatilities volatilities)
        {
            ResolvedFxVanillaOption 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));
        }