예제 #1
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));
        }
예제 #2
0
 private FxSingleTrade(TradeInfo info, FxSingle product)
 {
     JodaBeanUtils.notNull(info, "info");
     JodaBeanUtils.notNull(product, "product");
     this.info    = info;
     this.product = product;
 }
예제 #3
0
        internal static FxSwap sut2()
        {
            FxSingle nearLeg = FxSingle.of(CurrencyAmount.of(GBP, 1_100), CurrencyAmount.of(USD, -1_650), DATE_2011_11_21);
            FxSingle farLeg  = FxSingle.of(CurrencyAmount.of(GBP, -1_100), CurrencyAmount.of(USD, 1_750), DATE_2011_12_21);

            return(FxSwap.of(nearLeg, farLeg));
        }
 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));
 }
예제 #5
0
 private FxSwap(FxSingle nearLeg, FxSingle farLeg)
 {
     JodaBeanUtils.notNull(nearLeg, "nearLeg");
     JodaBeanUtils.notNull(farLeg, "farLeg");
     this.nearLeg = nearLeg;
     this.farLeg  = farLeg;
     validate();
 }
        //-------------------------------------------------------------------------
        public virtual void test_resolve()
        {
            FxSingle         fwd  = sut();
            ResolvedFxSingle test = fwd.resolve(REF_DATA);

            assertEquals(test.BaseCurrencyPayment, Payment.of(GBP_P1000, DATE_2015_06_30));
            assertEquals(test.CounterCurrencyPayment, Payment.of(USD_M1600, DATE_2015_06_30));
            assertEquals(test.PaymentDate, DATE_2015_06_30);
        }
        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_builder_switchOrder()
        {
            FxSingle test = FxSingle.meta().builder().set(FxSingle.meta().baseCurrencyPayment(), Payment.of(USD_M1600, DATE_2015_06_30)).set(FxSingle.meta().counterCurrencyPayment(), Payment.of(GBP_P1000, DATE_2015_06_30)).build();

            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_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_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));
        }
예제 #11
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_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);
        }
예제 #13
0
 //-----------------------------------------------------------------------
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         FxSingle other = (FxSingle)obj;
         return(JodaBeanUtils.equal(baseCurrencyPayment, other.baseCurrencyPayment) && JodaBeanUtils.equal(counterCurrencyPayment, other.counterCurrencyPayment) && JodaBeanUtils.equal(paymentDateAdjustment, other.paymentDateAdjustment));
     }
     return(false);
 }
예제 #14
0
            public override Builder set(string propertyName, object newValue)
            {
                switch (propertyName.GetHashCode())
                {
                case 3237038:         // info
                    this.info_Renamed = (TradeInfo)newValue;
                    break;

                case -309474065:         // product
                    this.product_Renamed = (FxSingle)newValue;
                    break;

                default:
                    throw new NoSuchElementException("Unknown property: " + propertyName);
                }
                return(this);
            }
예제 #15
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));
        }
        //-------------------------------------------------------------------------
        public virtual void test_of_rightOrder()
        {
            FxSingle test = sut();

            assertEquals(test.BaseCurrencyPayment, Payment.of(GBP_P1000, DATE_2015_06_30));
            assertEquals(test.CounterCurrencyPayment, Payment.of(USD_M1600, DATE_2015_06_30));
            assertEquals(test.BaseCurrencyAmount, GBP_P1000);
            assertEquals(test.CounterCurrencyAmount, USD_M1600);
            assertEquals(test.PaymentDate, DATE_2015_06_30);
            assertEquals(test.PaymentDateAdjustment, null);
            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));
        }
예제 #17
0
            public override Builder set(string propertyName, object newValue)
            {
                switch (propertyName.GetHashCode())
                {
                case 1825755334:         // nearLeg
                    this.nearLeg = (FxSingle)newValue;
                    break;

                case -1281739913:         // farLeg
                    this.farLeg = (FxSingle)newValue;
                    break;

                default:
                    throw new NoSuchElementException("Unknown property: " + propertyName);
                }
                return(this);
            }
예제 #18
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));
            }
        }
예제 #19
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains an instance of a foreign exchange trade.
 /// </summary>
 /// <param name="info">  the trade info </param>
 /// <param name="product">  the product </param>
 /// <returns> the trade </returns>
 public static FxSingleTrade of(TradeInfo info, FxSingle product)
 {
     return(new FxSingleTrade(info, product));
 }
예제 #20
0
 /// <summary>
 /// Sets the product that was agreed when the trade occurred.
 /// <para>
 /// The product captures the contracted financial details of the trade.
 /// </para>
 /// </summary>
 /// <param name="product">  the new value, not null </param>
 /// <returns> this, for chaining, not null </returns>
 public Builder product(FxSingle product)
 {
     JodaBeanUtils.notNull(product, "product");
     this.product_Renamed = product;
     return(this);
 }
예제 #21
0
 /// <summary>
 /// Restricted copy constructor. </summary>
 /// <param name="beanToCopy">  the bean to copy from, not null </param>
 internal Builder(FxSingleTrade beanToCopy)
 {
     this.info_Renamed    = beanToCopy.Info;
     this.product_Renamed = beanToCopy.Product;
 }
예제 #22
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));
        }
 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));
 }
예제 #25
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));
        }
 public virtual void test_builder_sameCurrency()
 {
     assertThrowsIllegalArg(() => FxSingle.meta().builder().set(FxSingle.meta().baseCurrencyPayment(), Payment.of(GBP_P1000, DATE_2015_06_30)).set(FxSingle.meta().counterCurrencyPayment(), Payment.of(GBP_M1000, DATE_2015_06_30)).build());
 }
 public virtual void test_of_rate_wrongCurrency()
 {
     assertThrowsIllegalArg(() => FxSingle.of(GBP_P1000, FxRate.of(USD, EUR, 1.45d), DATE_2015_06_30));
 }
예제 #28
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Creates an {@code FxSwap} from two transactions.
 /// <para>
 /// The transactions must be passed in with value dates in the correct order.
 /// The currency pair of each leg must match and have amounts flowing in opposite directions.
 ///
 /// </para>
 /// </summary>
 /// <param name="nearLeg">  the earlier leg </param>
 /// <param name="farLeg">  the later leg </param>
 /// <returns> the FX swap </returns>
 public static FxSwap of(FxSingle nearLeg, FxSingle farLeg)
 {
     return(new FxSwap(nearLeg, farLeg));
 }
 public virtual void test_of_sameCurrency()
 {
     assertThrowsIllegalArg(() => FxSingle.of(GBP_P1000, GBP_M1000, DATE_2015_06_30));
 }