/// <summary>Adds a specific <see cref="TenorTimeSpan"/> object to a specific <see cref="System.DateTime"/> object.
        /// </summary>
        /// <param name="startDate">The start date.</param>
        /// <param name="tenorTimeSpan">The time span to add in its <see cref="String"/> representation.</param>
        /// <param name="tenorTimeSpanFactor">A (optional) factor to take into account.</param>
        /// <returns>The <see cref="System.DateTime"/> which is the result of <paramref name="startDate"/> plus <paramref name="tenorTimeSpanFactor"/> * <paramref name="tenorTimeSpan"/>.</returns>
        /// <remarks>If <paramref name="tenorTimeSpan"/> is equal to <see cref="TenorTimeSpan.TomorrowNextTenor"/>, two (2) [times <paramref name="tenorTimeSpanFactor"/>] days will be added to <paramref name="startDate"/>.</remarks>
        public static DateTime AddTenorTimeSpan(this DateTime startDate, string tenorTimeSpan, int tenorTimeSpanFactor = 1)
        {
            DateTime  date = startDate;
            int       years, months, days;
            TenorType tenorType;

            if (TenorTimeSpan.TryParse(tenorTimeSpan, out years, out months, out days, out tenorType) == false)
            {
                throw new ArgumentException(String.Format(Dodoni.BasicComponents.ExceptionMessages.ArgumentIsInvalid, tenorTimeSpan), "tenorTimeSpan");
            }

            if (years != 0)
            {
                date = date.AddYears(tenorTimeSpanFactor * years);
            }
            if (months != 0)
            {
                date = date.AddMonths(tenorTimeSpanFactor * months);
            }
            if (days != 0)
            {
                date = date.AddDays(tenorTimeSpanFactor * days);
            }
            return(date);
        }
Exemplo n.º 2
0
 /// <summary>Indicates whether the current object is equal to another object of type <see cref="TenorTimeSpan"/>.
 /// </summary>
 /// <param name="other">An object to compare with this object.</param>
 /// <returns><c>true</c> if the current object is equal to the <paramref name="other"/> parameter; otherwise <c>false</c>.</returns>
 public bool Equals(TenorTimeSpan other)
 {
     if (TenorTimeSpan.IsNull(SecondTenor) == false)
     {
         return(false);
     }
     return(FirstTenor.Equals(other));
 }
Exemplo n.º 3
0
 /// <summary>Initializes a new instance of the <see cref="TenorTimeSpanSpread"/> struct.
 /// </summary>
 /// <param name="firstTenor">The first tenor.</param>
 /// <param name="secondTenor">The second tenor.</param>
 /// <param name="firstTenorDescription">The optional description of the <paramref name="firstTenor"/>.</param>
 /// <param name="secondTenorDescription">The optional description of the <paramref name="secondTenor"/>.</param>
 /// <param name="stringRepresentationUsage">The string representation usage, i.e. the delimiter used for the <see cref="TenorTimeSpanSpread.ToString()"/> method.</param>
 public TenorTimeSpanSpread(TenorTimeSpan firstTenor, TenorTimeSpan secondTenor, string firstTenorDescription = "", string secondTenorDescription = "", StringRepresentationUsage stringRepresentationUsage = StringRepresentationUsage.Versus)
 {
     FirstTenor                  = firstTenor;
     SecondTenor                 = secondTenor;
     FirstTenorDescription       = (firstTenorDescription != null) ? firstTenorDescription : String.Empty;
     SecondTenorDescription      = (secondTenorDescription != null) ? secondTenorDescription : String.Empty;
     m_StringRepresentationUsage = stringRepresentationUsage;
 }
Exemplo n.º 4
0
 /// <summary>Initializes a new instance of the <see cref="TenorTimeSpanSpread"/> struct.
 /// </summary>
 /// <param name="tenorTimeSpan">The tenor time span.</param>
 /// <param name="description">The optional description of <paramref name="tenorTimeSpan"/>.</param>
 /// <param name="stringRepresentationUsage">The string representation usage, i.e. the delimiter used for the <see cref="TenorTimeSpanSpread.ToString()"/> method.</param>
 public TenorTimeSpanSpread(TenorTimeSpan tenorTimeSpan, string description = "", StringRepresentationUsage stringRepresentationUsage = StringRepresentationUsage.Versus)
 {
     FirstTenor                  = tenorTimeSpan;
     FirstTenorDescription       = (description != null) ? description : String.Empty;
     SecondTenor                 = TenorTimeSpan.Null;
     SecondTenorDescription      = String.Empty;
     m_StringRepresentationUsage = stringRepresentationUsage;
 }
Exemplo n.º 5
0
        /// <summary>Converts a <see cref="System.String"/> object into two <see cref="TenorTimeSpan"/> objects and its descriptions.
        /// </summary>
        /// <param name="tenorSpreadString">The <see cref="System.String"/> representation of the tenor spread.</param>
        /// <param name="firstTenor">The first tenor (output).</param>
        /// <param name="secondTenor">The second tenor (output).</param>
        /// <param name="firstTenorDescription">The description of <paramref name="firstTenor"/>; perhaps <c>null</c> (output).</param>
        /// <param name="secondTenorDescription">The description of <paramref name="secondTenor"/>; perhaps <c>null</c> (output).</param>
        /// <param name="stringRepresentationUsage">The string representation usage, i.e. the delimiter used for the <see cref="TenorTimeSpanSpread.ToString()"/> method (output).</param>
        /// <returns>A value indicating whether <paramref name="firstTenor"/>, <paramref name="secondTenor"/>, <paramref name="firstTenorDescription"/> and <paramref name="secondTenorDescription"/> contains valid data.</returns>
        private static bool TryParse(string tenorSpreadString, out TenorTimeSpan firstTenor, out TenorTimeSpan secondTenor, out string firstTenorDescription, out string secondTenorDescription, out StringRepresentationUsage stringRepresentationUsage)
        {
            if (tenorSpreadString == null)
            {
                throw new ArgumentNullException("tenorSpreadString");
            }
            string tenorSpreadIDString = tenorSpreadString.ToIDString();

            firstTenor                = secondTenor = TenorTimeSpan.Null;
            firstTenorDescription     = secondTenorDescription = String.Empty;
            stringRepresentationUsage = StringRepresentationUsage.Minus;

            if (((tenorSpreadIDString.Length == 1) && (tenorSpreadIDString[0] == '0')) || (tenorSpreadIDString == sm_NullIdentifierStringRepresentation.IDString))
            {
                return(true);  // special: '0' and "<null>" will be interpreted as 'null'
            }

            int delimiterIndex = tenorSpreadString.IndexOf('-');

            if (delimiterIndex >= 0)
            {
                if (TryParse(tenorSpreadString.Substring(0, delimiterIndex), out firstTenor, out firstTenorDescription) == false)
                {
                    return(false);
                }
                return(TryParse(tenorSpreadString.Substring(delimiterIndex + 1, tenorSpreadString.Length - delimiterIndex - 1), out secondTenor, out secondTenorDescription));
            }

            delimiterIndex = tenorSpreadString.IndexOf('v');  // first character of "vs."
            if (delimiterIndex < 0)
            {
                return(TryParse(tenorSpreadString, out firstTenor, out firstTenorDescription));
            }
            else if (TryParse(tenorSpreadString.Substring(0, delimiterIndex), out firstTenor, out firstTenorDescription) == false)
            {
                return(false);
            }

            if ((delimiterIndex + 2 < tenorSpreadString.Length) && (tenorSpreadString[delimiterIndex + 1] == 's') && (tenorSpreadString[delimiterIndex + 2] == '.'))
            {
                stringRepresentationUsage = StringRepresentationUsage.Versus;

                return(TryParse(tenorSpreadString.Substring(delimiterIndex + 3, tenorSpreadString.Length - delimiterIndex - 3), out secondTenor, out secondTenorDescription));
            }
            return(false);
        }
        /// <summary>Adds a specific <see cref="TenorTimeSpan"/> object to a specific <see cref="System.DateTime"/> object.
        /// </summary>
        /// <param name="startDate">The start date.</param>
        /// <param name="tenorTimeSpan">The time span to add in its <see cref="TenorTimeSpan"/> representation.</param>
        /// <returns>The <see cref="System.DateTime"/> which is the result of <paramref name="startDate"/> plus <paramref name="tenorTimeSpan"/>.</returns>
        /// <remarks>If <paramref name="tenorTimeSpan"/> is equal to <see cref="TenorTimeSpan.TomorrowNextTenor"/>, two (2) days will be added to <paramref name="startDate"/>.</remarks>
        public static DateTime AddTenorTimeSpan(this DateTime startDate, TenorTimeSpan tenorTimeSpan)
        {
            DateTime date = startDate;

            if (tenorTimeSpan.Years != 0)
            {
                date = date.AddYears(tenorTimeSpan.Years);
            }
            if (tenorTimeSpan.Months != 0)
            {
                date = date.AddMonths(tenorTimeSpan.Months);
            }
            if (tenorTimeSpan.Days != 0)
            {
                date = date.AddDays(tenorTimeSpan.Days);
            }
            return(date);
        }
Exemplo n.º 7
0
        /// <summary>Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <param name="stringRepresentationUsage">The string representation usage.</param>
        /// <returns>A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public string ToString(StringRepresentationUsage stringRepresentationUsage)
        {
            if ((TenorTimeSpan.IsNull(FirstTenor) == true) && (TenorTimeSpan.IsNull(SecondTenor) == true) && (FirstTenorDescription == null || FirstTenorDescription.Length == 0) && (SecondTenorDescription == null || SecondTenorDescription.Length == 0))
            {
                return(sm_NullIdentifierStringRepresentation.String);
            }

            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(FirstTenor.ToString());
            if ((FirstTenorDescription != null) && (FirstTenorDescription.Length > 0))
            {
                if (strBuilder.Length > 0)
                {
                    strBuilder.Append(" ");
                }
                strBuilder.Append(String.Format(" [{0}]", FirstTenorDescription));
            }

            if ((TenorTimeSpan.IsNull(SecondTenor) == false) || (SecondTenorDescription != null && SecondTenorDescription.Length > 0))
            {
                switch (stringRepresentationUsage)
                {
                case StringRepresentationUsage.Versus:
                    strBuilder.Append(String.Format(" vs. {0}", SecondTenor.ToString()));
                    break;

                case StringRepresentationUsage.Minus:
                    strBuilder.Append(String.Format(" - {0}", SecondTenor.ToString()));
                    break;

                default:
                    throw new NotImplementedException();
                }
                if ((SecondTenorDescription != null) && (SecondTenorDescription.Length > 0))
                {
                    strBuilder.Append(String.Format(" [{0}]", SecondTenorDescription));
                }
            }
            return(strBuilder.ToString());
        }
Exemplo n.º 8
0
        /// <summary>Converts a <see cref="System.String"/> object into a <see cref="TenorTimeSpan"/> object and its optional description.
        /// </summary>
        /// <param name="tenorWithDescription">The tenor with [optional] description in its <see cref="System.String"/> representation.</param>
        /// <param name="tenor">The tenor (output).</param>
        /// <param name="tenorDescription">The description (output).</param>
        /// <returns>A value indicating whether <paramref name="tenor"/> and <paramref name="tenorDescription"/> contains valid data.</returns>
        private static bool TryParse(string tenorWithDescription, out TenorTimeSpan tenor, out string tenorDescription)
        {
            int descriptionStartIndex = tenorWithDescription.IndexOf('[');

            if (descriptionStartIndex < 0)
            {
                tenorDescription = String.Empty;
                return(TenorTimeSpan.TryParse(tenorWithDescription, out tenor));
            }
            int descriptionEndIndex = tenorWithDescription.LastIndexOf(']');

            if (descriptionEndIndex < descriptionStartIndex)
            {
                tenorDescription = String.Empty;
                tenor            = TenorTimeSpan.Null;
                return(false);
            }
            string tenorString = tenorWithDescription.Substring(0, descriptionStartIndex);

            tenorDescription = tenorWithDescription.Substring(descriptionStartIndex + 1, descriptionEndIndex - descriptionStartIndex - 1);
            return(TenorTimeSpan.TryParse(tenorString, out tenor));
        }
Exemplo n.º 9
0
 /// <summary>Initializes a new instance of the <see cref="ExpiryTenorTimeSpan"/> struct.
 /// </summary>
 /// <param name="expiryTimeSpan">The expiry time span of some swaption.</param>
 /// <param name="tenorTimeSpan">The tenor (maturity) time span of some swap/swaption.</param>
 public ExpiryTenorTimeSpan(TenorTimeSpan expiryTimeSpan, TenorTimeSpan tenorTimeSpan)
 {
     ExpiryTimeSpan = expiryTimeSpan;
     TenorTimeSpan  = tenorTimeSpan;
 }
Exemplo n.º 10
0
 /// <summary>Determines whether a specified <see cref="TenorTimeSpanSpread"/> object is a spread, i.e. <see cref="TenorTimeSpanSpread.FirstTenor"/> and <see cref="TenorTimeSpanSpread.SecondTenor"/> is <b>not</b> <see cref="TenorTimeSpan.Null"/>.
 /// </summary>
 /// <param name="tenorTimeSpanSpread">The <see cref="TenorTimeSpanSpread"/> object.</param>
 /// <returns><c>true</c> if both <see cref="TenorTimeSpan"/> objects of <paramref name="tenorTimeSpanSpread"/> are distinct from <see cref="TenorTimeSpan.Null"/>; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsSpread(TenorTimeSpanSpread tenorTimeSpanSpread)
 {
     return((TenorTimeSpan.IsNull(tenorTimeSpanSpread.FirstTenor) == false) && (TenorTimeSpan.IsNull(tenorTimeSpanSpread.SecondTenor) == false));
 }
Exemplo n.º 11
0
 /// <summary>Determines whether a specified <see cref="TenorTimeSpanSpread"/> object has a length of <c>0</c>, i.e. <see cref="TenorTimeSpanSpread.FirstTenor"/> = <see cref="TenorTimeSpanSpread.SecondTenor"/> = <see cref="TenorTimeSpan.Null"/>.
 /// </summary>
 /// <param name="tenorTimeSpanSpread">The <see cref="TenorTimeSpanSpread"/> object.</param>
 /// <returns><c>true</c> if both <see cref="TenorTimeSpan"/> objects of <paramref name="tenorTimeSpanSpread"/> are equal to <see cref="TenorTimeSpan.Null"/>; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsNull(TenorTimeSpanSpread tenorTimeSpanSpread)
 {
     return(TenorTimeSpan.IsNull(tenorTimeSpanSpread.FirstTenor) && (TenorTimeSpan.IsNull(tenorTimeSpanSpread.SecondTenor)));
 }
Exemplo n.º 12
0
 /// <summary>Adds a specific <see cref="TenorTimeSpan"/> object to the current instance.
 /// </summary>
 /// <param name="tenorTimeSpan">The tenor time span.</param>
 /// <param name="tenorTimeSpanToAdd">The <see cref="TenorTimeSpan"/> to add.</param>
 /// <param name="tenorTimeSpanFactor">A (optional) factor to take into account.</param>
 /// <returns>A <see cref="TenorTimeSpan"/> object which is the result of <paramref name="tenorTimeSpan"/> plus <paramref name="tenorTimeSpanFactor"/> * <paramref name="tenorTimeSpanToAdd"/>.</returns>
 /// <remarks>If <paramref name="tenorTimeSpanToAdd"/> is equal to <see cref="TenorTimeSpan.TomorrowNextTenor"/>, two (2) [times <paramref name="tenorTimeSpanFactor"/>] days will be added to <paramref name="tenorTimeSpan"/>.</remarks>
 public static TenorTimeSpan AddTimeSpan(this TenorTimeSpan tenorTimeSpan, TenorTimeSpan tenorTimeSpanToAdd, int tenorTimeSpanFactor = 1)
 {
     return(new TenorTimeSpan(tenorTimeSpan.Years + tenorTimeSpanFactor * tenorTimeSpanToAdd.Years, tenorTimeSpan.Months + tenorTimeSpanFactor * tenorTimeSpanToAdd.Months, tenorTimeSpan.Days + tenorTimeSpanFactor * tenorTimeSpanToAdd.Days));
 }
Exemplo n.º 13
0
 /// <summary>Converts a <see cref="TenorTimeSpan"/> object into its <see cref="IDateScheduleFrequency"/> representation.
 /// </summary>
 /// <param name="tenorTimeSpan">The tenor time span.</param>
 /// <returns>A <see cref="IDateScheduleFrequency"/> object which represent the <paramref name="tenorTimeSpan"/>.</returns>
 public static IDateScheduleFrequency AsFrequency(this TenorTimeSpan tenorTimeSpan)
 {
     return(new IndividualDateScheduleFrequency(tenorTimeSpan));
 }