public CDS() { FixedLeg = new GenericSwapLeg(OriginDate, Tenor, HolidayCalendar, Currency, new Frequency("1m"), Basis) { RollDay = "IMM" }; FixedSchedule = FixedLeg.GenerateSchedule(); }
public FloatingRateLoanDepo(CashFlow[] flows, FloatRateIndex floatRateIndex, string forecastCurve, string discountCurve) : base() { FloatRateIndex = floatRateIndex; ForecastCurve = forecastCurve; DiscountCurve = discountCurve; LoanDepoSchedule = new CashFlowSchedule { Flows = flows.ToList() }; }
public FixedRateLoanDeposit(DateTime startDate, DateTime endDate, double interestRate, Currency currency, DayCountBasis basis, double notional, string discountCurve) : base() { StartDate = startDate; EndDate = endDate; InterestRate = interestRate; Basis = basis; Notional = notional; DiscountCurve = discountCurve; Currency = currency; LoanDepoSchedule = new CashFlowSchedule { Flows = new List <CashFlow>() }; LoanDepoSchedule.Flows.Add(new CashFlow { Notional = Notional, Currency = Currency, FlowType = FlowType.FixedAmount, SettleDate = StartDate, }); LoanDepoSchedule.Flows.Add(new CashFlow { Notional = -Notional, Currency = Currency, FlowType = FlowType.FixedAmount, SettleDate = EndDate, }); var dcf = StartDate.CalculateYearFraction(EndDate, Basis); LoanDepoSchedule.Flows.Add(new CashFlow { Notional = -Notional, Currency = Currency, FlowType = FlowType.FixedRate, SettleDate = EndDate, AccrualPeriodStart = StartDate, AccrualPeriodEnd = EndDate, FixedRateOrMargin = InterestRate, YearFraction = dcf, Fv = -Notional * dcf * interestRate }); PillarDate = endDate; SolveCurve = DiscountCurve; }
public CashFlowSchedule GenerateSchedule() { var startDate = EffectiveDate; var endDate = TerminationDate.Date(startDate, ResetRollType, ResetCalendar); var f = new CashFlowSchedule(); var lf = new List <CashFlow>(); if (NotionalExchange == ExchangeType.FrontOnly || NotionalExchange == ExchangeType.Both) { lf.Add(new CashFlow { Notional = (double)Nominal * (Direction == SwapPayReceiveType.Payer ? -1.0 : 1.0), Fv = (double)Nominal * (Direction == SwapPayReceiveType.Payer ? -1.0 : 1.0), SettleDate = startDate, NotionalByYearFraction = 1.0, Dcf = 1.0, FlowType = FlowType.FixedAmount }); } //need to handle stub types and roll day types switch (StubType) { case StubType.ShortFront: case StubType.LongFront: { var nQ = 0; var currentReset = GetNextResetDate(endDate, false); while (GetNextResetDate(currentReset, false) >= startDate) { var q = new CashFlow() { ResetDateStart = currentReset, AccrualPeriodStart = currentReset, FixingDateStart = currentReset.SubtractPeriod(FixingRollType, FixingCalendar, FixingOffset), AccrualPeriodEnd = currentReset.AddPeriod(ResetRollType, ResetCalendar, ResetFrequency) }; q.SettleDate = (PaymentOffsetRelativeTo == OffsetRelativeToType.PeriodEnd) ? q.AccrualPeriodEnd.AddPeriod(PaymentRollType, PaymentCalendar, PaymentOffset) : q.AccrualPeriodStart.AddPeriod(PaymentRollType, PaymentCalendar, PaymentOffset); q.NotionalByYearFraction = (LegType != SwapLegType.FixedNoAccrual && LegType != SwapLegType.FloatNoAccrual) ? q.AccrualPeriodStart.CalculateYearFraction(q.AccrualPeriodEnd, AccrualDCB) : 1.0; q.Dcf = q.NotionalByYearFraction; q.Fv = (LegType == SwapLegType.Fixed) ? (double)Nominal * q.NotionalByYearFraction * (double)FixedRateOrMargin : 0; q.FixedRateOrMargin = (double)FixedRateOrMargin; q.FlowType = (LegType == SwapLegType.Fixed) ? FlowType.FixedRate : FlowType.FloatRate; q.Notional = (double)Nominal; lf.Add(q); nQ++; currentReset = GetNextResetDate(currentReset, false); } if (lf.Count == 0 || lf.Last().AccrualPeriodStart != startDate) { if (StubType == StubType.LongFront) { var Q = lf.Last(); Q.ResetDateStart = startDate; Q.AccrualPeriodStart = startDate; Q.SettleDate = (PaymentOffsetRelativeTo == OffsetRelativeToType.PeriodEnd) ? Q.AccrualPeriodEnd.AddPeriod(PaymentRollType, PaymentCalendar, PaymentOffset) : Q.AccrualPeriodStart.AddPeriod(PaymentRollType, PaymentCalendar, PaymentOffset); Q.Dcf = (LegType != SwapLegType.FixedNoAccrual && LegType != SwapLegType.FloatNoAccrual) ? Q.AccrualPeriodStart.CalculateYearFraction(Q.AccrualPeriodEnd, AccrualDCB) : 1.0; } else { var q = new CashFlow() { AccrualPeriodStart = startDate, FixingDateStart = startDate.SubtractPeriod(FixingRollType, FixingCalendar, FixingOffset), AccrualPeriodEnd = (lf.Count > 0 && lf.Last().AccrualPeriodEnd != DateTime.MinValue)? lf.Last().AccrualPeriodStart : endDate }; q.SettleDate = (PaymentOffsetRelativeTo == OffsetRelativeToType.PeriodEnd) ? q.AccrualPeriodEnd.AddPeriod(PaymentRollType, PaymentCalendar, PaymentOffset) : q.AccrualPeriodStart.AddPeriod(PaymentRollType, PaymentCalendar, PaymentOffset); //Q.Currency = CCY; q.NotionalByYearFraction = (LegType != SwapLegType.FixedNoAccrual && LegType != SwapLegType.FloatNoAccrual) ? q.AccrualPeriodStart.CalculateYearFraction(q.AccrualPeriodEnd, AccrualDCB) : 1.0; q.Dcf = q.NotionalByYearFraction; q.Fv = (LegType == SwapLegType.Fixed) ? (double)Nominal * q.NotionalByYearFraction * (double)FixedRateOrMargin : 0; q.FixedRateOrMargin = (double)FixedRateOrMargin; q.FlowType = (LegType == SwapLegType.Fixed) ? FlowType.FixedRate : FlowType.FloatRate; q.Notional = (double)Nominal; lf.Add(q); nQ++; } } break; } case StubType.ShortBack: case StubType.LongBack: { var nQ = 0; var currentReset = startDate; while (GetNextResetDate(currentReset, true) <= endDate) { var Q = new CashFlow() { AccrualPeriodStart = currentReset, FixingDateStart = currentReset.SubtractPeriod(FixingRollType, FixingCalendar, FixingOffset), AccrualPeriodEnd = currentReset.AddPeriod(ResetRollType, ResetCalendar, ResetFrequency) }; Q.SettleDate = (PaymentOffsetRelativeTo == OffsetRelativeToType.PeriodEnd) ? Q.AccrualPeriodEnd.AddPeriod(PaymentRollType, PaymentCalendar, PaymentOffset) : Q.AccrualPeriodStart.AddPeriod(PaymentRollType, PaymentCalendar, PaymentOffset); //Q.Currency = CCY; Q.NotionalByYearFraction = (LegType != SwapLegType.FixedNoAccrual && LegType != SwapLegType.FloatNoAccrual) ? Q.AccrualPeriodStart.CalculateYearFraction(Q.AccrualPeriodEnd, AccrualDCB) : 1.0; Q.Dcf = Q.NotionalByYearFraction; Q.Notional = (double)Nominal; Q.Fv = (LegType == SwapLegType.Fixed) ? (double)Nominal * Q.NotionalByYearFraction * (double)FixedRateOrMargin : 0; Q.FixedRateOrMargin = (double)FixedRateOrMargin; Q.FlowType = (LegType == SwapLegType.Fixed) ? FlowType.FixedRate : FlowType.FloatRate; lf.Add(Q); nQ++; currentReset = GetNextResetDate(currentReset, false); } if (lf.Last().AccrualPeriodEnd != endDate) { if (StubType == StubType.LongBack) { var Q = lf.Last(); Q.AccrualPeriodEnd = endDate; Q.SettleDate = (PaymentOffsetRelativeTo == OffsetRelativeToType.PeriodEnd) ? Q.AccrualPeriodEnd.AddPeriod(PaymentRollType, PaymentCalendar, PaymentOffset) : Q.AccrualPeriodStart.AddPeriod(PaymentRollType, PaymentCalendar, PaymentOffset); Q.Dcf = (LegType != SwapLegType.FixedNoAccrual && LegType != SwapLegType.FloatNoAccrual) ? Q.AccrualPeriodStart.CalculateYearFraction(Q.AccrualPeriodEnd, AccrualDCB) : 1.0; } else { var Q = new CashFlow() { AccrualPeriodStart = lf.Last().AccrualPeriodEnd, FixingDateStart = startDate.SubtractPeriod(FixingRollType, FixingCalendar, FixingOffset), AccrualPeriodEnd = endDate }; Q.SettleDate = (PaymentOffsetRelativeTo == OffsetRelativeToType.PeriodEnd) ? Q.AccrualPeriodEnd.AddPeriod(PaymentRollType, PaymentCalendar, PaymentOffset) : Q.AccrualPeriodStart.AddPeriod(PaymentRollType, PaymentCalendar, PaymentOffset); //Q.Currency = CCY; Q.NotionalByYearFraction = (LegType != SwapLegType.FixedNoAccrual && LegType != SwapLegType.FloatNoAccrual) ? Q.AccrualPeriodStart.CalculateYearFraction(Q.AccrualPeriodEnd, AccrualDCB) : 1.0; Q.Notional = (double)Nominal; Q.Dcf = Q.NotionalByYearFraction; Q.Fv = (LegType == SwapLegType.Fixed) ? (double)Nominal * Q.NotionalByYearFraction * (double)FixedRateOrMargin : 0; Q.FixedRateOrMargin = (double)FixedRateOrMargin; Q.FlowType = (LegType == SwapLegType.Fixed) ? FlowType.FixedRate : FlowType.FloatRate; Q.Notional = (double)Nominal; lf.Add(Q); nQ++; } } break; } case StubType.LongBoth: case StubType.ShortBoth: throw new NotImplementedException("Schedules with Both type stubs cannot be generated"); } if (NotionalExchange == ExchangeType.BackOnly || NotionalExchange == ExchangeType.Both) { lf.Add(new CashFlow { Notional = (double)Nominal * (Direction == SwapPayReceiveType.Receiver ? -1.0 : 1.0), Fv = (double)Nominal * (Direction == SwapPayReceiveType.Receiver ? -1.0 : 1.0), SettleDate = endDate, NotionalByYearFraction = 1.0, Dcf = 1.0, FlowType = FlowType.FixedAmount }); } f.Flows = lf.OrderBy(x => x.AccrualPeriodStart).ToList(); return(f); }