Пример #1
0
        /// <summary>Adds the specified rate for the specified base and counter currencies, using the specified update criterion.</summary>
        /// <param name="currencyBase">The <see cref="T:InitialMargin.Core.Currency"/> object representing the base currency.</param>
        /// <param name="currencyCounter">The <see cref="T:InitialMargin.Core.Currency"/> object representing the counter currency.</param>
        /// <param name="rate">A <see cref="T:System.Decimal"/> representing the rate.</param>
        /// <param name="update"><c>true</c> to update the lookup table if the currency pair implicitly defined by the currencies already exists; otherwise, <c>false</c>.</param>
        /// <exception cref="T:System.ArgumentException">Thrown when <paramref name="currencyBase">currencyBase</paramref> is equal to <paramref name="currencyCounter">currencyCounter</paramref> or when <paramref name="rate">rate</paramref> is less than or equal to <c>0</c>.</exception>
        /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="currencyBase">currencyBase</paramref> is <c>null</c> or when <paramref name="currencyCounter">currencyCounter</paramref> is <c>null</c>.</exception>
        /// <exception cref="T:System.InvalidOperationException">Thrown when the currency pair implicitly defined by <paramref name="currencyBase">currencyBase</paramref> and <paramref name="currencyCounter">currencyCounter</paramref> already exists in the lookup table and <paramref name="update">update</paramref> is <c>false</c>.</exception>
        public void AddRate(Currency currencyBase, Currency currencyCounter, Decimal rate, Boolean update)
        {
            if (currencyBase == null)
            {
                throw new ArgumentNullException(nameof(currencyBase));
            }

            if (currencyCounter == null)
            {
                throw new ArgumentNullException(nameof(currencyCounter));
            }

            if (currencyBase == currencyCounter)
            {
                throw new ArgumentException("The two currencies must be different.");
            }

            AddRate(CurrencyPair.Of(currencyBase, currencyCounter), rate, update);
        }
Пример #2
0
        /// <summary>Retrieves the rate for the specified base and counter currencies, using the specified triangulation approach.</summary>
        /// <param name="currencyBase">The <see cref="T:InitialMargin.Core.Currency"/> object representing the base currency.</param>
        /// <param name="currencyCounter">The <see cref="T:InitialMargin.Core.Currency"/> object representing the counter currency.</param>
        /// <param name="useTriangulation"><c>true</c> to perform a triangulation if necessary; otherwise, <c>false</c>.</param>
        /// <returns>A <see cref="T:System.Decimal"/> representing the rate.</returns>
        /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="currencyBase">currencyBase</paramref> is <c>null</c> or when <paramref name="currencyCounter">currencyCounter</paramref> is <c>null</c>.</exception>
        /// <exception cref="T:System.InvalidOperationException">Thrown when the rate cannot be retrieved.</exception>
        public Decimal GetRate(Currency currencyBase, Currency currencyCounter, Boolean useTriangulation)
        {
            if (currencyBase == null)
            {
                throw new ArgumentNullException(nameof(currencyBase));
            }

            if (currencyCounter == null)
            {
                throw new ArgumentNullException(nameof(currencyCounter));
            }

            if (currencyBase == currencyCounter)
            {
                return(1m);
            }

            return(GetRate(CurrencyPair.Of(currencyBase, currencyCounter), useTriangulation));
        }
Пример #3
0
        /// <summary>Tries to retrieve the rate for the specified base and counter currencies, using the specified triangulation approach.</summary>
        /// <param name="currencyBase">The <see cref="T:InitialMargin.Core.Currency"/> object representing the base currency.</param>
        /// <param name="currencyCounter">The <see cref="T:InitialMargin.Core.Currency"/> object representing the counter currency.</param>
        /// <param name="useTriangulation"><c>true</c> to perform a triangulation if necessary; otherwise, <c>false</c>.</param>
        /// <param name="rate">A <see cref="T:System.Decimal"/> representing the rate or <c>0</c>.</param>
        /// <returns><c>true</c> if the rate was successfully retrieved; otherwise, <c>false</c>.</returns>
        public Boolean TryGetRate(Currency currencyBase, Currency currencyCounter, Boolean useTriangulation, out Decimal rate)
        {
            if (currencyBase == null)
            {
                throw new ArgumentNullException(nameof(currencyBase));
            }

            if (currencyCounter == null)
            {
                throw new ArgumentNullException(nameof(currencyCounter));
            }

            if (currencyBase == currencyCounter)
            {
                rate = 1m;
                return(true);
            }

            return(TryGetRate(CurrencyPair.Of(currencyBase, currencyCounter), useTriangulation, out rate));
        }