Exemplo n.º 1
0
        /// <summary>
        /// Converts to an adjustable date type.
        /// </summary>
        /// <param name="unadjustedDate"></param>
        /// <param name="businessDayConvention"></param>
        /// <param name="businessCentersAsString"></param>
        /// <returns></returns>
        public static AdjustableDate ToAdjustableDate(DateTime unadjustedDate, BusinessDayConventionEnum businessDayConvention, string businessCentersAsString)
        {
            AdjustableDate result = ToAdjustableDate(unadjustedDate, businessDayConvention);

            result.dateAdjustments.businessCenters = BusinessCentersHelper.Parse(businessCentersAsString);
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Find the next business day with respect to the given date and
        /// rolling convention.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <param name="businessDayConvention">The business day convention.</param>
        /// <returns>Returns the resulting <see cref="DateTime"/>.</returns>
        public DateTime Roll(DateTime date, BusinessDayConventionEnum businessDayConvention)
        {
            // QL_REQUIRE(d!=Date(), "Calendar::roll : null date");
            DateTime rolledDate = date;

            if (businessDayConvention == BusinessDayConventionEnum.FOLLOWING || businessDayConvention == BusinessDayConventionEnum.MODFOLLOWING)
            {
                while (IsHoliday(rolledDate))
                {
                    rolledDate = Calendar.AddDays(rolledDate, 1);
                }
                if (businessDayConvention == BusinessDayConventionEnum.MODFOLLOWING && rolledDate.Month != date.Month)
                {
                    return(Roll(date, BusinessDayConventionEnum.PRECEDING));
                }
            }
            else if (businessDayConvention == BusinessDayConventionEnum.PRECEDING || businessDayConvention == BusinessDayConventionEnum.MODPRECEDING)
            {
                while (IsHoliday(rolledDate))
                {
                    rolledDate = Calendar.AddDays(rolledDate, -1);
                }
                if (businessDayConvention == BusinessDayConventionEnum.MODPRECEDING && rolledDate.Month != date.Month)
                {
                    return(Roll(date, BusinessDayConventionEnum.FOLLOWING));
                }
            }
            else if (businessDayConvention != BusinessDayConventionEnum.NONE)
            {
                throw new ArgumentOutOfRangeException(nameof(businessDayConvention), "Unknown rolling convention.");
            }

            return(rolledDate);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableRateCoupon"/> class.
 /// </summary>
 /// <param name="cashflowId">The stream id.</param>
 /// <param name="payerIsBase">The payer is base flag.</param>
 /// <param name="accrualStartDate">The accrual start date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="accrualEndDate">The accrual end date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="adjustCalculationDatesIndicator">if set to <c>true</c> [adjust calculation dates indicator].</param>
 /// <param name="accrualBusinessCenters">The accrual business centers.</param>
 /// <param name="fixedRate">The fixed rate.</param>
 /// <param name="notionalAmount">The notional amount.</param>
 /// <param name="dayCountFraction">Type of day Count fraction.</param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="accrualRollConvention">The accrual roll convention.</param>
 /// <param name="discountingType">The swap discounting type.</param>
 /// <param name="discountRate">The discount rate.</param>
 /// <param name="fraDiscounting">Determines whether the coupon is discounted or not. If this parameter is null,
 /// then it is assumed that there is no fra discounting</param>
 /// <param name="paymentCalendar">The paymentCalendar.</param>
 public PriceableFixedRateCoupon
 (
     string cashflowId
     , bool payerIsBase
     , DateTime accrualStartDate
     , DateTime accrualEndDate
     , bool adjustCalculationDatesIndicator
     , BusinessCenters accrualBusinessCenters
     , BusinessDayConventionEnum accrualRollConvention
     , DayCountFraction dayCountFraction
     , decimal fixedRate
     , Money notionalAmount
     , AdjustableOrAdjustedDate paymentDate
     , DiscountingTypeEnum?discountingType
     , decimal?discountRate
     , FraDiscountingEnum?fraDiscounting
     , IBusinessCalendar paymentCalendar)
     : base(cashflowId, CouponType.FixedRate, payerIsBase, accrualStartDate, accrualEndDate, adjustCalculationDatesIndicator,
            accrualBusinessCenters, accrualRollConvention, dayCountFraction, fixedRate, notionalAmount, paymentDate,
            discountingType, discountRate, fraDiscounting, paymentCalendar)
 {
     Id = cashflowId;
     CalculatePaymentAmount(0);
     ForecastAmount = PaymentAmount;
 }
 public DateOffset(XmlNode xmlNode)
 : base(xmlNode)
 {
     XmlNodeList businessDayConventionNodeList = xmlNode.SelectNodes("businessDayConvention");
     if (businessDayConventionNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in businessDayConventionNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 businessDayConventionIDRef = item.Attributes["id"].Name;
                 BusinessDayConventionEnum ob = BusinessDayConventionEnum();
                 IDManager.SetID(businessDayConventionIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 businessDayConventionIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 businessDayConvention = new BusinessDayConventionEnum(item);
             }
         }
     }
     
 
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableFxRateCashflow"/> class.
 /// </summary>
 /// <param name="cashlfowId">The stream id.</param>
 /// <param name="payerIsBase">The payer is base flag.</param>
 /// <param name="accrualStartDate">The accrual start date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="accrualEndDate">The accrual end date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="adjustAccrualDatesIndicator">if set to <c>true</c> [adjust calculation dates indicator].</param>
 /// <param name="accrualBusinessCenters">The accrual business centers.</param>
 /// <param name="margin">The margin.</param>
 /// <param name="baseRate">The base rate for a nettable fixed/floating cash flow. </param>
 /// <param name="observedRate">The observed Rate.</param>
 /// <param name="notionalAmount">The notional amount.</param>
 /// <param name="dayCountfraction">Type of day Countfraction.</param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="accrualRollConvention">The accrual roll convention.</param>
 /// <param name="resetRelativeTo">reset relative to?</param>
 /// <param name="fixingDateRelativeOffset">The fixing date offset.</param>
 /// <param name="forecastRateIndex">The forecastrateindex.</param>
 /// <param name="discountingType">The swap discounting type.</param>
 /// <param name="discountRate">The discount rate.</param>
 /// <param name="fraDiscounting">Determines whether the coupon is discounted or not. If this parameter is null,
 /// then it is assumed that there is no fradiscounting</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="paymentCalendar">The paymentCalendar.</param>
 public PriceableFloatingRateCoupon
 (
     string cashlfowId
     , bool payerIsBase
     , DateTime accrualStartDate
     , DateTime accrualEndDate
     , Boolean adjustAccrualDatesIndicator
     , BusinessCenters accrualBusinessCenters
     , BusinessDayConventionEnum accrualRollConvention
     , DayCountFraction dayCountfraction
     , ResetRelativeToEnum resetRelativeTo
     , RelativeDateOffset fixingDateRelativeOffset
     , Decimal margin
     , Decimal baseRate
     , Decimal?observedRate
     , Money notionalAmount
     , AdjustableOrAdjustedDate paymentDate
     , ForecastRateIndex forecastRateIndex
     , DiscountingTypeEnum?discountingType
     , Decimal?discountRate
     , FraDiscountingEnum?fraDiscounting
     , IBusinessCalendar fixingCalendar
     , IBusinessCalendar paymentCalendar)
     : base(
         cashlfowId
         , CouponType.FloatingRate
         , payerIsBase
         , accrualStartDate
         , accrualEndDate
         , adjustAccrualDatesIndicator
         , accrualBusinessCenters
         , accrualRollConvention
         , dayCountfraction
         , observedRate
         , notionalAmount
         , paymentDate
         , discountingType
         , discountRate
         , fraDiscounting
         , paymentCalendar)
 {
     BaseRate        = baseRate;
     FixingCalendar  = fixingCalendar;
     ModelIdentifier = "DualCurveCouponModel";
     Id = cashlfowId;
     ForwardStartDate         = AccrualStartDate;
     ForecastRateIndex        = forecastRateIndex;
     FixingDateRelativeOffset = fixingDateRelativeOffset;
     ResetRelativeTo          = resetRelativeTo;
     Margin             = margin;
     AdjustedFixingDate = GetResetDate(resetRelativeTo, fixingDateRelativeOffset);
     if (observedRate != null)
     {
         RateObservation = RateObservationHelper.Parse(AdjustedFixingDate, (decimal)observedRate, "1");
     }
     SetRateObservation(RateObservation, ResetDate);
     ForecastCurveName = CurveNameHelpers.GetForecastCurveName(forecastRateIndex);
 }
Exemplo n.º 6
0
        public static BusinessDayAdjustments Create(BusinessDayConventionEnum businessDayConvention, BusinessCenters businessCenters)
        {
            var result = new BusinessDayAdjustments
            {
                businessDayConvention = businessDayConvention,
                businessCenters       = businessCenters
            };

            return(result);
        }
Exemplo n.º 7
0
        public static BusinessDayAdjustments Create(BusinessDayConventionEnum businessDayConvention, string businessCentersAsString)
        {
            var result = new BusinessDayAdjustments
            {
                businessDayConvention = businessDayConvention,
                businessCenters       =
                    BusinessCentersHelper.Parse(businessCentersAsString)
            };

            return(result);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Converts t an adjustable date type.
        /// </summary>
        /// <param name="unadjustedDate"></param>
        /// <param name="businessDayConvention"></param>
        /// <returns></returns>
        public static AdjustableDate ToAdjustableDate(DateTime unadjustedDate, BusinessDayConventionEnum businessDayConvention)
        {
            var result = new AdjustableDate {
                unadjustedDate = ToUnadjustedIdentifiedDate(unadjustedDate)
            };
            var businessDayAdjustments = new BusinessDayAdjustments
            {
                businessDayConvention          = businessDayConvention,
                businessDayConventionSpecified = true
            };

            result.dateAdjustments = businessDayAdjustments;
            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));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableFxRateCashflow"/> class.
 /// </summary>
 /// <param name="cashlfowId">The stream id.</param>
 /// <param name="payerIsBase">The payer is base flag.</param>
 /// <param name="accrualStartDate">The accrual start date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="accrualEndDate">The accrual end date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="adjustAccrualDatesIndicator">if set to <c>true</c> [adjust calculation dates indicator].</param>
 /// <param name="accrualBusinessCenters">The accrual business centers.</param>
 /// <param name="margin">The margin.</param>
 /// <param name="observedRate">The observed Rate.</param>
 /// <param name="notionalAmount">The notional amount.</param>
 /// <param name="dayCountfraction">Type of day Countfraction.</param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="accrualRollConvention">The accrual roll convention.</param>
 /// <param name="resetRelativeTo">reset relative to?</param>
 /// <param name="fixingDateRelativeOffset">The fixing date offset.</param>
 /// <param name="forecastRateIndex">The forecastrateindex.</param>
 /// <param name="discountingType">The swap discounting type.</param>
 /// <param name="discountRate">The discount rate.</param>
 /// <param name="fraDiscounting">Determines whether the coupon is discounted or not. If this parameter is null,
 /// then it is assumed that there is no fradiscounting</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="paymentCalendar">The paymentCalendar.</param>
 public PriceableFloatingRateCoupon
 (
     string cashlfowId
     , bool payerIsBase
     , DateTime accrualStartDate
     , DateTime accrualEndDate
     , Boolean adjustAccrualDatesIndicator
     , BusinessCenters accrualBusinessCenters
     , BusinessDayConventionEnum accrualRollConvention
     , DayCountFraction dayCountfraction
     , ResetRelativeToEnum resetRelativeTo
     , RelativeDateOffset fixingDateRelativeOffset
     , Decimal margin
     , Decimal?observedRate
     , Money notionalAmount
     , AdjustableOrAdjustedDate paymentDate
     , ForecastRateIndex forecastRateIndex
     , DiscountingTypeEnum?discountingType
     , Decimal?discountRate
     , FraDiscountingEnum?fraDiscounting
     , IBusinessCalendar fixingCalendar
     , IBusinessCalendar paymentCalendar)
     : this(
         cashlfowId
         , payerIsBase
         , accrualStartDate
         , accrualEndDate
         , adjustAccrualDatesIndicator
         , accrualBusinessCenters
         , accrualRollConvention
         , dayCountfraction
         , resetRelativeTo
         , fixingDateRelativeOffset
         , margin
         , 0.0m
         , observedRate
         , notionalAmount
         , paymentDate
         , forecastRateIndex
         , discountingType
         , discountRate
         , fraDiscounting
         , fixingCalendar
         , paymentCalendar)
 {
 }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableRateCoupon"/> class.
 /// </summary>
 /// <param name="cashlfowId">The stream id.</param>
 /// <param name="accrualStartDate">The accrual start date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="accrualEndDate">The accrual end date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="adjustCalculationDatesIndicator">if set to <c>true</c> [adjust calculation dates indicator].</param>
 /// <param name="accrualBusinessCenters">The accrual business centers.</param>
 /// <param name="underlyingRateIndex">Te underlying rate index can be Xibor or Swap.</param>
 /// <param name="resetLagOffset">This allows for non-standard lags to be used in convexity adjustment calculations.</param>
 /// <param name="margin">The margin.</param>
 /// <param name="observedRate">The observed Rate.</param>
 /// <param name="notionalAmount">The notional amount.</param>
 /// <param name="accrualDayCountfraction">Type of day Countfraction used for the acrual period.</param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="accrualRollConvention">The accrual roll convention.</param>
 /// <param name="resetRelativeTo">reset relative to?</param>
 /// <param name="fixingDateRelativeOffset">The fixing date offset.</param>
 /// <param name="forecastRateIndex">The forecastrateindex.</param>
 /// <param name="discountingType">The swap discounting type.</param>
 /// <param name="discountRate">The discount rate.</param>
 /// <param name="fraDiscounting">Determines whether the coupon is discounted or not. If this parameter is null,
 /// <param name="underlyingRateIndex"></param>
 /// then it is assumed that there is no fradiscounting</param>
 public PriceableStructuredRateCoupon
 (
     string cashlfowId
     , DateTime accrualStartDate
     , DateTime accrualEndDate
     , Boolean adjustCalculationDatesIndicator
     , BusinessCenters accrualBusinessCenters
     , BusinessDayConventionEnum accrualRollConvention
     , DayCountFraction accrualDayCountfraction
     , ResetRelativeToEnum resetRelativeTo
     , RelativeDateOffset fixingDateRelativeOffset
     , RateIndex underlyingRateIndex
     , RelativeDateOffset resetLagOffset
     , Decimal margin
     , Decimal?observedRate
     , Money notionalAmount
     , AdjustableDate paymentDate
     , ForecastRateIndex forecastRateIndex
     , DiscountingTypeEnum?discountingType
     , Decimal?discountRate
     , FraDiscountingEnum?fraDiscounting)
     : base(
         cashlfowId
         , accrualStartDate
         , accrualEndDate
         , adjustCalculationDatesIndicator
         , accrualBusinessCenters
         , accrualRollConvention
         , accrualDayCountfraction
         , resetRelativeTo
         , fixingDateRelativeOffset
         , margin
         , observedRate
         , notionalAmount
         , paymentDate
         , forecastRateIndex
         , discountingType
         , discountRate
         , fraDiscounting
         )
 {
     UnderlyingRateIndex = underlyingRateIndex;
     ResetLagOffset      = resetLagOffset;
     PriceableCouponType = CouponType.StructuredRate;
     AnalyticsModel      = new StructuredRateCouponAnalytic();
 }
Exemplo n.º 12
0
 /// <summary>
 /// Constructor for the class <see cref="SwapRate"/>.</summary>
 /// <param name="logger">The logger.</param>
 /// <param name="cache">The cache.</param>
 /// <param name="nameSpace">The clients namespace</param>
 /// <param name="businessCalendar">Four letter (uppercase) code for
 /// the business calendar that will be used to generate all dates in
 /// the swap schedule.
 /// Example: AUSY.</param>
 /// <param name="calculationDate">Base date.</param>
 /// <param name="dayCount">Three letter (uppercase) code for the day
 /// count convention that will be used to compute the accrual factors.
 /// Example: ACT/365.</param>
 /// <param name="discountFactors">Array of known discount factors.
 /// </param>
 /// <param name="offsets">The number of days from the Calculation
 /// Date to each known discount factor.</param>
 /// <param name="fixedSideFrequency">Roll frequency (number of
 /// rolls/payments per year) on the fixed side of the swap.
 /// Precondition: must be a divisor of 12.
 /// Example: Quarterly corresponds to a frequency of 4; Monthly
 /// corresponds to a frequency of 12.</param>
 /// <param name="rollConvention">Roll convention used to generate
 /// the swap schedule.
 /// Example: MODFOLLOWING.</param>
 public SwapRate(ILogger logger, ICoreCache cache,
                 string nameSpace,
                 string businessCalendar,
                 DateTime calculationDate,
                 string dayCount,
                 double[] discountFactors,
                 int[] offsets,
                 int fixedSideFrequency,
                 BusinessDayConventionEnum rollConvention)
 {
     InitialisePrivateFields(logger, cache,
                             nameSpace,
                             businessCalendar,
                             calculationDate,
                             dayCount,
                             discountFactors,
                             offsets,
                             fixedSideFrequency,
                             rollConvention);
 }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Master function used by the constructor to initialise all
 /// private fields.
 /// </summary>
 /// <param name="logger">The logger.</param>
 /// <param name="cache">The cache.</param>
 /// <param name="nameSpace">The clients namespace</param>
 /// <param name="businessCalendar">Four letter (uppercase) code for
 /// the business calendar that will be used to generate all dates in
 /// the swap schedule.
 /// Example: AUSY.</param>
 /// <param name="calculationDate">Base date.</param>
 /// <param name="dayCount">Three letter (uppercase) code for the day
 /// count convention that will be used to compute the accrual factors.
 /// Example: ACT/365.</param>
 /// <param name="discountFactors">Array of known discount factors.
 /// </param>
 /// <param name="offsets">The number of days from the Calculation
 /// Date to each known discount factor.</param>
 /// <param name="fixedSideFrequency">Roll frequency (number of
 /// rolls/payments per year) on the fixed side of the swap.
 /// Precondition: must be a divisor of 12.
 /// Example: Quarterly corresponds to a frequency of 4; Monthly
 /// corresponds to a frequency of 12.</param>
 /// <param name="rollConvention">Roll convention used to generate
 /// the swap schedule.
 /// Example: MODFOLLOWING.</param>
 private void InitialisePrivateFields
     (ILogger logger, ICoreCache cache,
     string nameSpace,
     string businessCalendar,
     DateTime calculationDate,
     string dayCount,
     double[] discountFactors,
     int[] offsets,
     int fixedSideFrequency,
     BusinessDayConventionEnum rollConvention)
 {
     // Initialise all private fields, except for the one dimensional
     // interpolation object.
     _businessCalendar   = BusinessCenterHelper.ToBusinessCalendar(cache, new[] { businessCalendar }, nameSpace);
     _calculationDate    = calculationDate;
     _discountFactors    = null;
     _dayCount           = dayCount;
     _fixedSideFrequency = fixedSideFrequency;
     _rollConvention     = rollConvention;
     _swapSchedule       = null;
     // Initialise the one dimensional interpolation object.
     InitialiseDiscountFactorObject(discountFactors, offsets);
     logger.LogDebug("Discount factors initialised.");
 }
Exemplo n.º 15
0
        public CapletBootstrapEngineHelperTests()
        {
            const string CalculationDateString = @"2007-11-29";
            const string StartDateString       = @"2007-11-30";
            const bool   ValidateArguments     = true;

            _calculationDate            = DateTime.Parse(CalculationDateString);
            _capFrequency               = CapFrequency.Quarterly;
            _capStartLag                = 1;
            _currency                   = "AUD";
            _handle                     = "Caplet Bootstrap Engine Helper tests";
            _numYears                   = 10.0d;
            _parVolatilityInterpolation =
                ParVolatilityInterpolationType.CubicHermiteSpline;
            _rollConvention = BusinessDayConventionEnum.MODFOLLOWING;
            _startDate      = DateTime.Parse(StartDateString);
            _tolerance      = 1.0E-5d;
            _settingsObj    = new CapletBootstrapSettings
                                  (_calculationDate,
                                  _capFrequency,
                                  _capStartLag,
                                  _currency,
                                  _handle,
                                  _parVolatilityInterpolation,
                                  _rollConvention,
                                  ValidateArguments);

            // Initialise the offsets.
            _offsets = new List <double>();

            foreach (DateTime date in _dates)
            {
                TimeSpan dateDiff = date - _calculationDate;
                _offsets.Add(dateDiff.Days);
            }
        }
Exemplo n.º 16
0
        /// <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));
        }
 public FinalCalculationPeriodDateAdjustment(XmlNode xmlNode)
 {
     XmlNodeList relevantUnderlyingDateReferenceNodeList = xmlNode.SelectNodes("relevantUnderlyingDateReference");
     if (relevantUnderlyingDateReferenceNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in relevantUnderlyingDateReferenceNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 relevantUnderlyingDateReferenceIDRef = item.Attributes["id"].Name;
                 RelevantUnderlyingDateReference ob = RelevantUnderlyingDateReference();
                 IDManager.SetID(relevantUnderlyingDateReferenceIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 relevantUnderlyingDateReferenceIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 relevantUnderlyingDateReference = new RelevantUnderlyingDateReference(item);
             }
         }
     }
     
 
     XmlNodeList swapStreamReferenceNodeList = xmlNode.SelectNodes("swapStreamReference");
     if (swapStreamReferenceNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in swapStreamReferenceNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 swapStreamReferenceIDRef = item.Attributes["id"].Name;
                 InterestRateStreamReference ob = InterestRateStreamReference();
                 IDManager.SetID(swapStreamReferenceIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 swapStreamReferenceIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 swapStreamReference = new InterestRateStreamReference(item);
             }
         }
     }
     
 
     XmlNodeList businessDayConventionNodeList = xmlNode.SelectNodes("businessDayConvention");
     if (businessDayConventionNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in businessDayConventionNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 businessDayConventionIDRef = item.Attributes["id"].Name;
                 BusinessDayConventionEnum ob = BusinessDayConventionEnum();
                 IDManager.SetID(businessDayConventionIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 businessDayConventionIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 businessDayConvention = new BusinessDayConventionEnum(item);
             }
         }
     }
     
 
 }
Exemplo n.º 18
0
        /// <summary>
        /// Adjusted dates from effective date.
        /// </summary>
        /// <param name="effectiveDate">The effective date.</param>
        /// <param name="terminationDate">The termination date.</param>
        /// <param name="periodInterval">The period interval.</param>
        /// <param name="rollConvention">The roll convention.</param>
        /// <param name="businessCalender">The business calender.</param>
        /// <param name="dateAdjustmentConvention">The date adjustment convention.</param>
        /// <returns></returns>
        public static DateTime[] AdjustedDatesFromEffectiveDate(DateTime effectiveDate, DateTime terminationDate, string periodInterval,
                                                                string rollConvention, IBusinessCalendar businessCalender, BusinessDayConventionEnum dateAdjustmentConvention)
        {
            DateTime[]      dateSchedule         = DateScheduler.GetUnadjustedDatesFromEffectiveDate(effectiveDate, terminationDate, PeriodHelper.Parse(periodInterval), RollConventionEnumHelper.Parse(rollConvention), out _, out _);
            List <DateTime> adjustedDateSchedule = GetAdjustedDateSchedule(dateSchedule, dateAdjustmentConvention, businessCalender);

            return(adjustedDateSchedule.ToArray());
        }
Exemplo n.º 19
0
        /// <summary>
        /// Gets the adjusted date schedule.
        /// </summary>
        /// <param name="unadjustedPeriodDates">The unadjusted Dates.</param>
        /// <param name="businessDayConvention">The business day convention.</param>
        /// <param name="paymentCalendar">The payment Calendar.</param>
        /// <returns></returns>
        public static List <DateTime> GetAdjustedDateSchedule(IEnumerable <DateTime> unadjustedPeriodDates, BusinessDayConventionEnum businessDayConvention, IBusinessCalendar paymentCalendar)
        {
            IEnumerable <DateTime> adjustedPeriodDates
                = unadjustedPeriodDates.Select(a => paymentCalendar.Roll(a, businessDayConvention));

            return(adjustedPeriodDates.ToList());
        }
Exemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PriceableCapFloorCoupon"/> class.
 /// </summary>
 /// <param name="cashFlowId">The stream id.</param>
 /// <param name="buyerIsBase">The buyer is base flag.</param>
 /// <param name="capStrike">The Cap strike.</param>
 /// <param name="floorStrike">The floor strike.</param>
 /// <param name="accrualStartDate">The accrual start date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="accrualEndDate">The accrual end date. If adjusted, the adjustCalculationDatesIndicator should be false.</param>
 /// <param name="adjustAccrualDatesIndicator">if set to <c>true</c> [adjust calculation dates indicator].</param>
 /// <param name="accrualBusinessCenters">The accrual business centers.</param>
 /// <param name="margin">The margin.</param>
 /// <param name="observedRate">The observed Rate.</param>
 /// <param name="notionalAmount">The notional amount.</param>
 /// <param name="dayCountFraction">Type of day Count fraction.</param>
 /// <param name="paymentDate">The payment date.</param>
 /// <param name="accrualRollConvention">The accrual roll convention.</param>
 /// <param name="resetRelativeTo">reset relative to?</param>
 /// <param name="fixingDateRelativeOffset">The fixing date offset.</param>
 /// <param name="forecastRateIndex">The forecast rate index.</param>
 /// <param name="discountingType">The swap discounting type.</param>
 /// <param name="discountRate">The discount rate.</param>
 /// <param name="fraDiscounting">Determines whether the coupon is discounted or not. If this parameter is null,
 /// then it is assumed that there is no fra discounting</param>
 /// <param name="fixingCalendar">The fixingCalendar.</param>
 /// <param name="paymentCalendar">The paymentCalendar.</param>
 public PriceableCapFloorCoupon
 (
     string cashFlowId
     , bool buyerIsBase
     , decimal?capStrike
     , decimal?floorStrike
     , DateTime accrualStartDate
     , DateTime accrualEndDate
     , Boolean adjustAccrualDatesIndicator
     , BusinessCenters accrualBusinessCenters
     , BusinessDayConventionEnum accrualRollConvention
     , DayCountFraction dayCountFraction
     , ResetRelativeToEnum resetRelativeTo
     , RelativeDateOffset fixingDateRelativeOffset
     , Decimal margin
     , Decimal?observedRate
     , Money notionalAmount
     , AdjustableOrAdjustedDate paymentDate
     , ForecastRateIndex forecastRateIndex
     , DiscountingTypeEnum?discountingType
     , Decimal?discountRate
     , FraDiscountingEnum?fraDiscounting
     , IBusinessCalendar fixingCalendar
     , IBusinessCalendar paymentCalendar)
     : base(
         cashFlowId
         , buyerIsBase
         , accrualStartDate
         , accrualEndDate
         , adjustAccrualDatesIndicator
         , accrualBusinessCenters
         , accrualRollConvention
         , dayCountFraction
         , resetRelativeTo
         , fixingDateRelativeOffset
         , margin
         , observedRate
         , notionalAmount
         , paymentDate
         , forecastRateIndex
         , discountingType
         , discountRate
         , fraDiscounting
         , fixingCalendar
         , paymentCalendar)
 {
     CapStrike             = capStrike;
     FloorStrike           = floorStrike;
     VolatilitySurfaceName = CurveNameHelpers.GetRateVolatilityMatrixName(forecastRateIndex);
     if (capStrike != null && floorStrike == null)
     {
         PriceableCouponType = CouponType.Cap;
         ModelIdentifier     = "DualCurveCapModel";
         IsCall = true;
     }
     if (floorStrike != null && capStrike == null)
     {
         PriceableCouponType = CouponType.Floor;
         ModelIdentifier     = "DualCurveFloorModel";
     }
     if (floorStrike != null && capStrike != null)
     {
         PriceableCouponType = CouponType.Collar;
         ModelIdentifier     = "DualCurveCollarModel";
     }
 }
Exemplo n.º 21
0
 /// <summary>
 /// Advances the given date the given offset.
 /// </summary>
 /// <param name="date">The <see cref="DateTime"/> that is to be advanced.</param>
 /// <param name="offset">The <see cref="Offset"/> that the given date is advanced.</param>
 /// <param name="businessDayConvention">The <see cref="BusinessDayConventionEnum"/> to use.</param>
 /// <returns>Returns the resulting <see cref="DateTime"/>.</returns>
 public DateTime Advance(DateTime date, Offset offset, BusinessDayConventionEnum businessDayConvention)
 {
     return(Advance(date, int.Parse(offset.periodMultiplier), offset.period, offset.dayType, businessDayConvention));
 }
 public StockIndex(XmlNode xmlNode)
 {
     XmlNodeList codeNodeList = xmlNode.SelectNodes("code");
     if (codeNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in codeNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 codeIDRef = item.Attributes["id"].Name;
                 XsdTypeToken ob = XsdTypeToken();
                 IDManager.SetID(codeIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 codeIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 code = new XsdTypeToken(item);
             }
         }
     }
     
 
     XmlNodeList nameNodeList = xmlNode.SelectNodes("name");
     if (nameNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in nameNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 nameIDRef = item.Attributes["id"].Name;
                 XsdTypeToken ob = XsdTypeToken();
                 IDManager.SetID(nameIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 nameIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 name = new XsdTypeToken(item);
             }
         }
     }
     
 
     XmlNodeList indexTypeNodeList = xmlNode.SelectNodes("indexType");
     if (indexTypeNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in indexTypeNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 indexTypeIDRef = item.Attributes["id"].Name;
                 XsdTypeToken ob = XsdTypeToken();
                 IDManager.SetID(indexTypeIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 indexTypeIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 indexType = new XsdTypeToken(item);
             }
         }
     }
     
 
     XmlNodeList businessDayConventionNodeList = xmlNode.SelectNodes("businessDayConvention");
     if (businessDayConventionNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in businessDayConventionNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 businessDayConventionIDRef = item.Attributes["id"].Name;
                 BusinessDayConventionEnum ob = BusinessDayConventionEnum();
                 IDManager.SetID(businessDayConventionIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 businessDayConventionIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 businessDayConvention = new BusinessDayConventionEnum(item);
             }
         }
     }
     
 
     XmlNodeList endOfMonthNodeList = xmlNode.SelectNodes("endOfMonth");
     if (endOfMonthNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in endOfMonthNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 endOfMonthIDRef = item.Attributes["id"].Name;
                 XsdTypeBoolean ob = XsdTypeBoolean();
                 IDManager.SetID(endOfMonthIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 endOfMonthIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 endOfMonth = new XsdTypeBoolean(item);
             }
         }
     }
     
 
     XmlNodeList dayCounterNodeList = xmlNode.SelectNodes("dayCounter");
     if (dayCounterNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in dayCounterNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 dayCounterIDRef = item.Attributes["id"].Name;
                 XsdTypeToken ob = XsdTypeToken();
                 IDManager.SetID(dayCounterIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 dayCounterIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 dayCounter = new XsdTypeToken(item);
             }
         }
     }
     
 
 }
Exemplo n.º 23
0
        /// <summary>
        /// Advances the given <see cref="DateTime"/> the given
        /// <paramref name="periodMultiplier"/> of time <paramref name="period"/>.
        /// </summary>
        /// <param name="date">The <see cref="DateTime"/> that is to be advanced.</param>
        /// <param name="periodMultiplier">The number of time period to advance.</param>
        /// <param name="period">The <see cref="PeriodEnum"/> used.</param>
        /// <param name="dayType">Type of the day.</param>
        /// <param name="businessDayConvention">The business day convention.</param>
        /// <returns>
        /// Returns the resulting <see cref="DateTime"/>.
        /// </returns>
        /// <overloads>
        /// Advances the given <see cref="DateTime"/>.
        /// </overloads>
        private DateTime Advance(DateTime date, int periodMultiplier, PeriodEnum period, DayTypeEnum dayType, BusinessDayConventionEnum businessDayConvention)
        {
            #region Assert validity of parameters

            if ((dayType != DayTypeEnum.Business) & (dayType != DayTypeEnum.Calendar))
            {
                throw new ArgumentOutOfRangeException(nameof(dayType), dayType, "Only 'DayTypeEnum.Business' and 'DayTypeEnum.Calendar' day types are currently supported.");
            }

            //  We can only use Business dayType for days intervals.
            //
            if ((dayType == DayTypeEnum.Business) & (period != PeriodEnum.D))
            {
                throw new NotSupportedException();
            }

            #endregion

            // handling the NONE day convention
            if (businessDayConvention == BusinessDayConventionEnum.NONE)
            {
                // No rolling if multiplier is zero
                if (periodMultiplier == 0)
                {
                    return(date);
                }
                BusinessDayConventionEnum advConvention = periodMultiplier > 0? BusinessDayConventionEnum.FOLLOWING: BusinessDayConventionEnum.PRECEDING;
                return(Advance(date, periodMultiplier, period, dayType, advConvention));
            }

            if (periodMultiplier == 0)
            {
                return(Roll(date, businessDayConvention));
            }
            if ((period == PeriodEnum.D) & DayTypeEnum.Business == dayType) //Business days
            {
                DateTime returnValue = date;
                if (periodMultiplier > 0)
                {
                    while (periodMultiplier > 0)
                    {
                        returnValue = returnValue.AddDays(1);
                        while (IsHoliday(returnValue))
                        {
                            returnValue = returnValue.AddDays(1);
                        }
                        periodMultiplier--;
                    }
                }
                else
                {
                    while (periodMultiplier < 0)
                    {
                        returnValue = returnValue.AddDays(-1);
                        while (IsHoliday(returnValue))
                        {
                            returnValue = returnValue.AddDays(-1);
                        }
                        periodMultiplier++;
                    }
                }

                return(returnValue);
            }
            var interval = new Period {
                period = period, periodMultiplier = periodMultiplier.ToString(CultureInfo.InvariantCulture)
            };
            return(Roll(Add(date, interval), businessDayConvention));
        }
 public FxFixingDate(XmlNode xmlNode)
 : base(xmlNode)
 {
     XmlNodeList businessDayConventionNodeList = xmlNode.SelectNodes("businessDayConvention");
     if (businessDayConventionNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in businessDayConventionNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 businessDayConventionIDRef = item.Attributes["id"].Name;
                 BusinessDayConventionEnum ob = BusinessDayConventionEnum();
                 IDManager.SetID(businessDayConventionIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 businessDayConventionIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 businessDayConvention = new BusinessDayConventionEnum(item);
             }
         }
     }
     
 
     XmlNodeList businessCentersReferenceNodeList = xmlNode.SelectNodes("businessCentersReference");
     if (businessCentersReferenceNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in businessCentersReferenceNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 businessCentersReferenceIDRef = item.Attributes["id"].Name;
                 BusinessCentersReference ob = BusinessCentersReference();
                 IDManager.SetID(businessCentersReferenceIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 businessCentersReferenceIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 businessCentersReference = new BusinessCentersReference(item);
             }
         }
     }
     
 
     XmlNodeList businessCentersNodeList = xmlNode.SelectNodes("businessCenters");
     if (businessCentersNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in businessCentersNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 businessCentersIDRef = item.Attributes["id"].Name;
                 BusinessCenters ob = BusinessCenters();
                 IDManager.SetID(businessCentersIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 businessCentersIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 businessCenters = new BusinessCenters(item);
             }
         }
     }
     
 
     XmlNodeList dateRelativeToPaymentDatesNodeList = xmlNode.SelectNodes("dateRelativeToPaymentDates");
     if (dateRelativeToPaymentDatesNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in dateRelativeToPaymentDatesNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 dateRelativeToPaymentDatesIDRef = item.Attributes["id"].Name;
                 DateRelativeToPaymentDates ob = DateRelativeToPaymentDates();
                 IDManager.SetID(dateRelativeToPaymentDatesIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 dateRelativeToPaymentDatesIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 dateRelativeToPaymentDates = new DateRelativeToPaymentDates(item);
             }
         }
     }
     
 
     XmlNodeList dateRelativeToCalculationPeriodDatesNodeList = xmlNode.SelectNodes("dateRelativeToCalculationPeriodDates");
     if (dateRelativeToCalculationPeriodDatesNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in dateRelativeToCalculationPeriodDatesNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 dateRelativeToCalculationPeriodDatesIDRef = item.Attributes["id"].Name;
                 DateRelativeToCalculationPeriodDates ob = DateRelativeToCalculationPeriodDates();
                 IDManager.SetID(dateRelativeToCalculationPeriodDatesIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 dateRelativeToCalculationPeriodDatesIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 dateRelativeToCalculationPeriodDates = new DateRelativeToCalculationPeriodDates(item);
             }
         }
     }
     
 
 }
 /// <summary>
 /// Gets the forward spot date.
 /// </summary>
 /// <returns></returns>
 protected DateTime GetForwardDate(DateTime spotDate, IBusinessCalendar paymentCalendar, Period tenor, BusinessDayConventionEnum businessDayConvention)
 {
     return(paymentCalendar.Advance(spotDate, OffsetHelper.FromInterval(tenor, DayTypeEnum.Calendar), businessDayConvention));
 }
 public RelativeDateOffset(XmlNode xmlNode)
 : base(xmlNode)
 {
     XmlNodeList businessDayConventionNodeList = xmlNode.SelectNodes("businessDayConvention");
     if (businessDayConventionNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in businessDayConventionNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 businessDayConventionIDRef = item.Attributes["id"].Name;
                 BusinessDayConventionEnum ob = BusinessDayConventionEnum();
                 IDManager.SetID(businessDayConventionIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 businessDayConventionIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 businessDayConvention = new BusinessDayConventionEnum(item);
             }
         }
     }
     
 
     XmlNodeList businessCentersReferenceNodeList = xmlNode.SelectNodes("businessCentersReference");
     if (businessCentersReferenceNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in businessCentersReferenceNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 businessCentersReferenceIDRef = item.Attributes["id"].Name;
                 BusinessCentersReference ob = BusinessCentersReference();
                 IDManager.SetID(businessCentersReferenceIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 businessCentersReferenceIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 businessCentersReference = new BusinessCentersReference(item);
             }
         }
     }
     
 
     XmlNodeList businessCentersNodeList = xmlNode.SelectNodes("businessCenters");
     if (businessCentersNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in businessCentersNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 businessCentersIDRef = item.Attributes["id"].Name;
                 BusinessCenters ob = BusinessCenters();
                 IDManager.SetID(businessCentersIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 businessCentersIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 businessCenters = new BusinessCenters(item);
             }
         }
     }
     
 
     XmlNodeList dateRelativeToNodeList = xmlNode.SelectNodes("dateRelativeTo");
     if (dateRelativeToNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in dateRelativeToNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 dateRelativeToIDRef = item.Attributes["id"].Name;
                 DateReference ob = DateReference();
                 IDManager.SetID(dateRelativeToIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 dateRelativeToIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 dateRelativeTo = new DateReference(item);
             }
         }
     }
     
 
     XmlNodeList adjustedDateNodeList = xmlNode.SelectNodes("adjustedDate");
     if (adjustedDateNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in adjustedDateNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 adjustedDateIDRef = item.Attributes["id"].Name;
                 IdentifiedDate ob = IdentifiedDate();
                 IDManager.SetID(adjustedDateIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 adjustedDateIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 adjustedDate = new IdentifiedDate(item);
             }
         }
     }
     
 
 }
Exemplo n.º 27
0
        /// <summary>
        /// Converts to an adjustable date type.
        /// </summary>
        /// <param name="unadjustedDate"></param>
        /// <param name="businessDayConvention"></param>
        /// <param name="businessCentersAsString"></param>
        /// <returns></returns>
        public static AdjustableOrAdjustedDate ToAdjustableOrAdjustedDate(DateTime unadjustedDate, BusinessDayConventionEnum businessDayConvention, string businessCentersAsString)
        {
            var result = AdjustableOrAdjustedDateHelper.CreateUnadjustedDate(unadjustedDate, businessDayConvention.ToString(), businessCentersAsString);

            return(result);
        }
 public BusinessDayAdjustments(XmlNode xmlNode)
 {
     XmlNodeList businessDayConventionNodeList = xmlNode.SelectNodes("businessDayConvention");
     if (businessDayConventionNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in businessDayConventionNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 businessDayConventionIDRef = item.Attributes["id"].Name;
                 BusinessDayConventionEnum ob = BusinessDayConventionEnum();
                 IDManager.SetID(businessDayConventionIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 businessDayConventionIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 businessDayConvention = new BusinessDayConventionEnum(item);
             }
         }
     }
     
 
     XmlNodeList businessCentersReferenceNodeList = xmlNode.SelectNodes("businessCentersReference");
     if (businessCentersReferenceNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in businessCentersReferenceNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 businessCentersReferenceIDRef = item.Attributes["id"].Name;
                 BusinessCentersReference ob = BusinessCentersReference();
                 IDManager.SetID(businessCentersReferenceIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 businessCentersReferenceIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 businessCentersReference = new BusinessCentersReference(item);
             }
         }
     }
     
 
     XmlNodeList businessCentersNodeList = xmlNode.SelectNodes("businessCenters");
     if (businessCentersNodeList.Count > 1 )
     {
             throw new Exception();
     }
     
     foreach (XmlNode item in businessCentersNodeList)
     {
         if (item.Attributes["href"] != null || item.Attributes["id"] == null) 
         {
             if (item.Attributes["id"] != null) 
             {
                 businessCentersIDRef = item.Attributes["id"].Name;
                 BusinessCenters ob = BusinessCenters();
                 IDManager.SetID(businessCentersIDRef, ob);
             }
             else if (item.Attributes.ToString() == "href")
             {
                 businessCentersIDRef = item.Attributes["href"].Name;
             }
             else
             {
                 businessCenters = new BusinessCenters(item);
             }
         }
     }
     
 
 }