/// <summary> /// Builds this instance. /// </summary> /// <returns></returns> public PrincipalExchange Build() { var money = MoneyHelper.Mul(PaymentAmount, PayerIsBaseParty); var px = PrincipalExchangeHelper.Create(PaymentDate, money.amount); px.id = Id; //px. px.adjustedPrincipalExchangeDate = PaymentDate; px.adjustedPrincipalExchangeDateSpecified = true; if (CalculationPerfomedIndicator) { px.discountFactor = PaymentDiscountFactor; var npv = System.Math.Abs(ForecastAmount.amount) * PaymentDiscountFactor; px.discountFactorSpecified = true; px.presentValuePrincipalExchangeAmount = MoneyHelper.Mul(npv, PaymentAmount.currency.Value, PayerIsBaseParty); } return(px); }
// private static void UpdateCashflowsWithDetailedCashflows(Cashflows cashflows, List<DetailedCashflowRangeItem> listDetailedCashflows, bool fixedLeg) // { // for (int i = 0; i < cashflows.paymentCalculationPeriod.Length; ++i) // { // PaymentCalculationPeriod paymentCalculationPeriod = cashflows.paymentCalculationPeriod[i]; // DetailedCashflowRangeItem detailedCashflowRangeItem = listDetailedCashflows[i]; // // paymentCalculationPeriod.adjustedPaymentDate = detailedCashflowRangeItem.PaymentDate; // PaymentCalculationPeriodHelper.SetCalculationPeriodStartDate(paymentCalculationPeriod, detailedCashflowRangeItem.StartDate); // PaymentCalculationPeriodHelper.SetCalculationPeriodEndDate(paymentCalculationPeriod, detailedCashflowRangeItem.EndDate); // //PaymentCalculationPeriodHelper.GetNumberOfDays(paymentCalculationPeriod, ); // // // Update notional amount // // // PaymentCalculationPeriodHelper.SetNotionalAmount(paymentCalculationPeriod, (decimal)detailedCashflowRangeItem.NotionalAmount); // // if (detailedCashflowRangeItem.CouponType == "Fixed") // { // CalculationPeriod calculationPeriod = PaymentCalculationPeriodHelper.GetCalculationPeriods(paymentCalculationPeriod)[0]; // // if (XsdClassesFieldResolver.CalculationPeriod_HasFixedRate(calculationPeriod)) // { // // Fixed->Fixed // // // PaymentCalculationPeriodHelper.SetRate(paymentCalculationPeriod, (decimal)detailedCashflowRangeItem.Rate); // } // else if (XsdClassesFieldResolver.CalculationPeriod_HasFloatingRateDefinition(calculationPeriod)) // { // // Float->Fixed // // // PaymentCalculationPeriodHelper.ReplaceFloatingRateWithFixedRate(paymentCalculationPeriod, (decimal)detailedCashflowRangeItem.Rate); // } // else // { // throw new NotImplementedException(); // } // // } // else if (detailedCashflowRangeItem.CouponType == "Float") // { // // After the spread is reset - we need to update calculated rate. // // // PaymentCalculationPeriodHelper.SetSpread(paymentCalculationPeriod, (decimal)detailedCashflowRangeItem.Spread); // } // else // { // throw new NotImplementedException(); // } // } // } private static void CreatePrincipalExchangesFromListOfRanges(Cashflows cashflows, IEnumerable <PrincipalExchangeCashflowRangeItem> principalExchangeRangeList) { cashflows.principalExchange = (from item in principalExchangeRangeList where 0 != item.Amount select PrincipalExchangeHelper.Create(item.PaymentDate, (decimal)item.Amount)).ToArray(); }
/// <summary> /// Don't generate stubs? /// </summary> /// <param name="interestRateStream"></param> /// <param name="rollDates">from #1st roll date to last roll date (last roll dates is effectively the end of the swap)</param> /// <param name="paymentCalendar"></param> /// <returns></returns> public static CalculationPeriodsPrincipalExchangesAndStubs GenerateCalculationPeriodsPrincipalExchangesAndStubsFromRollDates(InterestRateStream interestRateStream, List <DateTime> rollDates, IBusinessCalendar paymentCalendar) { CalculationPeriodDates calculationPeriodDates = interestRateStream.calculationPeriodDates; AdjustableDate adjustableEffectiveDate = XsdClassesFieldResolver.CalculationPeriodDatesGetEffectiveDate(calculationPeriodDates); var result = new CalculationPeriodsPrincipalExchangesAndStubs(); for (int rollDateIndex = 0; rollDateIndex < rollDates.Count - 1; ++rollDateIndex) { DateTime startOfThePeriod = rollDates[rollDateIndex]; DateTime endOfThePeriod = rollDates[rollDateIndex + 1]; var calculationPeriod = new CalculationPeriod(); // Set adjusted period dates // CalculationPeriodHelper.SetAdjustedDates(calculationPeriod, startOfThePeriod, endOfThePeriod); result.Add(calculationPeriod); } // Add principle exchanges if this need is defined in parametric representation of the interest rate steam. // if (null != interestRateStream.principalExchanges) { // Initial PE // if (interestRateStream.principalExchanges.initialExchange) { //if (paymentCalendar == null) //{ // paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, adjustableEffectiveDate.dateAdjustments.businessCenters); //} PrincipalExchange initialExchange = PrincipalExchangeHelper.Create(AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustableEffectiveDate)); result.InitialPrincipalExchange = initialExchange; } // intermediatory PE // if (interestRateStream.principalExchanges.intermediateExchange) { // Generate a list of intermediatory PE exchanges // Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(interestRateStream.calculationPeriodAmount); Notional notionalSchedule = XsdClassesFieldResolver.CalculationGetNotionalSchedule(calculation); if (null != notionalSchedule.notionalStepSchedule.step)//there should be steps - otherwise NO interm. exchanges. { foreach (DateTime stepDate in ScheduleHelper.GetStepDates(notionalSchedule.notionalStepSchedule)) { PrincipalExchange intermediatoryExchange = PrincipalExchangeHelper.Create(stepDate); result.Add(intermediatoryExchange); } } } //AdjustableDate adjustableTerminationDate = XsdClassesFieldResolver.CalculationPeriodDates_GetTerminationDate(calculationPeriodDates); DateTime lastRollDate = rollDates[rollDates.Count - 1]; // Final PE // if (interestRateStream.principalExchanges.finalExchange) { //PrincipalExchange finalExchange = PrincipalExchangeHelper.Create(DateTypesHelper.ToAdjustedDate(adjustableTerminationDate)); PrincipalExchange finalExchange = PrincipalExchangeHelper.Create(lastRollDate); result.FinalPrincipalExchange = finalExchange; } } return(result); }
private static void CreatePrincipalExchangesFromListOfRanges( Cashflows cashflows, IEnumerable <InputPrincipalExchangeCashflowRangeItem> principalExchangeRangeList) { cashflows.principalExchange = principalExchangeRangeList.Select(item => PrincipalExchangeHelper.Create(item.PaymentDate, (decimal)item.Amount)).ToArray(); }
public static CalculationPeriodsPrincipalExchangesAndStubs GenerateCalculationPeriodsPrincipalExchangesAndStubs( InterestRateStream interestRateStream, IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar) { CalculationPeriodDates calculationPeriodDates = interestRateStream.calculationPeriodDates; AdjustableDate adjustableEffectiveDate = XsdClassesFieldResolver.CalculationPeriodDatesGetEffectiveDate(calculationPeriodDates); AdjustableDate adjustableTerminationDate = XsdClassesFieldResolver.CalculationPeriodDatesGetTerminationDate(calculationPeriodDates); AdjustableDate adjustableFirstPeriodDate = adjustableEffectiveDate; DateTime?firstRegularPeriodStartDate = XsdClassesFieldResolver.CalculationPeriodDatesGetFirstRegularPeriodStartDate(calculationPeriodDates); var tempDate = XsdClassesFieldResolver.CalculationPeriodDatesGetFirstPeriodStartDate(calculationPeriodDates); if (tempDate != null && firstRegularPeriodStartDate != null) { adjustableFirstPeriodDate = tempDate; Frequency frequency = calculationPeriodDates.calculationPeriodFrequency; var startDate = CalculationPeriodGenerator.AddPeriod((DateTime)firstRegularPeriodStartDate, IntervalHelper.FromFrequency(frequency), -1); adjustableFirstPeriodDate.unadjustedDate = IdentifiedDateHelper.Create(startDate); } DateTime?lastRegularPeriodEndDate = XsdClassesFieldResolver.CalculationPeriodDatesGetLastRegularPeriodEndDate(calculationPeriodDates); // This assumes automatic adjustment of calculationperiods. CalculationPeriodsPrincipalExchangesAndStubs result = CalculationPeriodGenerator.GenerateAdjustedCalculationPeriods( adjustableFirstPeriodDate.unadjustedDate.Value, adjustableTerminationDate.unadjustedDate.Value, firstRegularPeriodStartDate, lastRegularPeriodEndDate, calculationPeriodDates.calculationPeriodFrequency, calculationPeriodDates.calculationPeriodDatesAdjustments, paymentCalendar); //Determine whether the reset dates must be calcuated. Calculation calculation = XsdClassesFieldResolver.CalculationPeriodAmountGetCalculation(interestRateStream.calculationPeriodAmount); // Add principle exchanges if this need is defined in parametric representation of the interest rate steam. // if (null != interestRateStream.principalExchanges) { //if (paymentCalendar == null) //{ // paymentCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, adjustableEffectiveDate.dateAdjustments.businessCenters); //} // Initial PE // if (interestRateStream.principalExchanges.initialExchange) { PrincipalExchange initialExchange = PrincipalExchangeHelper.Create(AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustableEffectiveDate)); result.InitialPrincipalExchange = initialExchange; } // intermediatory PE // if (interestRateStream.principalExchanges.intermediateExchange) { // Generate a list of intermediatory PE exchanges // Notional notionalSchedule = XsdClassesFieldResolver.CalculationGetNotionalSchedule(calculation); if (null != notionalSchedule.notionalStepSchedule.step)//there should be steps - otherwise NO interm. exchanges. { foreach (DateTime stepDate in ScheduleHelper.GetStepDates(notionalSchedule.notionalStepSchedule)) { PrincipalExchange intermediatoryExchange = PrincipalExchangeHelper.Create(stepDate); result.Add(intermediatoryExchange); } } } // Final PE // Assume the same calendar is used for the termination date as well! if (interestRateStream.principalExchanges.finalExchange) { PrincipalExchange finalExchange = PrincipalExchangeHelper.Create(AdjustedDateHelper.ToAdjustedDate(paymentCalendar, adjustableTerminationDate)); result.FinalPrincipalExchange = finalExchange; } } //Only does upfront resetRelativeTo start date. if (interestRateStream.resetDates != null && calculation.Items[0].GetType() == typeof(FloatingRateCalculation)) { //Get the fixing date convention. var fixingDateConvention = interestRateStream.resetDates.resetDatesAdjustments; //if (fixingCalendar == null) //{ // fixingCalendar = BusinessCenterHelper.ToBusinessCalendar(cache, fixingDateConvention.businessCenters); //} foreach (var calculationPeriod in result.CalculationPeriods) { if (calculationPeriod.adjustedStartDateSpecified) { //Set the adjusted fixing date. var adjustedFixingDate = AdjustedDateHelper.ToAdjustedDate(fixingCalendar, calculationPeriod.adjustedStartDate, fixingDateConvention); var floatingRateDefinition = new FloatingRateDefinition(); var rateObservation = new RateObservation { observedRateSpecified = false, adjustedFixingDateSpecified = true, adjustedFixingDate = adjustedFixingDate }; floatingRateDefinition.rateObservation = new[] { rateObservation }; calculationPeriod.Item1 = floatingRateDefinition; } } //The initial stub period. if (result.InitialStubCalculationPeriod != null) { if (result.InitialStubCalculationPeriod.adjustedStartDateSpecified) { //Set the adjusted fixing date. var adjustedFixingDate = AdjustedDateHelper.ToAdjustedDate(fixingCalendar, result.InitialStubCalculationPeriod.adjustedStartDate, fixingDateConvention); var floatingRateDefinition = new FloatingRateDefinition(); var rateObservation = new RateObservation { observedRateSpecified = false, adjustedFixingDateSpecified = true, adjustedFixingDate = adjustedFixingDate }; floatingRateDefinition.rateObservation = new[] { rateObservation }; result.InitialStubCalculationPeriod.Item1 = floatingRateDefinition; } } //The final stub period if (result.FinalStubCalculationPeriod != null) { if (result.FinalStubCalculationPeriod.adjustedStartDateSpecified) { //Set the adjusted fixing date. var adjustedFixingDate = AdjustedDateHelper.ToAdjustedDate(fixingCalendar, result.FinalStubCalculationPeriod.adjustedStartDate, fixingDateConvention); var floatingRateDefinition = new FloatingRateDefinition(); var rateObservation = new RateObservation { observedRateSpecified = false, adjustedFixingDateSpecified = true, adjustedFixingDate = adjustedFixingDate }; floatingRateDefinition.rateObservation = new[] { rateObservation }; result.FinalStubCalculationPeriod.Item1 = floatingRateDefinition; } } } return(result); }