public LiborForwardModelProcess(int size, IborIndex index, IDiscretization disc) : base(disc) { size_ = size; index_ = index; initialValues_ = new InitializedList <double>(size_); fixingTimes_ = new InitializedList <double>(size); fixingDates_ = new InitializedList <Date>(size_); accrualStartTimes_ = new InitializedList <double>(size); accrualEndTimes_ = new InitializedList <double>(size); accrualPeriod_ = new InitializedList <double>(size_); m1 = new Vector(size_); m2 = new Vector(size_); DayCounter dayCounter = index.dayCounter(); IList <CashFlow> flows = cashFlows(1); if (!(size_ == flows.Count)) { throw new ArgumentException("wrong number of cashflows"); } Date settlement = index_.forwardingTermStructure().link.referenceDate(); Date startDate; IborCoupon iborcoupon = (IborCoupon)flows[0]; startDate = iborcoupon.fixingDate(); for (int i = 0; i < size_; ++i) { IborCoupon coupon = (IborCoupon)flows[i]; if (!(coupon.date() == coupon.accrualEndDate())) { throw new ArgumentException("irregular coupon types are not suppported"); } initialValues_[i] = coupon.rate(); accrualPeriod_[i] = coupon.accrualPeriod(); fixingDates_[i] = coupon.fixingDate(); fixingTimes_[i] = dayCounter.yearFraction(startDate, coupon.fixingDate()); accrualStartTimes_[i] = dayCounter.yearFraction(settlement, coupon.accrualStartDate()); accrualEndTimes_[i] = dayCounter.yearFraction(settlement, coupon.accrualEndDate()); } }
public override void setupArguments(IPricingEngineArguments args) { base.setupArguments(args); VanillaSwap.Arguments arguments = args as VanillaSwap.Arguments; if (arguments == null) // it's a swap engine... { return; } arguments.type = type_; arguments.nominal = nominal_; List <CashFlow> fixedCoupons = fixedLeg(); arguments.fixedResetDates = new InitializedList <Date>(fixedCoupons.Count); arguments.fixedPayDates = new InitializedList <Date>(fixedCoupons.Count); arguments.fixedCoupons = new InitializedList <double>(fixedCoupons.Count); for (int i = 0; i < fixedCoupons.Count; ++i) { FixedRateCoupon coupon = (FixedRateCoupon)fixedCoupons[i]; arguments.fixedPayDates[i] = coupon.date(); arguments.fixedResetDates[i] = coupon.accrualStartDate(); arguments.fixedCoupons[i] = coupon.amount(); } List <CashFlow> floatingCoupons = floatingLeg(); arguments.floatingResetDates = new InitializedList <Date>(floatingCoupons.Count); arguments.floatingPayDates = new InitializedList <Date>(floatingCoupons.Count); arguments.floatingFixingDates = new InitializedList <Date>(floatingCoupons.Count); arguments.floatingAccrualTimes = new InitializedList <double>(floatingCoupons.Count); arguments.floatingSpreads = new InitializedList <double>(floatingCoupons.Count); arguments.floatingCoupons = new InitializedList <double>(floatingCoupons.Count); for (int i = 0; i < floatingCoupons.Count; ++i) { IborCoupon coupon = (IborCoupon)floatingCoupons[i]; arguments.floatingResetDates[i] = coupon.accrualStartDate(); arguments.floatingPayDates[i] = coupon.date(); arguments.floatingFixingDates[i] = coupon.fixingDate(); arguments.floatingAccrualTimes[i] = coupon.accrualPeriod(); arguments.floatingSpreads[i] = coupon.spread(); try { arguments.floatingCoupons[i] = coupon.amount(); } catch { arguments.floatingCoupons[i] = default(double); } } }
public override void setupArguments(IPricingEngineArguments args) { base.setupArguments(args); BasisSwap.Arguments arguments = args as BasisSwap.Arguments; if (arguments == null) // it's a swap engine... { return; } arguments.type = type_; arguments.nominal = nominal_; List <CashFlow> floating1Coupons = floating1Leg(); arguments.floating1ResetDates = new InitializedList <Date>(floating1Coupons.Count); arguments.floating1PayDates = new InitializedList <Date>(floating1Coupons.Count); arguments.floating1FixingDates = new InitializedList <Date>(floating1Coupons.Count); arguments.floating1AccrualTimes = new InitializedList <double>(floating1Coupons.Count); arguments.floating1Spreads = new InitializedList <double>(floating1Coupons.Count); arguments.floating1Coupons = new InitializedList <double>(floating1Coupons.Count); for (int i = 0; i < floating1Coupons.Count; ++i) { IborCoupon coupon = (IborCoupon)floating1Coupons[i]; arguments.floating1ResetDates[i] = coupon.accrualStartDate(); arguments.floating1PayDates[i] = coupon.date(); arguments.floating1FixingDates[i] = coupon.fixingDate(); arguments.floating1AccrualTimes[i] = coupon.accrualPeriod(); arguments.floating1Spreads[i] = coupon.spread(); try { arguments.floating1Coupons[i] = coupon.amount(); } catch { arguments.floating1Coupons[i] = default(double); } } List <CashFlow> floating2Coupons = floating2Leg(); arguments.floating2ResetDates = new InitializedList <Date>(floating2Coupons.Count); arguments.floating2PayDates = new InitializedList <Date>(floating2Coupons.Count); arguments.floating2FixingDates = new InitializedList <Date>(floating2Coupons.Count); arguments.floating2AccrualTimes = new InitializedList <double>(floating2Coupons.Count); arguments.floating2Spreads = new InitializedList <double>(floating2Coupons.Count); arguments.floating2Coupons = new InitializedList <double>(floating2Coupons.Count); for (int i = 0; i < floating2Coupons.Count; ++i) { IborCoupon coupon = (IborCoupon)floating2Coupons[i]; arguments.floating2ResetDates[i] = coupon.accrualStartDate(); arguments.floating2PayDates[i] = coupon.date(); arguments.floating2FixingDates[i] = coupon.fixingDate(); arguments.floating2AccrualTimes[i] = coupon.accrualPeriod(); arguments.floating2Spreads[i] = coupon.spread(); try { arguments.floating2Coupons[i] = coupon.amount(); } catch { arguments.floating2Coupons[i] = default(double); } } }