public virtual void test_of_positiveNegative()
 {
     assertThrowsIllegalArg(() => FxSingle.of(GBP_P1000, USD_P1600, DATE_2015_06_30));
     assertThrowsIllegalArg(() => FxSingle.of(GBP_M1000, USD_M1600, DATE_2015_06_30));
     assertThrowsIllegalArg(() => FxSingle.of(CurrencyAmount.zero(GBP), USD_M1600, DATE_2015_06_30));
     assertThrowsIllegalArg(() => FxSingle.of(CurrencyAmount.zero(GBP), USD_P1600, DATE_2015_06_30));
 }
예제 #2
0
        public virtual void test_of_wrongCounterCurrency()
        {
            FxSingle nearLeg = FxSingle.of(USD_P1550, EUR_P1590.negated(), DATE_2011_11_21);
            FxSingle farLeg  = FxSingle.of(GBP_M1000, EUR_P1590, DATE_2011_12_21);

            assertThrowsIllegalArg(() => FxSwap.of(nearLeg, farLeg));
        }
        public virtual void test_of_rate_bothZero()
        {
            FxSingle test = FxSingle.of(CurrencyAmount.zero(GBP), FxRate.of(USD, GBP, 1.6d), DATE_2015_06_30);

            assertEquals(test.BaseCurrencyAmount, CurrencyAmount.zero(GBP));
            assertEquals(test.CounterCurrencyAmount.Amount, CurrencyAmount.zero(USD).Amount, 1e-12);
            assertEquals(test.PaymentDate, DATE_2015_06_30);
            assertEquals(test.CurrencyPair, CurrencyPair.of(GBP, USD));
            assertEquals(test.ReceiveCurrencyAmount, CurrencyAmount.of(USD, 0d));
        }
        public virtual void test_of_rate_switchOrder()
        {
            FxSingle test = FxSingle.of(USD_M1600, FxRate.of(USD, GBP, 1d / 1.6d), DATE_2015_06_30);

            assertEquals(test.BaseCurrencyAmount, GBP_P1000);
            assertEquals(test.CounterCurrencyAmount, USD_M1600);
            assertEquals(test.PaymentDate, DATE_2015_06_30);
            assertEquals(test.CurrencyPair, CurrencyPair.of(GBP, USD));
            assertEquals(test.ReceiveCurrencyAmount, GBP_P1000);
        }
        public virtual void test_of_rate_withAdjustment()
        {
            FxSingle test = FxSingle.of(GBP_P1000, FxRate.of(GBP, USD, 1.6d), DATE_2015_06_30, BDA);

            assertEquals(test.BaseCurrencyAmount, GBP_P1000);
            assertEquals(test.CounterCurrencyAmount, USD_M1600);
            assertEquals(test.PaymentDate, DATE_2015_06_30);
            assertEquals(test.PaymentDateAdjustment, BDA);
            assertEquals(test.CurrencyPair, CurrencyPair.of(GBP, USD));
            assertEquals(test.ReceiveCurrencyAmount, GBP_P1000);
        }
        public virtual void test_of_bothZero()
        {
            FxSingle test = FxSingle.of(CurrencyAmount.zero(GBP), CurrencyAmount.zero(USD), DATE_2015_06_30);

            assertEquals(test.BaseCurrencyAmount, CurrencyAmount.zero(GBP));
            assertEquals(test.CounterCurrencyAmount, CurrencyAmount.zero(USD));
            assertEquals(test.PaymentDate, DATE_2015_06_30);
            assertEquals(test.CurrencyPair, CurrencyPair.of(GBP, USD));
            assertEquals(test.PayCurrencyAmount, CurrencyAmount.zero(GBP));
            assertEquals(test.ReceiveCurrencyAmount, CurrencyAmount.zero(USD));
        }
예제 #7
0
        public virtual void test_ofForwardPoints_withAdjustment()
        {
            double   nearRate   = 1.6;
            double   fwdPoint   = 0.1;
            FxSwap   test       = FxSwap.ofForwardPoints(GBP_P1000, FxRate.of(GBP, USD, nearRate), fwdPoint, DATE_2011_11_21, DATE_2011_12_21, BDA);
            FxSingle nearLegExp = FxSingle.of(GBP_P1000, CurrencyAmount.of(USD, -1000.0 * nearRate), DATE_2011_11_21, BDA);
            FxSingle farLegExp  = FxSingle.of(GBP_M1000, CurrencyAmount.of(USD, 1000.0 * (nearRate + fwdPoint)), DATE_2011_12_21, BDA);

            assertEquals(test.NearLeg, nearLegExp);
            assertEquals(test.FarLeg, farLegExp);
        }
        //-------------------------------------------------------------------------
        public virtual void test_of_rightOrderPayments()
        {
            FxSingle test = FxSingle.of(Payment.of(GBP_P1000, DATE_2015_06_30), Payment.of(USD_M1600, DATE_2015_06_29), BDA);

            assertEquals(test.BaseCurrencyPayment, Payment.of(GBP_P1000, DATE_2015_06_30));
            assertEquals(test.CounterCurrencyPayment, Payment.of(USD_M1600, DATE_2015_06_29));
            assertEquals(test.BaseCurrencyAmount, GBP_P1000);
            assertEquals(test.CounterCurrencyAmount, USD_M1600);
            assertEquals(test.PaymentDate, DATE_2015_06_30);
            assertEquals(test.PaymentDateAdjustment, BDA);
            assertEquals(test.CurrencyPair, CurrencyPair.of(GBP, USD));
            assertEquals(test.PayCurrencyAmount, USD_M1600);
            assertEquals(test.ReceiveCurrencyAmount, GBP_P1000);
            assertEquals(test.CrossCurrency, true);
            assertEquals(test.allPaymentCurrencies(), ImmutableSet.of(GBP, USD));
            assertEquals(test.allCurrencies(), ImmutableSet.of(GBP, USD));
        }
예제 #9
0
        /// <summary>
        /// Creates an {@code FxSwap} using two FX rates, near and far, specifying a date adjustment.
        /// <para>
        /// The FX rate at the near date is specified as {@code nearRate}.
        /// The FX rate at the far date is specified as {@code farRate}.
        /// The FX rates must have the same currency pair.
        /// </para>
        /// <para>
        /// The two currencies are specified by the FX rates.
        /// The amount must be specified using one of the currencies of the near FX rate.
        /// The near date must be before the far date.
        /// Conventions will be used to determine the base and counter currency.
        ///
        /// </para>
        /// </summary>
        /// <param name="amount">  the amount being exchanged, positive if being received in the near leg, negative if being paid </param>
        /// <param name="nearRate">  the near FX rate </param>
        /// <param name="farRate">  the far FX rate </param>
        /// <param name="nearDate">  the near value date </param>
        /// <param name="farDate">  the far value date </param>
        /// <returns> the FX swap </returns>
        /// <exception cref="IllegalArgumentException"> if the FX rate and amount do not have a currency in common,
        ///   or if the FX rate currencies differ </exception>
        public static FxSwap of(CurrencyAmount amount, FxRate nearRate, LocalDate nearDate, FxRate farRate, LocalDate farDate)
        {
            Currency currency1 = amount.Currency;

            if (!nearRate.Pair.contains(currency1))
            {
                throw new System.ArgumentException(Messages.format("FxRate '{}' and CurrencyAmount '{}' must have a currency in common", nearRate, amount));
            }
            if (!nearRate.Pair.toConventional().Equals(farRate.Pair.toConventional()))
            {
                throw new System.ArgumentException(Messages.format("FxRate '{}' and FxRate '{}' must contain the same currencies", nearRate, farRate));
            }
            FxSingle nearLeg = FxSingle.of(amount, nearRate, nearDate);
            FxSingle farLeg  = FxSingle.of(amount.negated(), farRate, farDate);

            return(of(nearLeg, farLeg));
        }
예제 #10
0
        public override object build <T1>(Type beanType, BeanBuilder <T1> builder)
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.joda.beans.impl.BufferingBeanBuilder<?> bld = (org.joda.beans.impl.BufferingBeanBuilder<?>) builder;
            BufferingBeanBuilder <object> bld = (BufferingBeanBuilder <object>)builder;
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.ConcurrentMap<org.joda.beans.MetaProperty<?>, Object> buffer = bld.getBuffer();
            ConcurrentMap <MetaProperty <object>, object> buffer = bld.Buffer;
            BusinessDayAdjustment bda = (BusinessDayAdjustment)buffer.getOrDefault(PAYMENT_ADJUSTMENT_DATE, null);

            if (buffer.containsKey(BASE_CURRENCY_AMOUNT) && buffer.containsKey(COUNTER_CURRENCY_AMOUNT) && buffer.containsKey(PAYMENT_DATE))
            {
                CurrencyAmount baseAmount    = (CurrencyAmount)builder.get(BASE_CURRENCY_AMOUNT);
                CurrencyAmount counterAmount = (CurrencyAmount)builder.get(COUNTER_CURRENCY_AMOUNT);
                LocalDate      paymentDate   = (LocalDate)builder.get(PAYMENT_DATE);
                return(bda != null?FxSingle.of(baseAmount, counterAmount, paymentDate, bda) : FxSingle.of(baseAmount, counterAmount, paymentDate));
            }
            else
            {
                Payment basePayment    = (Payment)buffer.get(BASE_CURRENCY_PAYMENT);
                Payment counterPayment = (Payment)buffer.get(COUNTER_CURRENCY_PAYMENT);
                return(bda != null?FxSingle.of(basePayment, counterPayment, bda) : FxSingle.of(basePayment, counterPayment));
            }
        }
 internal static FxSingle sut2()
 {
     return(FxSingle.of(GBP_M1000, EUR_P1600, DATE_2015_06_29));
 }
 //-------------------------------------------------------------------------
 internal static FxSingle sut()
 {
     return(FxSingle.of(GBP_P1000, USD_M1600, DATE_2015_06_30));
 }
 public virtual void test_of_rate_wrongCurrency()
 {
     assertThrowsIllegalArg(() => FxSingle.of(GBP_P1000, FxRate.of(USD, EUR, 1.45d), DATE_2015_06_30));
 }
 public virtual void test_of_sameCurrency()
 {
     assertThrowsIllegalArg(() => FxSingle.of(GBP_P1000, GBP_M1000, DATE_2015_06_30));
 }
예제 #15
0
        public virtual void test_of_sameSign()
        {
            FxSingle farLeg = FxSingle.of(GBP_M1000.negated(), USD_P1550.negated(), DATE_2011_12_21);

            assertThrowsIllegalArg(() => FxSwap.of(NEAR_LEG, farLeg));
        }
예제 #16
0
        public virtual void test_of_wrongBaseCurrency()
        {
            FxSingle nearLeg = FxSingle.of(EUR_P1590, USD_M1600, DATE_2011_11_21);

            assertThrowsIllegalArg(() => FxSwap.of(nearLeg, FAR_LEG));
        }