/// <summary> /// Gets the unadjusted 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="firstRegularPeriodStartDate">The first regular period start date.</param> /// <param name="lastRegularPeriodEndDate">The last regular period end date.</param> /// <returns>A vertical arrray of dates.</returns> public object[,] UnadjustedDatesFromEffectiveDate(DateTime effectiveDate, DateTime terminationDate, string periodInterval, string rollConvention, out DateTime firstRegularPeriodStartDate, out DateTime lastRegularPeriodEndDate) { var dates = DateScheduler.UnadjustedDatesFromEffectiveDate(effectiveDate, terminationDate, periodInterval, rollConvention, out firstRegularPeriodStartDate, out lastRegularPeriodEndDate); var result = RangeHelper.ConvertArrayToRange(dates); return(result); }
/// <summary> /// /// </summary> /// <param name="baseDate"></param> /// <param name="bondAsset"></param> /// <param name="notionalAmount"></param> /// <param name="bondCouponType"></param> /// <param name="paymentConvention"></param> /// <param name="fOCalculationMethod"></param> /// <param name="fixingCalendar"></param> /// <param name="paymentCalendar"></param> /// <returns></returns> public static List <PriceableRateCoupon> CreatePriceableBondCoupons(DateTime baseDate, Bond bondAsset, decimal notionalAmount, CouponStreamType bondCouponType, BusinessDayAdjustments paymentConvention, bool fOCalculationMethod, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar) { List <PriceableRateCoupon> result = new List <PriceableRateCoupon>(); //This handles the case of a bond forward used in curve building. if (bondAsset.maturity > baseDate) { var rollConvention = RollConventionEnumHelper.Parse(bondAsset.maturity.Day.ToString(CultureInfo.InvariantCulture)); //var frequency = FrequencyHelper.ToFrequency(bondAsset.paymentFrequency); var unAdjustedPeriodDates = DateScheduler.GetUnadjustedCouponDatesFromMaturityDate(baseDate, bondAsset.maturity, bondAsset.paymentFrequency, rollConvention, out _, out _); var adjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unAdjustedPeriodDates, paymentConvention.businessDayConvention, paymentCalendar).ToArray(); var length = unAdjustedPeriodDates.Length; for (int i = 0; i < length - 1; i++) { var id = "Coupon" + "_" + i; var startDate = unAdjustedPeriodDates[i]; var endDate = unAdjustedPeriodDates[i + 1]; var paymentDate = adjustedPeriodDates[i + 1]; var coupon = CreatePriceableBondCoupon(id, bondAsset, notionalAmount, bondCouponType, startDate, endDate, paymentDate, paymentCalendar); result.Add(coupon); } return(result); } return(result); }
public override DateTime[] GetBucketingDates(DateTime baseDate, Period bucketInterval) { DateTime endDate = FloatingCoupon.AccrualEndDate; var bucketDates = new List <DateTime>(DateScheduler.GetUnadjustedDatesFromTerminationDate(baseDate, endDate, bucketInterval, RollConventionEnum.NONE, out _, out _)); return(bucketDates.ToArray()); }
/// <summary> /// /// </summary> /// <param name="baseDate"></param> /// <param name="bucketInterval"></param> /// <returns></returns> public override DateTime[] GetBucketingDates(DateTime baseDate, Period bucketInterval) { //DateTime endDate = FixedCoupon.AccrualEndDate; var bucketDates = new List <DateTime>(DateScheduler.GetUnadjustedDatesFromEffectiveDate(baseDate, RiskMaturityDate, BucketingInterval, RollConventionEnum.NONE, out _, out _)); return(bucketDates.ToArray()); }
public void UnadjustedDatesFromTermination() { DateTime effectiveDate = new DateTime(2009, 05, 01); DateTime terminationDate = new DateTime(2010, 11, 27); Period periodInterval = PeriodHelper.Parse("3M"); RollConventionEnum rollDayConvention = RollConventionEnum.Item19; DateTime firstRegularPeriodStartDate = effectiveDate; DateTime lastRegularPeriodEndDate = terminationDate; DateTime[] dates = DateScheduler.GetUnadjustedDatesFromTerminationDate(effectiveDate, terminationDate, periodInterval, rollDayConvention, out firstRegularPeriodStartDate, out lastRegularPeriodEndDate); Assert.AreEqual(dates.Length, 7); Assert.AreEqual(firstRegularPeriodStartDate, new DateTime(2009, 08, 19)); Assert.AreEqual(lastRegularPeriodEndDate, new DateTime(2010, 08, 19)); dates = DateScheduler.GetUnadjustedDatesFromTerminationDate(effectiveDate, terminationDate, periodInterval, rollDayConvention, out firstRegularPeriodStartDate, out lastRegularPeriodEndDate); Assert.AreEqual(dates.Length, 7); Assert.AreEqual(firstRegularPeriodStartDate, new DateTime(2009, 08, 19)); Assert.AreEqual(lastRegularPeriodEndDate, new DateTime(2010, 08, 19)); effectiveDate = new DateTime(2009, 11, 16); terminationDate = new DateTime(2011, 11, 28); rollDayConvention = RollConventionEnum.Item29; dates = DateScheduler.GetUnadjustedDatesFromTerminationDate(effectiveDate, terminationDate, periodInterval, rollDayConvention, out firstRegularPeriodStartDate, out lastRegularPeriodEndDate); Assert.AreEqual(dates.Length, 9); Assert.AreEqual(firstRegularPeriodStartDate, new DateTime(2010, 02, 28)); Assert.AreEqual(lastRegularPeriodEndDate, new DateTime(2011, 08, 29)); }
public void DatesScheduleGeneratorGetDatesScheduleNoAdjustment() { DateTime startDate = DateTime.Today; Debug.Print("Start date: {0}", startDate); //BusinessDayAdjustments businessDayAdjustments = BusinessDayAdjustmentsHelper.Create("FOLLOWING", "AUSY-GBLO"); List <Triplet <Period, Period, RollConventionEnum> > metaScheduleDefinition = GetMetaScheduleDefinition(); var metaScheduleDefinitionRange = new List <ThreeStringsRangeItem>(); foreach (Triplet <Period, Period, RollConventionEnum> triplet in metaScheduleDefinition) { var threeStringsRangeItem = new ThreeStringsRangeItem { Value1 = triplet.First.ToString(), Value2 = triplet.Second.ToString(), Value3 = triplet.Third.ToString() }; metaScheduleDefinitionRange.Add(threeStringsRangeItem); } object o = DateScheduler.GetUnadjustedDatesSchedule(metaScheduleDefinitionRange, startDate, ""); //PrintListOfDates(unadjustedDates); Debug.Print("Dates:"); // Debug.Print(ParameterFormatter.FormatObject(o)); }
/// <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()); }
public override DateTime[] GetBucketingDates(DateTime baseDate, Period bucketInterval) { DateTime firstRegularPeriodStartDate; DateTime lastRegularPeriodEndDate; var bucketDates = new List <DateTime>(DateScheduler.GetUnadjustedDatesFromEffectiveDate(baseDate, RiskMaturityDate, BucketingInterval, RollConventionEnum.NONE, out firstRegularPeriodStartDate, out lastRegularPeriodEndDate)); return(bucketDates.ToArray()); }
/// <summary> /// Gets the adjusted date schedule. /// </summary> /// <param name="businessCalendar">The businessCalendar.</param> /// <param name="effectiveDate">The effective date.</param> /// <param name="intervalToTerminationDate">The interval to termination date.</param> /// <param name="periodInterval">The period interval.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <returns></returns> public static List <DateTime> GetAdjustedDateSchedule(DateTime effectiveDate, Period intervalToTerminationDate, Period periodInterval, BusinessDayAdjustments businessDayAdjustments, IBusinessCalendar businessCalendar) { List <DateTime> unadjustedPeriodDates = DateScheduler.GetUnadjustedDateSchedule(effectiveDate, intervalToTerminationDate, periodInterval); IEnumerable <DateTime> adjustedPeriodDates = unadjustedPeriodDates.Select(a => businessCalendar.Roll(a, businessDayAdjustments.businessDayConvention)); return(adjustedPeriodDates.Distinct().ToList()); }
/// <summary> /// Gets the unadjusted calculation period start dates. /// </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="firstRegularPeriodDate">The first regular period date.</param> /// <param name="stubPeriodType">Type of the stub period.</param> /// <returns>A vertival range of dates.</returns> public object[,] GetUnadjustedCalculationPeriodDates(DateTime effectiveDate, DateTime terminationDate, string periodInterval, string rollConvention, DateTime firstRegularPeriodDate, string stubPeriodType) { var dates = DateScheduler.GetUnadjustedCalculationPeriodDates(effectiveDate, terminationDate, periodInterval, rollConvention, firstRegularPeriodDate, stubPeriodType); var result = RangeHelper.ConvertArrayToRange(dates); return(result); }
/// <summary> /// /// </summary> /// <param name="baseDate"></param> /// <param name="bucketInterval"></param> /// <returns></returns> public override DateTime[] GetBucketingDates(DateTime baseDate, Period bucketInterval) { var bucketDates = new List <DateTime>(); if (Coupons.Count > 1) { bucketDates = new List <DateTime>(DateScheduler.GetUnadjustedDatesFromEffectiveDate(baseDate, RiskMaturityDate, BucketingInterval, RollConventionEnum.NONE, out _, out _)); } return(bucketDates.ToArray()); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableIRSwap"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="nodeStruct">The nodeStruct;</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="paymentCalendar">The paymentCalendar.</param> /// <param name="fixedRate">The fixed rate.</param> public PriceableIRSwap(DateTime baseDate, SimpleIRSwapNodeStruct nodeStruct, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate) : base(baseDate, nodeStruct, fixingCalendar, paymentCalendar, fixedRate) { ModelIdentifier = DiscountingType == null ? "SwapAsset" : "DiscountSwapAsset"; //The floating leg which is now non-zero. var unadjustedDateSchedule = DateScheduler.GetUnadjustedDateSchedule(AdjustedStartDate, SimpleIRSwap.term, UnderlyingRateIndex.term); FloatingLegAdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedDateSchedule, BusinessDayAdjustments.businessDayConvention, fixingCalendar); FloatingLegWeightings = CreateWeightings(CDefaultWeightingValue, FloatingLegAdjustedPeriodDates.Count - 1); FloatingLegYearFractions = GetFloatingLegYearFractions(); }
/// <summary> /// Returns the unadjusted the calculation dates /// </summary> /// <param name="effectiveDate">The effective date.</param> /// <param name="terminationDate">The termination date.</param> /// <param name="intervalToFirstRegularPeriodStart">The interval to first regular period start.</param> /// <param name="periodInterval">The period interval.</param> /// <param name="rollConvention">The roll convention.</param> /// <param name="stubPeriodType">Type of the stub period.</param> /// <returns>A vertical arrray of dates.</returns> public object[,] UnadjustedCalculationDatesFromFirstRegularInterval(DateTime effectiveDate, DateTime terminationDate, string intervalToFirstRegularPeriodStart, string periodInterval, string rollConvention, string stubPeriodType) { var dates = DateScheduler.UnadjustedCalculationDatesFromFirstRegularInterval(effectiveDate, terminationDate, intervalToFirstRegularPeriodStart, periodInterval, rollConvention, stubPeriodType); var result = RangeHelper.ConvertArrayToRange(dates); return(result); }
/// <summary> /// Gets the bucketed coupon dates. /// </summary> /// <param name="baseDate">The base datew.</param> /// <param name="bucketInterval">The bucket interval.</param> /// <returns></returns> protected IDictionary <string, DateTime[]> GetBucketedPaymentDates(DateTime baseDate, Period bucketInterval) { IDictionary <string, DateTime[]> bucketPaymentDates = new Dictionary <string, DateTime[]>(); var bucketDates = new List <DateTime>(); foreach (var payment in Payments) { bucketDates.AddRange(new List <DateTime>(DateScheduler.GetUnadjustedDatesFromTerminationDate(baseDate, payment.PaymentDate, BucketingInterval, RollConventionEnum.NONE, out _, out _))); bucketDates = RemoveDuplicates(bucketDates); bucketPaymentDates.Add(payment.Id, bucketDates.ToArray()); } return(bucketPaymentDates); }
/// <summary> /// Gets the bucketed coupon dates. /// </summary> /// <param name="bucketInterval">The bucket interval.</param> /// <returns></returns> protected IDictionary <string, DateTime[]> GetBucketedCouponDates(Period bucketInterval) { IDictionary <string, DateTime[]> bucketCouponDates = new Dictionary <string, DateTime[]>(); var bucketDates = new List <DateTime>(); foreach (IPriceableInstrumentController <PaymentCalculationPeriod> coupon in Coupons) { var priceableRateCoupon = (IPriceableRateCoupon <IRateCouponParameters, IRateInstrumentResults>)coupon; bucketDates.AddRange(new List <DateTime>(DateScheduler.GetUnadjustedDatesFromTerminationDate(priceableRateCoupon.UnadjustedStartDate, priceableRateCoupon.UnadjustedEndDate, BucketingInterval, RollConventionEnum.NONE, out _, out _))); bucketDates = RemoveDuplicates(bucketDates); bucketCouponDates.Add(coupon.Id, bucketDates.ToArray()); } return(bucketCouponDates); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleFra"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="nodeStruct"></param> /// <param name="fixingCalendar"></param> /// <param name="paymentCalendar"></param> /// <param name="fixedRate">The fixed rate.</param> public PriceableSimpleRevenueInflationSwap(DateTime baseDate, SimpleIRSwapNodeStruct nodeStruct, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate) : base(baseDate, nodeStruct.DateAdjustments, fixedRate) { Id = nodeStruct.SimpleIRSwap.id; SimpleInflationSwap = nodeStruct.SimpleIRSwap; SpotDateOffset = nodeStruct.SpotDate; Calculation = nodeStruct.Calculation; UnderlyingRateIndex = nodeStruct.UnderlyingRateIndex; AdjustedStartDate = GetSpotDate(baseDate, fixingCalendar, SpotDateOffset); DayCounter = DayCounterHelper.Parse(Calculation.dayCountFraction.Value); List <DateTime> unadjustedDateSchedule = DateScheduler.GetUnadjustedDateSchedule(AdjustedStartDate, SimpleInflationSwap.term, SimpleInflationSwap.paymentFrequency); AdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedDateSchedule, nodeStruct.DateAdjustments.businessDayConvention, paymentCalendar); }
public void GetUnadjustedDateScheduleTest() { var startDate = new DateTime(2010, 03, 31); var term = new Period { period = PeriodEnum.M, periodMultiplier = "2" }; var interval = new Period { period = PeriodEnum.M, periodMultiplier = "1" }; List <DateTime> dates = DateScheduler.GetUnadjustedDateSchedule(startDate, term, interval); Assert.AreEqual(3, dates.Count); Assert.AreEqual(startDate, dates[0]); Assert.AreEqual(new DateTime(2010, 04, 30), dates[1]); Assert.AreEqual(new DateTime(2010, 05, 31), dates[2]); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableIRSwap"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="fixedLegSwap">The fixed leg details.</param> /// <param name="spotDate">the spot date.</param> /// <param name="notional">The notional amount.</param> /// <param name="paymentBusinessDayAdjustments">The business day adjustments.</param> /// <param name="floatingLegSwap">The floating leg details.</param> /// <param name="floatingLegcalculation">The floatingLegcalculation.</param> /// <param name="fixingDateOffset">The fixing date business day adjustments.</param> /// <param name="resetRates">The reset rates of the floating leg - if any.</param> /// <param name="fixingCalendar">The fixing calendar. If null, a new is constructed based on the business calendars.</param> /// <param name="paymentCalendar">The payment calendar. If null, a new is constructed based on the business calendars.</param> /// <param name="fixedRate">The fixed rate.</param> /// <param name="spread">The spread on the floating leg.</param> public PriceableIRSwap(DateTime baseDate, SimpleIRSwap fixedLegSwap, DateTime spotDate, MoneyBase notional, BusinessDayAdjustments paymentBusinessDayAdjustments, SimpleIRSwap floatingLegSwap, Calculation floatingLegcalculation, RelativeDateOffset fixingDateOffset, List <Decimal> resetRates, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate, BasicQuotation spread) : base(baseDate, fixedLegSwap, fixingDateOffset, floatingLegcalculation, paymentBusinessDayAdjustments, null, fixingCalendar, paymentCalendar, fixedRate) { ModelIdentifier = DiscountingType == null ? "SwapAsset" : "DiscountSwapAsset"; FloatingLegSpread = GetSpread(spread); ForwardRates = resetRates?.ToArray(); UnderlyingRateIndex = RateIndexHelper.Parse(FloatingRateCalculation.floatingRateIndex.Value, notional.currency.Value, Calculation.dayCountFraction.Value); var unadjustedFloatingDates = DateScheduler.GetUnadjustedDateSchedule(spotDate, floatingLegSwap.term, floatingLegSwap.paymentFrequency); FloatingLegAdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedFloatingDates, paymentBusinessDayAdjustments.businessDayConvention, paymentCalendar); FloatingLegWeightings = CreateWeightings(CDefaultWeightingValue, FloatingLegAdjustedPeriodDates.Count - 1); FloatingLegYearFractions = GetFloatingLegYearFractions(); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableLeaseAsset"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="paymentCalendar">The payment Calendar.</param> /// <param name="marketQuote">The market quote.</param> /// <param name="lease">The lease.</param> public PriceableLeaseAsset(DateTime baseDate, FpML.V5r3.Reporting.Lease lease, IBusinessCalendar paymentCalendar, BasicQuotation marketQuote) { PaymentCalendar = paymentCalendar; Multiplier = 1.0m; YearFractions = new[] { 0.25m }; ModelIdentifier = "LeaseAsset"; StartAmount = lease.startGrossPrice.amount; MaturityDate = lease.leaseExpiryDate.Value; Frequency = lease.paymentFrequency; LeaseRate = lease.reviewChange; Currency = lease.currency; BaseDate = baseDate; SettlementDate = baseDate; PaymentBusinessDayAdjustments = lease.businessDayAdjustments; FirstPaymentDate = lease.startDate.Value; ReviewFrequency = lease.reviewFrequency; NextReviewDate = lease.nextReviewDate.Value; if (MaturityDate > BaseDate) { var rollConvention = RollConventionEnumHelper.Parse(MaturityDate.Day.ToString(CultureInfo.InvariantCulture)); UnAdjustedPeriodDates = DateScheduler.GetUnadjustedCouponDatesFromMaturityDate(SettlementDate, MaturityDate, Frequency, rollConvention, out _, out var nextCouponDate); LastPaymentDate = UnAdjustedPeriodDates[0]; AdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(UnAdjustedPeriodDates, PaymentBusinessDayAdjustments.businessDayConvention, paymentCalendar).ToArray(); AdjustedPeriodDates[0] = SettlementDate; NextPaymentDate = nextCouponDate; } RiskMaturityDate = AdjustedPeriodDates[AdjustedPeriodDates.Length - 1]; Weightings = CreateWeightings(CDefaultWeightingValue, AdjustedPeriodDates.Length - 1);//, LeaseRate, //TODO Need to add a credit spread to this. LeaseDiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency.Value, true); }
public void UnadjustedDatesSchedule2() { DateTime effectiveDate = new DateTime(2008, 07, 9); DateTime terminationDate = new DateTime(2011, 07, 11); Period periodInterval = PeriodHelper.Parse("3M"); RollConventionEnum rollDayConvention = RollConventionEnum.Item7; DateTime firstRegularPeriodStartDate = effectiveDate; DateTime lastRegularPeriodEndDate = terminationDate; //Back|Forward are same string expectedDates = "9/07/2008;7/10/2008;7/01/2009;7/04/2009;7/07/2009;7/10/2009;7/01/2010;7/04/2010;7/07/2010;7/10/2010;7/01/2011;7/04/2011;11/07/2011"; DateTime[] bdates = DateScheduler.GetUnadjustedDatesFromTerminationDate(effectiveDate, terminationDate, periodInterval, rollDayConvention, out firstRegularPeriodStartDate, out lastRegularPeriodEndDate); //bdates = AdjustDates(bdates, BusinessDayConventionEnum.MODFOLLOWING, "AUSY"); Validate(expectedDates, bdates); DateTime[] fdates = DateScheduler.GetUnadjustedDatesFromEffectiveDate(effectiveDate, terminationDate, periodInterval, rollDayConvention, out firstRegularPeriodStartDate, out lastRegularPeriodEndDate); //fdates = AdjustDates(fdates, BusinessDayConventionEnum.MODFOLLOWING, "AUSY"); Validate(expectedDates, fdates); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleIRSwap"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="simpleIRSwap">THe FpML swap.</param> /// <param name="spotDate">The spot date.</param> /// <param name="calculation">A calculation.</param> /// <param name="stringRollConvention">The roll convention.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="underlyingRateIndex">Index of the rate.</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="paymentCalendar">The paymentCalendar.</param> /// <param name="fixedRate">The fixed rate.</param> public PriceableSimpleIRSwap(DateTime baseDate, SimpleIRSwap simpleIRSwap, DateTime spotDate, Calculation calculation, String stringRollConvention, BusinessDayAdjustments businessDayAdjustments, RateIndex underlyingRateIndex, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate) : base(baseDate, businessDayAdjustments, calculation, fixedRate) { Id = simpleIRSwap.id; SimpleIRSwap = simpleIRSwap; UnderlyingRateIndex = underlyingRateIndex; AdjustedStartDate = spotDate; List <DateTime> unadjustedDateSchedule = DateScheduler.GetUnadjustedDateSchedule(AdjustedStartDate, SimpleIRSwap.term, SimpleIRSwap.paymentFrequency); AdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedDateSchedule, BusinessDayAdjustments.businessDayConvention, paymentCalendar); RiskMaturityDate = AdjustedPeriodDates[AdjustedPeriodDates.Count - 1]; Weightings = CreateWeightings(CDefaultWeightingValue, AdjustedPeriodDates.Count - 1); YearFractions = GetYearFractions(); ModelIdentifier = DiscountingType == null ? "SimpleSwapAsset" : "SimpleDiscountSwapAsset"; var timeToMaturity = Actual365.Instance.YearFraction(baseDate, RiskMaturityDate); EndDiscountFactor = (decimal)System.Math.Exp(-(double)fixedRate.value * timeToMaturity); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleIRSwap"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="nodeStruct">The nodeStruct;</param> /// <param name="fixingCalendar">The fixingCalendar.</param> /// <param name="paymentCalendar">The paymentCalendar.</param> /// <param name="fixedRate">The fixed rate.</param> public PriceableSimpleIRSwap(DateTime baseDate, SimpleIRSwapNodeStruct nodeStruct, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar, BasicQuotation fixedRate) : base(baseDate, nodeStruct.DateAdjustments, nodeStruct.Calculation, fixedRate) { Id = nodeStruct.SimpleIRSwap.id; FixingDateOffset = nodeStruct.SpotDate; SimpleIRSwap = nodeStruct.SimpleIRSwap; UnderlyingRateIndex = nodeStruct.UnderlyingRateIndex; //TODO: This needs to be modified to use backwards roll. AdjustedStartDate = GetSpotDate(baseDate, fixingCalendar, FixingDateOffset); List <DateTime> unadjustedDateSchedule = DateScheduler.GetUnadjustedDateSchedule(AdjustedStartDate, SimpleIRSwap.term, SimpleIRSwap.paymentFrequency); AdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(unadjustedDateSchedule, BusinessDayAdjustments.businessDayConvention, paymentCalendar); RiskMaturityDate = AdjustedPeriodDates[AdjustedPeriodDates.Count - 1]; Weightings = CreateWeightings(CDefaultWeightingValue, AdjustedPeriodDates.Count - 1); YearFractions = GetYearFractions(); ModelIdentifier = DiscountingType == null ? "SimpleSwapAsset" : "SimpleDiscountSwapAsset"; var timeToMaturity = Actual365.Instance.YearFraction(baseDate, RiskMaturityDate); EndDiscountFactor = (decimal)System.Math.Exp(-(double)fixedRate.value * timeToMaturity); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleBond"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="nodeStruct">The bond nodeStruct</param> /// <param name="settlementCalendar">The settlement Calendar.</param> /// <param name="paymentCalendar">The payment Calendar.</param> /// <param name="marketQuote">The market quote.</param> /// <param name="quoteType">THe quote Type</param> public PriceableSimpleBond(DateTime baseDate, BondNodeStruct nodeStruct, IBusinessCalendar settlementCalendar, IBusinessCalendar paymentCalendar, BasicQuotation marketQuote, BondPriceEnum quoteType) : base(baseDate, nodeStruct.Bond.faceAmount, nodeStruct.Bond.currency, nodeStruct.SettlementDate, nodeStruct.ExDivDate, nodeStruct.BusinessDayAdjustments, marketQuote, quoteType) { Id = nodeStruct.Bond.id; var tempId = Id.Split('-'); var bondId = tempId[0]; if (tempId.Length > 2) { bondId = tempId[2]; } SettlementDateCalendar = settlementCalendar; Issuer = (string)nodeStruct.Bond.Item;//Does not handle PartyReference type -> only string! Description = "Not Defined"; //IsYTMQuote = true; if (nodeStruct.Bond.description != null) { Description = nodeStruct.Bond.description; } MaturityDate = nodeStruct.Bond.maturity; CouponDayCount = new DayCountFraction { Value = nodeStruct.Bond.dayCountFraction.Value }; CouponFrequency = new Period { period = nodeStruct.Bond.paymentFrequency.period, periodMultiplier = nodeStruct.Bond.paymentFrequency.periodMultiplier }; if (nodeStruct.Bond.couponRateSpecified) { CouponRate = nodeStruct.Bond.couponRate; } if (nodeStruct.Bond.parValueSpecified) { ParValue = nodeStruct.Bond.parValue; } if (nodeStruct.Bond.clearanceSystem != null) { ClearanceSystem = nodeStruct.Bond.clearanceSystem.Value; } if (nodeStruct.Bond.exchangeId != null) { Exchange = nodeStruct.Bond.exchangeId.Value; } CouponType = CouponTypeEnum.Fixed; if (nodeStruct.Bond.seniority != null) { Seniority = EnumHelper.Parse <CreditSeniorityEnum>(nodeStruct.Bond.seniority.Value, true); } if (nodeStruct.Bond.instrumentId != null) { InstrumentIds = new List <InstrumentId>(); foreach (var identifier in nodeStruct.Bond.instrumentId.Select(id => InstrumentIdHelper.Parse(id.Value))) { InstrumentIds.Add(identifier); } } //This handles the case of a bondforward used in curve building. if (MaturityDate > BaseDate) { DateTime lastCouponDate; DateTime nextCouponDate; var rollConvention = RollConventionEnumHelper.Parse(MaturityDate.Day.ToString(CultureInfo.InvariantCulture)); Frequency = FrequencyHelper.ToFrequency(nodeStruct.Bond.paymentFrequency); //Get the settlement date SettlementDate = GetSettlementDate(baseDate, settlementCalendar, nodeStruct.SettlementDate); //Generate the necessary dates. //TODO Should the settlement date and the underlying bond be calculated on the fly when calculation occurs? UnAdjustedPeriodDates = DateScheduler.GetUnadjustedCouponDatesFromMaturityDate(SettlementDate, MaturityDate, CouponFrequency, rollConvention, out lastCouponDate, out nextCouponDate); LastCouponDate = UnAdjustedPeriodDates[0]; NextCouponDate = nextCouponDate; AdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(UnAdjustedPeriodDates, nodeStruct.BusinessDayAdjustments .businessDayConvention, paymentCalendar) .ToArray(); AdjustedPeriodDates[0] = SettlementDate; //TODO check this! NextExDivDate = GetNextExDivDate(); IsXD = IsExDiv(); } BondCurveName = CurveNameHelpers.GetBondCurveName(Currency.Value, bondId); SwapDiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency.Value, true); }
/// <summary> /// Initializes a new instance of the <see cref="PriceableSimpleBond"/> class. /// </summary> /// <param name="baseDate">The base date.</param> /// <param name="bond">The bond</param> /// <param name="settlementDate">The settlement date.</param> /// <param name="exDivDate">The ex dividend date.</param> /// <param name="businessDayAdjustments">The business day adjustments.</param> /// <param name="paymentCalendar">The payment Calendar.</param> /// <param name="marketQuote">The market quote.</param> /// <param name="quoteType">The quote type</param> public PriceableSimpleBond(DateTime baseDate, Bond bond, DateTime settlementDate, DateTime exDivDate, BusinessDayAdjustments businessDayAdjustments, IBusinessCalendar paymentCalendar, BasicQuotation marketQuote, BondPriceEnum quoteType) : base(baseDate, bond.faceAmount, bond.currency, null, null, businessDayAdjustments, marketQuote, quoteType) { Id = bond.id; var tempId = Id.Split('-'); var bondId = tempId[0]; if (tempId.Length > 2) { bondId = tempId[2]; } Issuer = (string)bond.Item;//Does not handle PartyReference type -> only string! Description = "Not Defined"; if (bond.description != null) { Description = bond.description; } MaturityDate = bond.maturity; CouponDayCount = new DayCountFraction { Value = bond.dayCountFraction.Value }; if (bond.parValueSpecified) { ParValue = bond.parValue; } if (bond.couponRateSpecified) { CouponRate = bond.couponRate; } CouponFrequency = new Period { period = bond.paymentFrequency.period, periodMultiplier = bond.paymentFrequency.periodMultiplier }; CouponType = CouponTypeEnum.Fixed; if (bond.clearanceSystem != null) { ClearanceSystem = bond.clearanceSystem.Value; } if (bond.exchangeId != null) { Exchange = bond.exchangeId.Value; } if (bond.seniority != null) { Seniority = EnumHelper.Parse <CreditSeniorityEnum>(bond.seniority.Value); } if (bond.instrumentId != null) { InstrumentIds = new List <InstrumentId>(); foreach (var identifier in bond.instrumentId.Select(id => InstrumentIdHelper.Parse(id.Value))) { InstrumentIds.Add(identifier); } } //This handles the case of a bond forward used in curve building. if (MaturityDate > BaseDate) { var rollConvention = RollConventionEnumHelper.Parse(MaturityDate.Day.ToString(CultureInfo.InvariantCulture)); Frequency = FrequencyHelper.ToFrequency(bond.paymentFrequency); SettlementDate = settlementDate; UnAdjustedPeriodDates = DateScheduler.GetUnadjustedCouponDatesFromMaturityDate(SettlementDate, MaturityDate, CouponFrequency, rollConvention, out _, out var nextCouponDate); LastCouponDate = UnAdjustedPeriodDates[0]; NextCouponDate = nextCouponDate; AdjustedPeriodDates = AdjustedDateScheduler.GetAdjustedDateSchedule(UnAdjustedPeriodDates, PaymentBusinessDayAdjustments.businessDayConvention, paymentCalendar).ToArray(); AdjustedPeriodDates[0] = SettlementDate; NextExDivDate = exDivDate; IsXD = IsExDiv(); } BondCurveName = CurveNameHelpers.GetBondCurveName(Currency.Value, bondId); SwapDiscountCurveName = CurveNameHelpers.GetDiscountCurveName(Currency.Value, true); }