Ejemplo n.º 1
0
        public void TestOutputCsv(RegulationRole regulationRole, String csvFile)
        {
            FxRatesProvider ratesProvider = m_TestsFixture.RatesProvider;
            ReadOnlyCollection <DataEntity> dataEntities = m_TestsFixture.DataEntities;
            OutputWriterCsv writer = m_TestsFixture.WriterCsv;

            Engine engine = Engine.Of(Currency.Usd, ratesProvider);

            String csvExpectedFile = Utilities.GetStaticFilePath(csvFile);
            String csvActualFile   = Utilities.GetRandomFilePath(".csv");

            MarginTotal margin = engine.CalculateDetailed(regulationRole, dataEntities);

            writer.Write(csvActualFile, margin);

            String expected = Utilities.ComputeHash(File.ReadAllText(csvExpectedFile));
            String actual   = Utilities.ComputeHash(File.ReadAllText(csvActualFile));

            try
            {
                File.Delete(csvActualFile);
            }
            catch { }

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 2
0
        /// <summary>Calculates the worst total margin among all the regulations for the specified regulation role and for the entities defined in the specified CRIF file.</summary>
        /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
        /// <param name="crifPath">The <see cref="T:System.String"/> representing the CRIF file that defines the target entities.</param>
        /// <returns>A <see cref="T:InitialMargin.Core.MarginTotal"/> object representing the worst total margin among all the regulations.</returns>
        /// <exception cref="T:System.ArgumentException">Thrown when <paramref name="crifPath">crifPath</paramref> is invalid or does not refer to a CSV file.</exception>
        /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
        /// <exception cref="T:System.IO.FileNotFoundException">Thrown when <paramref name="crifPath">crifPath</paramref> could not be found.</exception>
        /// <exception cref="T:System.IO.InvalidDataException">Thrown when the CRIF file contains invalid or malformed data.</exception>
        public MarginTotal CalculateDetailedWorstOf(RegulationRole regulationRole, String crifPath)
        {
            ICollection <DataEntity> entities   = CrifManager.Read(crifPath);
            List <DataValue>         values     = entities.OfType <DataValue>().ToList();
            List <DataParameter>     parameters = entities.OfType <DataParameter>().ToList();

            return(CalculateDetailedWorstOf(regulationRole, values, parameters));
        }
Ejemplo n.º 3
0
        /// <summary>Calculates the total margin amount of each regulation for the specified regulation role and for the entities defined in the specified CRIF file.</summary>
        /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
        /// <param name="crifPath">The <see cref="T:System.String"/> representing the CRIF file that defines the target entities.</param>
        /// <returns>An <see cref="System.Collections.Generic.IDictionary{TKey,TValue}"/> of pairs defined by <see cref="T:InitialMargin.Core.Regulation"/> keys and <see cref="T:InitialMargin.Core.Amount"/> values representing the regulation/amount couples.</returns>
        /// <exception cref="T:System.ArgumentException">Thrown when <paramref name="crifPath">crifPath</paramref> is invalid or does not refer to a CSV file.</exception>
        /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
        /// <exception cref="T:System.IO.FileNotFoundException">Thrown when <paramref name="crifPath">crifPath</paramref> could not be found.</exception>
        /// <exception cref="T:System.IO.InvalidDataException">Thrown when the CRIF file contains invalid or malformed data.</exception>
        public IDictionary <Regulation, Amount> CalculateByRole(RegulationRole regulationRole, String crifPath)
        {
            ICollection <DataEntity> entities   = CrifManager.Read(crifPath);
            List <DataValue>         values     = entities.OfType <DataValue>().ToList();
            List <DataParameter>     parameters = entities.OfType <DataParameter>().ToList();

            return(CalculateByRole(regulationRole, values, parameters));
        }
Ejemplo n.º 4
0
        /// <summary>Calculates the total margin of each regulation for the specified regulation role, value entities and parameter entities.</summary>
        /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
        /// <param name="values">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataValue"/> objects representing the target value entities.</param>
        /// <param name="parameters">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataParameter"/> objects representing the target parameter entities.</param>
        /// <returns>An <see cref="System.Collections.Generic.IDictionary{TKey,TValue}"/> of pairs defined by <see cref="T:InitialMargin.Core.Regulation"/> keys and <see cref="T:InitialMargin.Core.Amount"/> values representing the regulation/margin couples.</returns>
        /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="values">values</paramref> is <c>null</c> or when <paramref name="parameters">parameters</paramref> is <c>null</c>.</exception>
        /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
        public IDictionary <Regulation, MarginTotal> CalculateDetailedByRole(RegulationRole regulationRole, ICollection <DataValue> values, ICollection <DataParameter> parameters)
        {
            if (!Enum.IsDefined(typeof(RegulationRole), regulationRole))
            {
                throw new InvalidEnumArgumentException("Invalid regulation role specified.");
            }

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

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

            List <Regulation> regulations = values.SelectMany(x => SelectRegulations(x, regulationRole))
                                            .Concat(parameters.SelectMany(x => SelectRegulations(x, regulationRole)))
                                            .OrderBy(x => x)
                                            .Distinct().ToList();

            if (regulations.Count == 0)
            {
                return(new Dictionary <Regulation, MarginTotal>());
            }

            List <DataValue> valuesFinal = values.Where(x => !(x is PresentValue) && !(x is Sensitivity)).Select(x => (DataValue)x.Clone())
                                           .Concat(values.OfType <PresentValue>().Select(x => AdjustedClone(x, regulationRole)))
                                           .Concat(values.OfType <Sensitivity>().Select(x => AdjustedClone(x, regulationRole)))
                                           .ToList();

            List <DataParameter> parametersFinal = parameters
                                                   .Select(x => (DataParameter)x.Clone())
                                                   .ToList();

            Dictionary <Regulation, MarginTotal> result = new Dictionary <Regulation, MarginTotal>();

            foreach (Regulation regulation in regulations)
            {
                List <DataValue>     valuesByRegulation     = valuesFinal.Where(x => SelectRegulations(x, regulationRole).Contains(regulation)).ToList();
                List <DataParameter> parametersByRegulation = parametersFinal.Where(x => SelectRegulations(x, regulationRole).Contains(regulation)).ToList();

                List <IMargin> margins = new List <IMargin>(m_Processors.Count);

                foreach (Processor processor in m_Processors)
                {
                    margins.Add(processor.Process(valuesByRegulation, parametersByRegulation));
                }

                result[regulation] = MarginTotal.Of(regulationRole, regulation, m_ValuationDate, m_CalculationCurrency, margins);
            }

            return(result);
        }
Ejemplo n.º 5
0
        private static DataValue AdjustedClone(PresentValue presentValue, RegulationRole regulationRole)
        {
            DataValue clone = (DataValue)presentValue.Clone();

            if (regulationRole == RegulationRole.Secured)
            {
                clone = clone.ChangeAmount(-clone.Amount);
            }

            return(clone);
        }
Ejemplo n.º 6
0
        private static DataValue AdjustedClone(Sensitivity sensitivity, RegulationRole regulationRole)
        {
            DataValue clone = (DataValue)sensitivity.Clone();

            if (regulationRole == RegulationRole.Pledgor)
            {
                clone = clone.ChangeAmount(-clone.Amount);
            }

            return(clone);
        }
Ejemplo n.º 7
0
        /// <summary>Calculates the total margin of each regulation for the specified regulation role and entities.</summary>
        /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
        /// <param name="entities">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataEntity"/> objects representing the target entities.</param>
        /// <returns>An <see cref="System.Collections.Generic.IDictionary{TKey,TValue}"/> of pairs defined by <see cref="T:InitialMargin.Core.Regulation"/> keys and <see cref="T:InitialMargin.Core.Amount"/> values representing the regulation/margin couples.</returns>
        /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="entities">entities</paramref> is <c>null</c>.</exception>
        /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
        public IDictionary <Regulation, MarginTotal> CalculateDetailedByRole(RegulationRole regulationRole, ICollection <DataEntity> entities)
        {
            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }

            ICollection <DataValue>     values     = entities.OfType <DataValue>().ToList();
            ICollection <DataParameter> parameters = entities.OfType <DataParameter>().ToList();

            return(CalculateDetailedByRole(regulationRole, values, parameters));
        }
Ejemplo n.º 8
0
        public void TestResult(RegulationRole regulationRole, Double result)
        {
            FxRatesProvider ratesProvider = m_TestsFixture.RatesProvider;
            ReadOnlyCollection <DataEntity> dataEntities = m_TestsFixture.DataEntities;

            Engine engine = Engine.Of(Currency.Usd, ratesProvider);

            Decimal expected = Convert.ToDecimal(result);
            Decimal actual   = Math.Round(engine.Calculate(regulationRole, dataEntities).Value, 0, MidpointRounding.AwayFromZero);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 9
0
        /// <summary>Calculates the worst total margin among all the regulations for the specified regulation role and entities.</summary>
        /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
        /// <param name="entities">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataEntity"/> objects representing the target entities.</param>
        /// <returns>A <see cref="T:InitialMargin.Core.MarginTotal"/> object representing the worst total margin among all the regulations.</returns>
        /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="entities">entities</paramref> is <c>null</c>.</exception>
        /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
        public MarginTotal CalculateDetailedWorstOf(RegulationRole regulationRole, ICollection <DataEntity> entities)
        {
            if (entities == null)
            {
                throw new ArgumentNullException(nameof(entities));
            }

            List <DataValue>     values     = entities.OfType <DataValue>().ToList();
            List <DataParameter> parameters = entities.OfType <DataParameter>().ToList();

            return(CalculateDetailedWorstOf(regulationRole, values, parameters));
        }
Ejemplo n.º 10
0
        /// <summary>Calculates the total margin for the specified regulation role, value entities and parameter entities.</summary>
        /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
        /// <param name="values">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataValue"/> objects representing the target value entities.</param>
        /// <param name="parameters">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataParameter"/> objects representing the target parameter entities.</param>
        /// <returns>A <see cref="T:InitialMargin.Core.MarginTotal"/> object representing the total margin.</returns>
        /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="values">values</paramref> is <c>null</c> or when <paramref name="parameters">parameters</paramref> is <c>null</c>.</exception>
        /// <exception cref="T:System.InvalidOperationException">Thrown when <paramref name="values">values</paramref> contains elements defined on different regulations or when <paramref name="parameters">parameters</paramref> contains elements defined on different regulations.</exception>
        /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
        public MarginTotal CalculateDetailed(RegulationRole regulationRole, ICollection <DataValue> values, ICollection <DataParameter> parameters)
        {
            if (!Enum.IsDefined(typeof(RegulationRole), regulationRole))
            {
                throw new InvalidEnumArgumentException("Invalid regulation role specified.");
            }

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

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

            List <Regulation> regulations = values.SelectMany(x => SelectRegulations(x, regulationRole))
                                            .Concat(parameters.SelectMany(x => SelectRegulations(x, regulationRole)))
                                            .OrderBy(x => x)
                                            .Distinct().ToList();

            if (regulations.Count > 1)
            {
                throw new InvalidOperationException($"All data entities must either have no regulations defined or belong to a single {((regulationRole == RegulationRole.Pledgor) ? "post" : "collect")} regulation.");
            }

            List <DataValue> valuesFinal = values.Where(x => !(x is PresentValue) && !(x is Sensitivity)).Select(x => (DataValue)x.Clone())
                                           .Concat(values.OfType <PresentValue>().Select(x => AdjustedClone(x, regulationRole)))
                                           .Concat(values.OfType <Sensitivity>().Select(x => AdjustedClone(x, regulationRole)))
                                           .ToList();

            List <DataParameter> parametersFinal = parameters
                                                   .Select(x => (DataParameter)x.Clone())
                                                   .ToList();

            List <IMargin> margins = new List <IMargin>(m_Processors.Count);

            foreach (Processor processor in m_Processors)
            {
                margins.Add(processor.Process(valuesFinal, parametersFinal));
            }

            return(MarginTotal.Of(regulationRole, regulations.Single(), m_ValuationDate, m_CalculationCurrency, margins));
        }
Ejemplo n.º 11
0
 /// <summary>Calculates the worst total margin among all the regulations for the specified regulation role and value entities.</summary>
 /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
 /// <param name="values">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataValue"/> objects representing the target value entities.</param>
 /// <returns>A <see cref="T:InitialMargin.Core.MarginTotal"/> object representing the worst total margin among all the regulations.</returns>
 /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="values">values</paramref> is <c>null</c>.</exception>
 /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
 public MarginTotal CalculateDetailedWorstOf(RegulationRole regulationRole, ICollection <DataValue> values)
 {
     return(CalculateDetailedWorstOf(regulationRole, values, (new List <DataParameter>(0))));
 }
Ejemplo n.º 12
0
 /// <summary>Calculates the total margin amount for the specified regulation role, value entities and parameter entities.</summary>
 /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
 /// <param name="values">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataValue"/> objects representing the target value entities.</param>
 /// <param name="parameters">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataParameter"/> objects representing the target parameter entities.</param>
 /// <returns>An <see cref="T:InitialMargin.Core.Amount"/> object representing the total margin amount.</returns>
 /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="values">values</paramref> is <c>null</c> or when <paramref name="parameters">parameters</paramref> is <c>null</c>.</exception>
 /// <exception cref="T:System.InvalidOperationException">Thrown when <paramref name="values">values</paramref> contains elements defined on different regulations or when <paramref name="parameters">parameters</paramref> contains elements defined on different regulations.</exception>
 /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
 public Amount Calculate(RegulationRole regulationRole, ICollection <DataValue> values, ICollection <DataParameter> parameters)
 {
     return(CalculateDetailed(regulationRole, values, parameters).Value);
 }
Ejemplo n.º 13
0
 /// <summary>Calculates the total margin amount for the specified regulation role and value entities.</summary>
 /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
 /// <param name="values">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataValue"/> objects representing the target value entities.</param>
 /// <returns>An <see cref="T:InitialMargin.Core.Amount"/> object representing the total margin amount.</returns>
 /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="values">values</paramref> is <c>null</c>.</exception>
 /// <exception cref="T:System.InvalidOperationException">Thrown when <paramref name="values">values</paramref> contains elements defined on different regulations.</exception>
 /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
 public Amount Calculate(RegulationRole regulationRole, ICollection <DataValue> values)
 {
     return(CalculateDetailed(regulationRole, values, (new List <DataParameter>(0))).Value);
 }
Ejemplo n.º 14
0
 /// <summary>Calculates the total margin amount for the specified regulation role and entities.</summary>
 /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
 /// <param name="entities">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataEntity"/> objects representing the target entities.</param>
 /// <returns>An <see cref="T:InitialMargin.Core.Amount"/> object representing the total margin amount.</returns>
 /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="entities">entities</paramref> is <c>null</c>.</exception>
 /// <exception cref="T:System.InvalidOperationException">Thrown when <paramref name="entities">entities</paramref> contains elements defined on different regulations.</exception>
 /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
 public Amount Calculate(RegulationRole regulationRole, ICollection <DataEntity> entities)
 {
     return(CalculateDetailed(regulationRole, entities).Value);
 }
Ejemplo n.º 15
0
 /// <summary>Calculates the total margin amount of each regulation for the specified regulation role and value entities.</summary>
 /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
 /// <param name="values">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataValue"/> objects representing the target value entities.</param>
 /// <returns>An <see cref="System.Collections.Generic.IDictionary{TKey,TValue}"/> of pairs defined by <see cref="T:InitialMargin.Core.Regulation"/> keys and <see cref="T:InitialMargin.Core.Amount"/> values representing the regulation/amount couples.</returns>
 /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="values">values</paramref> is <c>null</c>.</exception>
 /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
 public IDictionary <Regulation, Amount> CalculateByRole(RegulationRole regulationRole, ICollection <DataValue> values)
 {
     return(CalculateByRole(regulationRole, values, (new List <DataParameter>(0))));
 }
Ejemplo n.º 16
0
        /// <summary>Calculates the total margin amount of each regulation for the specified regulation role, value entities and parameter entities.</summary>
        /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
        /// <param name="values">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataValue"/> objects representing the target value entities.</param>
        /// <param name="parameters">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataParameter"/> objects representing the target parameter entities.</param>
        /// <returns>An <see cref="System.Collections.Generic.IDictionary{TKey,TValue}"/> of pairs defined by <see cref="T:InitialMargin.Core.Regulation"/> keys and <see cref="T:InitialMargin.Core.Amount"/> values representing the regulation/amount couples.</returns>
        /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="values">values</paramref> is <c>null</c> or when <paramref name="parameters">parameters</paramref> is <c>null</c>.</exception>
        /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
        public IDictionary <Regulation, Amount> CalculateByRole(RegulationRole regulationRole, ICollection <DataValue> values, ICollection <DataParameter> parameters)
        {
            IDictionary <Regulation, MarginTotal> result = CalculateDetailedByRole(regulationRole, values, parameters);

            return(result.ToDictionary(x => x.Key, x => x.Value.Value));
        }
Ejemplo n.º 17
0
 private static List <Regulation> SelectRegulations(DataEntity entity, RegulationRole regulationRole)
 {
     return(((regulationRole == RegulationRole.Pledgor) ? entity.PostRegulations : entity.CollectRegulations).ToList());
 }
Ejemplo n.º 18
0
 /// <summary>Calculates the total margin of each regulation for the specified regulation role and value entities.</summary>
 /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
 /// <param name="values">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataValue"/> objects representing the target value entities.</param>
 /// <returns>An <see cref="System.Collections.Generic.IDictionary{TKey,TValue}"/> of pairs defined by <see cref="T:InitialMargin.Core.Regulation"/> keys and <see cref="T:InitialMargin.Core.Amount"/> values representing the regulation/margin couples.</returns>
 /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="values">values</paramref> is <c>null</c>.</exception>
 /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
 public IDictionary <Regulation, MarginTotal> CalculateDetailedByRole(RegulationRole regulationRole, ICollection <DataValue> values)
 {
     return(CalculateDetailedByRole(regulationRole, values, (new List <DataParameter>(0))));
 }
Ejemplo n.º 19
0
        /// <summary>Calculates the worst total margin among all the regulations for the specified regulation role, value entities and parameter entities.</summary>
        /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
        /// <param name="values">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataValue"/> objects representing the target value entities.</param>
        /// <param name="parameters">The <see cref="System.Collections.Generic.ICollection{T}"/> of <see cref="T:InitialMargin.Core.DataParameter"/> objects representing the target parameter entities.</param>
        /// <returns>A <see cref="T:InitialMargin.Core.MarginTotal"/> object representing the worst total margin among all the regulations.</returns>
        /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="values">values</paramref> is <c>null</c> or when <paramref name="parameters">parameters</paramref> is <c>null</c>.</exception>
        /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
        public MarginTotal CalculateDetailedWorstOf(RegulationRole regulationRole, ICollection <DataValue> values, ICollection <DataParameter> parameters)
        {
            IDictionary <Regulation, MarginTotal> result = CalculateDetailedByRole(regulationRole, values, parameters);

            return(result.Select(x => x.Value).OrderByDescending(x => Amount.Abs(x.Value)).ThenBy(x => x.Regulation).FirstOrDefault());
        }
Ejemplo n.º 20
0
 /// <summary>Calculates the worst total margin amount among all the regulations for the specified regulation role and for the entities defined in the specified CRIF file.</summary>
 /// <param name="regulationRole">An enumerator value of type <see cref="T:InitialMargin.Core.RegulationRole"/> that specifies the target regulation role.</param>
 /// <param name="crifPath">The <see cref="T:System.String"/> representing the CRIF file that defines the target entities.</param>
 /// <returns>An <see cref="T:InitialMargin.Core.Amount"/> object representing the worst total margin amount among all the regulations.</returns>
 /// <exception cref="T:System.ArgumentException">Thrown when <paramref name="crifPath">crifPath</paramref> is invalid or does not refer to a CSV file.</exception>
 /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when <paramref name="regulationRole">regulationRole</paramref> is undefined.</exception>
 /// <exception cref="T:System.IO.FileNotFoundException">Thrown when <paramref name="crifPath">crifPath</paramref> could not be found.</exception>
 /// <exception cref="T:System.IO.InvalidDataException">Thrown when the CRIF file contains invalid or malformed data.</exception>
 public Amount CalculateWorstOf(RegulationRole regulationRole, String crifPath)
 {
     return(CalculateDetailedWorstOf(regulationRole, crifPath).Value);
 }