/// <summary>Sets the rounding rule for Libor rates and sets the <see cref="LiborRateRoundingRuleState"/> to <see cref="ConventionState.StandardValue"/>.
 /// </summary>
 /// <param name="liborRateRoundingRule">The rounding rule for Libor rates.</param>
 internal void SetStandardLiborRateRoundingRule(IRoundingRule liborRateRoundingRule)
 {
     if (liborRateRoundingRule == null)
     {
         throw new ArgumentNullException("liborRateRoundingRule");
     }
     m_LiborRateRoundingRule      = liborRateRoundingRule;
     m_LiborRateRoundingRuleState = ConventionState.StandardValue;
 }
 /// <summary>Sets the rounding rule and sets the <see cref="RoundingRuleState"/> to <see cref="ConventionState.StandardValue"/>.
 /// </summary>
 /// <param name="roundingRule">The rounding rule.</param>
 /// <returns>A value indicating whether <see cref="RoundingRule"/> and <see cref="RoundingRuleState"/> has been changed.</returns>
 internal void SetStandardRoundingRule(IRoundingRule roundingRule)
 {
     if (roundingRule == null)
     {
         throw new ArgumentNullException("roundingRule");
     }
     m_RoundingRule      = roundingRule;
     m_RoundingRuleState = ConventionState.StandardValue;
 }
Esempio n. 3
0
 /// <summary>Initializes a new instance of the <see cref="ReadOnlyInflationMarketConventions"/> class.
 /// </summary>
 /// <param name="inflationMarketConventions">The inflation market conventions.</param>
 /// <exception cref="ArgumentNullException">Thrown, if <paramref name="inflationMarketConventions"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentException">Thrown, if <paramref name="inflationMarketConventions"/> is not completely defined.</exception>
 public ReadOnlyInflationMarketConventions(InflationMarketConventions inflationMarketConventions)
 {
     if (inflationMarketConventions == null)
     {
         throw new ArgumentNullException("inflationMarketConventions");
     }
     if (inflationMarketConventions.IsCompletelyDefined == false)
     {
         throw new ArgumentException(String.Format(ExceptionMessages.ArgumentIsNotWellDefined, "Inflation market conventions"), "inflationMarketConventions");
     }
     RoundingRule = inflationMarketConventions.RoundingRule;
     SwapMarket   = inflationMarketConventions.SwapMarket.AsReadOnly();
     BondMarket   = inflationMarketConventions.BondMarket.AsReadOnly();
 }
Esempio n. 4
0
        /// <summary>Gets a specific rounding rule with respect to its <see cref="System.String"/> representation.
        /// </summary>
        /// <param name="name">The name of the rounding rule.</param>
        /// <param name="value">The rounding rule (output).</param>
        /// <param name="addIntoPool">If a individual rounding rule has been created, the corresponding
        /// <paramref name="value"/> object will be added to the <see cref="RoundingRule"/> if set to <c>true</c>.</param>
        /// <returns>A value indicating whether <paramref name="value"/> contains valid data.</returns>
        public static bool TryGetValue(string name, out IRoundingRule value, bool addIntoPool = false)
        {
            if (sm_Pool.TryGetValue(name, out value) == true)
            {
                return(true);
            }

            // Format: "Rulename:Unit=23.1" or "Rulename:Digits=5" etc.
            string[] ruleNameSplit = name.Split(':', '=');
            if ((ruleNameSplit != null) && (ruleNameSplit.Length == 3))
            {
                Type roundingRuleType;
                if (sm_RoundingRuleTypes.TryGetValue(ruleNameSplit[0].ToIDString(), out roundingRuleType) == true)
                {
                    try
                    {
                        /* assume that the rounding rule needs exactly one argument in the constructor:
                         */
                        Type parameterType = roundingRuleType.GetConstructors()[0].GetParameters()[0].ParameterType;
                        if (parameterType.Equals(typeof(Int32)) == true)
                        {
                            value = (IRoundingRule)Activator.CreateInstance(roundingRuleType, Int32.Parse(ruleNameSplit[2]));
                        }
                        else if (parameterType.Equals(typeof(Double)) == true)
                        {
                            value = (IRoundingRule)Activator.CreateInstance(roundingRuleType, Double.Parse(ruleNameSplit[2], CultureInfo.InvariantCulture));
                        }
                        else if (parameterType.Equals(typeof(String)) == true)
                        {
                            value = (IRoundingRule)Activator.CreateInstance(roundingRuleType, ruleNameSplit[2]);
                        }
                        if (value != null)
                        {
                            if (addIntoPool == true)
                            {
                                sm_Pool.Add(value);
                            }
                            return(true);
                        }
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
            return(false);
        }
 /// <summary>Initializes a new instance of the <see cref="ReadOnlyMoneyMarketConventions"/> class.
 /// </summary>
 /// <param name="moneyMarketConventions">The money market conventions.</param>
 /// <exception cref="ArgumentNullException">Thrown, if <paramref name="moneyMarketConventions"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentException">Thrown, if <paramref name="moneyMarketConventions"/> is not completely defined.</exception>
 public ReadOnlyMoneyMarketConventions(MoneyMarketConventions moneyMarketConventions)
 {
     if (moneyMarketConventions == null)
     {
         throw new ArgumentNullException("moneyMarketConventions");
     }
     if (moneyMarketConventions.IsCompletelyDefined == false)
     {
         throw new ArgumentException(String.Format(ExceptionMessages.ArgumentIsNotWellDefined, "Money market conventions"), "moneyMarketConventions");
     }
     BusinessDayConvention = moneyMarketConventions.BusinessDayConvention;
     FixingLag             = moneyMarketConventions.FixingLag;
     BusinessDaysToSettle  = moneyMarketConventions.BusinessDaysToSettle.Value;
     CapletTenorConvention = moneyMarketConventions.CapletTenorConvention;
     DayCountConvention    = moneyMarketConventions.DayCountConvention;
     FutureBasePointValue  = moneyMarketConventions.FutureBasePointValue;
     LiborIndexName        = moneyMarketConventions.LiborIndexName;
     LiborRateRoundingRule = moneyMarketConventions.LiborRateRoundingRule;
 }
Esempio n. 6
0
 /// <summary>Adds the specified rounding rule.
 /// </summary>
 /// <param name="roundingRule">The rounding rule.</param>
 /// <returns>A value indicating whether <paramref name="roundingRule"/> has been inserted.</returns>
 public static ItemAddedState Add(IRoundingRule roundingRule)
 {
     return(sm_Pool.Add(roundingRule));
 }