public static RelativeDateOffset Create(string period, DayTypeEnum dayType,
                                                string businessDayConventionAsString,
                                                BusinessCenters businessCenters,
                                                string dateRelativeTo)
        {
            var    result   = new RelativeDateOffset();
            Period interval = PeriodHelper.Parse(period);

            result.period           = interval.period;
            result.periodSpecified  = true;
            result.periodMultiplier = interval.periodMultiplier;
            result.dayType          = dayType;
            result.dayTypeSpecified = true;
            if (businessDayConventionAsString != null)
            {
                result.businessDayConvention          = BusinessDayConventionHelper.Parse(businessDayConventionAsString);
                result.businessDayConventionSpecified = true;
            }
            result.businessCenters = businessCenters;
            if (dateRelativeTo != null)
            {
                var dateReference = new DateReference {
                    href = dateRelativeTo
                };
                result.dateRelativeTo = dateReference;
            }
            return(result);
        }
        /// <summary>
        /// Advances the specified calendars.
        /// </summary>
        /// <param name="businessCalendar">The calendars.</param>
        /// <param name="date">The date.</param>
        /// <param name="dayTypeString">The day type string.</param>
        /// <param name="periodInterval">The period interval.</param>
        /// <param name="businessDayConvention">The business day convention.</param>
        /// <returns></returns>
        public static DateTime Advance(IBusinessCalendar businessCalendar, DateTime date, string dayTypeString, string periodInterval, string businessDayConvention)
        {
            //IBusinessCalendar calendar = GetCalendar(calendars, ruleFullFilePath);
            Period interval = PeriodHelper.Parse(periodInterval);
            var    dayType  = DayTypeEnum.Calendar;

            if (dayTypeString.Length > 0)
            {
                dayType = (DayTypeEnum)Enum.Parse(typeof(DayTypeEnum), dayTypeString, true);
            }
            Offset offset = OffsetHelper.FromInterval(interval, dayType);
            BusinessDayConventionEnum dayConvention = BusinessDayConventionHelper.Parse(businessDayConvention);

            return(businessCalendar.Advance(date, offset, dayConvention));
        }
示例#3
0
        private void AddCashFlows(ILogger logger, ICoreCache cache,
                                  IBusinessCalendar fixingCalendar,
                                  IBusinessCalendar paymentCalendar,
                                  Fra fraFpML, bool isBuyer, String nameSpace)
        {
            EffectiveDate   = fraFpML.adjustedEffectiveDate.Value;
            TerminationDate = fraFpML.adjustedTerminationDate;
            if (paymentCalendar == null)
            {
                paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, fraFpML.paymentDate.dateAdjustments.businessCenters, nameSpace);
            }
            if (fixingCalendar == null)
            {
                fixingCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, fraFpML.fixingDateOffset.businessCenters, nameSpace);
            }
            DateTime unadjustedPaymentDate = fraFpML.paymentDate.unadjustedDate.Value;
            var      notional = MoneyHelper.GetAmount(fraFpML.notional.amount, fraFpML.notional.currency);

            PaymentDate = paymentCalendar.Roll(unadjustedPaymentDate, BusinessDayConventionHelper.Parse(fraFpML.paymentDate.dateAdjustments.businessDayConvention.ToString()));
            DateTime adjustedFixingDate = GetResetDate(logger, cache, fixingCalendar, fraFpML, nameSpace);
            var      interval           = fraFpML.indexTenor[0];
            var      floatingInterest   = new PriceableFloatingRateCoupon(fraFpML.id + "FloatingCoupon_1"
                                                                          , isBuyer
                                                                          , EffectiveDate
                                                                          , TerminationDate
                                                                          , adjustedFixingDate
                                                                          , fraFpML.dayCountFraction
                                                                          , 0.0m
                                                                          , FixedRate
                                                                          , null
                                                                          , isBuyer ? MoneyHelper.Neg(notional) : notional
                                                                          , PaymentDate
                                                                          , new ForecastRateIndex {
                floatingRateIndex = fraFpML.floatingRateIndex, indexTenor = interval
            }
                                                                          , null
                                                                          , null
                                                                          , fraFpML.fraDiscounting
                                                                          , paymentCalendar
                                                                          , fixingCalendar)
            {
                ForecastRateInterpolation = ForecastRateInterpolation
            };

            // Combine two cashflows into one leg
            //
            FloatingCoupon = floatingInterest;//fraFpML.fraDiscounting,
        }
示例#4
0
        /// <summary>
        /// Converts t an adjustable date type.
        /// </summary>
        /// <param name="unadjustedDate"></param>
        /// <param name="businessDayConventionAsString"></param>
        /// <returns></returns>
        public static AdjustableDate ToAdjustableDate(DateTime unadjustedDate, string businessDayConventionAsString)
        {
            var result = new AdjustableDate {
                unadjustedDate = ToUnadjustedIdentifiedDate(unadjustedDate)
            };
            var businessDayAdjustments = new BusinessDayAdjustments
            {
                businessDayConvention =
                    BusinessDayConventionHelper.Parse(
                        businessDayConventionAsString),
                businessDayConventionSpecified = true
            };

            result.dateAdjustments = businessDayAdjustments;
            return(result);
        }
示例#5
0
        /// <summary>
        /// Adds the period.
        /// </summary>
        /// <param name="startDate">The start date.</param>
        /// <param name="tenorString">The tenor string.</param>
        /// <param name="calendar">The calendar.</param>
        /// <param name="rollConvention">The roll convention.</param>
        /// <param name="dayType">Type of the day.</param>
        /// <returns></returns>
        public static DateTime AddPeriod(DateTime startDate, string tenorString, IBusinessCalendar calendar, string rollConvention, string dayType)
        {
            const string defaultRollConvention = "FOLLOWING";

            if (calendar == null)
            {
                calendar = new Hell();
            }
            if (String.IsNullOrEmpty(rollConvention))
            {
                rollConvention = defaultRollConvention;
            }
            Period rollPeriod = PeriodHelper.Parse(tenorString);

            if (String.IsNullOrEmpty(dayType))
            {
                dayType = DayTypeStringFromRollPeriodInterval(rollPeriod);
            }
            var dayTypeEnum = (DayTypeEnum)Enum.Parse(typeof(DayTypeEnum), dayType, true);
            BusinessDayConventionEnum businessDayConvention = BusinessDayConventionHelper.Parse(rollConvention);
            DateTime endDate = calendar.Advance(startDate, OffsetHelper.FromInterval(rollPeriod, dayTypeEnum), businessDayConvention);

            return(endDate);
        }
        /// <summary>
        /// Rolls the specified date using the underlying calendars.
        /// </summary>
        /// <param name="businessCalendar">The calendars.</param>
        /// <param name="date">The date.</param>
        /// <param name="businessDayConvention">The business day convention.</param>
        /// <returns></returns>
        public static DateTime Roll(IBusinessCalendar businessCalendar, DateTime date, string businessDayConvention)
        {
            BusinessDayConventionEnum dayConvention = BusinessDayConventionHelper.Parse(businessDayConvention);

            return(businessCalendar.Roll(date, dayConvention));
        }
示例#7
0
 public static BusinessDayAdjustments Create(string businessDayConventionAsString, string businessCentersAsString)
 {
     return(Create(BusinessDayConventionHelper.Parse(businessDayConventionAsString), businessCentersAsString));
 }