// Constructors /*! If strike is given in the constructor, can calculate the * NPV of the contract via NPV(). * * If strike/forward price is desired, it can be obtained via * forwardPrice(). In this case, the strike variable in the * constructor is irrelevant and will be ignored. */ public FixedRateBondForward(Date valueDate, Date maturityDate, Position.Type type, double strike, int settlementDays, DayCounter dayCounter, Calendar calendar, BusinessDayConvention businessDayConvention, FixedRateBond fixedCouponBond, Handle <YieldTermStructure> discountCurve, Handle <YieldTermStructure> incomeDiscountCurve) : base(dayCounter, calendar, businessDayConvention, settlementDays, new ForwardTypePayoff(type, strike), valueDate, maturityDate, discountCurve) { fixedCouponBond_ = fixedCouponBond; incomeDiscountCurve_ = incomeDiscountCurve; incomeDiscountCurve_.registerWith(update); }
protected override void performCalculations() { List <BTP> btps = basket_.btps(); List <Handle <Quote> > quotes = basket_.cleanPriceQuotes(); Date bondSettlementDate = btps[0].settlementDate(); for (int i = 0; i < basket_.size(); ++i) { yields_[i] = BondFunctions.yield(btps[i], quotes[i].link.value(), new ActualActual(ActualActual.Convention.ISMA), Compounding.Compounded, Frequency.Annual, bondSettlementDate, // accuracy, maxIterations, guess 1.0e-10, 100, yields_[i]); durations_[i] = BondFunctions.duration(btps[i], yields_[i], new ActualActual(ActualActual.Convention.ISMA), Compounding.Compounded, Frequency.Annual, Duration.Type.Modified, bondSettlementDate); } duration_ = 0; basket_.weights().ForEach((ii, vv) => duration_ += vv * yields()[ii]); int settlDays = 2; DayCounter fixedDayCount = swaps_[0].fixedDayCount(); equivalentSwapIndex_ = nSwaps_ - 1; swapRates_[0] = swaps_[0].fairRate(); FixedRateBond swapBond = new FixedRateBond(settlDays, 100.0, // faceAmount swaps_[0].fixedSchedule(), new List <double>() { swapRates_[0].Value }, fixedDayCount, BusinessDayConvention.Following, // paymentConvention 100.0); // redemption swapBondYields_[0] = BondFunctions.yield(swapBond, 100.0, // floating leg NPV including end payment new ActualActual(ActualActual.Convention.ISMA), Compounding.Compounded, Frequency.Annual, bondSettlementDate, // accuracy, maxIterations, guess 1.0e-10, 100, swapBondYields_[0].Value); swapBondDurations_[0] = BondFunctions.duration(swapBond, swapBondYields_[0].Value, new ActualActual(ActualActual.Convention.ISMA), Compounding.Compounded, Frequency.Annual, Duration.Type.Modified, bondSettlementDate); for (int i = 1; i < nSwaps_; ++i) { swapRates_[i] = swaps_[i].fairRate(); FixedRateBond swapBond2 = new FixedRateBond(settlDays, 100.0, // faceAmount swaps_[i].fixedSchedule(), new List <double>() { swapRates_[i].Value }, fixedDayCount, BusinessDayConvention.Following, // paymentConvention 100.0); // redemption swapBondYields_[i] = BondFunctions.yield(swapBond2, 100.0, // floating leg NPV including end payment new ActualActual(ActualActual.Convention.ISMA), Compounding.Compounded, Frequency.Annual, bondSettlementDate, // accuracy, maxIterations, guess 1.0e-10, 100, swapBondYields_[i].Value); swapBondDurations_[i] = BondFunctions.duration(swapBond2, swapBondYields_[i].Value, new ActualActual(ActualActual.Convention.ISMA), Compounding.Compounded, Frequency.Annual, Duration.Type.Modified, bondSettlementDate); if (swapBondDurations_[i] > duration_) { equivalentSwapIndex_ = i - 1; break; // exit the loop } } return; }