businessDayConvention() private method

private businessDayConvention ( ) : BusinessDayConvention
return BusinessDayConvention
Exemplo n.º 1
0
        // Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>());
        public ForwardRateAgreement(Date valueDate, Date maturityDate, Position.Type type, double strikeForwardRate,
                                    double notionalAmount, IborIndex index, Handle <YieldTermStructure> discountCurve)
            : base(index.dayCounter(), index.fixingCalendar(), index.businessDayConvention(), index.fixingDays(), new Payoff(),
                   valueDate, maturityDate, discountCurve)
        {
            fraType_        = type;
            notionalAmount_ = notionalAmount;
            index_          = index;

            if (notionalAmount <= 0.0)
            {
                throw new ApplicationException("notional Amount must be positive");
            }

            // do I adjust this ?
            // valueDate_ = calendar_.adjust(valueDate_,businessDayConvention_);
            Date fixingDate = calendar_.advance(valueDate_, -settlementDays_, TimeUnit.Days);

            forwardRate_       = new InterestRate(index.fixing(fixingDate), index.dayCounter(), Compounding.Simple, Frequency.Once);
            strikeForwardRate_ = new InterestRate(strikeForwardRate, index.dayCounter(), Compounding.Simple, Frequency.Once);
            double strike = notionalAmount_ * strikeForwardRate_.compoundFactor(valueDate_, maturityDate_);

            payoff_ = new ForwardTypePayoff(fraType_, strike);
            // incomeDiscountCurve_ is irrelevant to an FRA
            incomeDiscountCurve_ = discountCurve_;
            // income is irrelevant to FRA - set it to zero
            underlyingIncome_ = 0.0;

            index_.registerWith(update);
        }
Exemplo n.º 2
0
      // Handle<YieldTermStructure> discountCurve = Handle<YieldTermStructure>());
      public ForwardRateAgreement(Date valueDate, Date maturityDate, Position.Type type, double strikeForwardRate,
                                  double notionalAmount, IborIndex index, Handle<YieldTermStructure> discountCurve)
         : base(index.dayCounter(), index.fixingCalendar(), index.businessDayConvention(), index.fixingDays(), new Payoff(),
                 valueDate, maturityDate, discountCurve) {

         fraType_ = type;
         notionalAmount_ = notionalAmount;
         index_ = index;

         if (notionalAmount <= 0.0)
            throw new ApplicationException("notional Amount must be positive");

         // do I adjust this ?
         // valueDate_ = calendar_.adjust(valueDate_,businessDayConvention_);
         Date fixingDate = calendar_.advance(valueDate_, -settlementDays_, TimeUnit.Days);
         forwardRate_ = new InterestRate(index.fixing(fixingDate), index.dayCounter(), Compounding.Simple, Frequency.Once);
         strikeForwardRate_ = new InterestRate(strikeForwardRate, index.dayCounter(), Compounding.Simple, Frequency.Once);
         double strike = notionalAmount_ * strikeForwardRate_.compoundFactor(valueDate_, maturityDate_);
         payoff_ = new ForwardTypePayoff(fraType_, strike);
         // incomeDiscountCurve_ is irrelevant to an FRA
         incomeDiscountCurve_ = discountCurve_;
         // income is irrelevant to FRA - set it to zero
         underlyingIncome_ = 0.0;
         
         index_.registerWith(update);
      }
Exemplo n.º 3
0
 public DepositRateHelper(double rate, IborIndex i)
     : base(rate)
 {
     iborIndex_ = new IborIndex("no-fix", // never take fixing into account
                                i.tenor(), i.fixingDays(), new Currency(),
                                i.fixingCalendar(), i.businessDayConvention(),
                                i.endOfMonth(), i.dayCounter(), termStructureHandle_);
     initializeDates();
 }
Exemplo n.º 4
0
 public DepositRateHelper(double rate, IborIndex i)
     : base(rate)
 {
     iborIndex_ = new IborIndex("no-fix", // never take fixing into account
                                i.tenor(), i.fixingDays(), new Currency(),
                                i.fixingCalendar(), i.businessDayConvention(),
                                i.endOfMonth(), i.dayCounter(), termStructureHandle_);
     initializeDates();
 }
Exemplo n.º 5
0
        protected override void initializeDates()
        {
            // why not using index_->fixingDays instead of settlementDays_
            Date settlement = iborIndex_.fixingCalendar().advance(evaluationDate_, iborIndex_.fixingDays(), TimeUnit.Days);

            earliestDate_ = iborIndex_.fixingCalendar().advance(settlement, periodToStart_,
                                                                iborIndex_.businessDayConvention(), iborIndex_.endOfMonth());
            latestDate_ = iborIndex_.maturityDate(earliestDate_);
            fixingDate_ = iborIndex_.fixingDate(earliestDate_);
        }
Exemplo n.º 6
0
 public MakeCms(Period swapTenor,
                SwapIndex swapIndex,
                IborIndex iborIndex,
                double iborSpread   = 0.0,
                Period forwardStart = null,
                Date maturityDate   = null)
 {
     swapTenor_     = swapTenor;
     swapIndex_     = swapIndex;
     iborIndex_     = iborIndex;
     iborSpread_    = iborSpread;
     iborCap_       = null;
     iborFloor_     = null;
     useAtmSpread_  = false;
     forwardStart_  = forwardStart ?? new Period(0, TimeUnit.Days);
     cmsSpread_     = 0.0;
     cmsGearing_    = 1.0;
     cmsCap_        = null;
     cmsFloor_      = null;
     effectiveDate_ = null;
     cmsCalendar_   = swapIndex.fixingCalendar();
     floatCalendar_ = iborIndex.fixingCalendar();
     payCms_        = true;
     nominal_       = 1.0;
     maturityDate_  = maturityDate;
     cmsTenor_      = new Period(3, TimeUnit.Months);
     floatTenor_    = iborIndex.tenor();
     cmsConvention_ = BusinessDayConvention.ModifiedFollowing;
     cmsTerminationDateConvention_ = BusinessDayConvention.ModifiedFollowing;
     floatConvention_ = iborIndex.businessDayConvention();
     floatTerminationDateConvention_ = iborIndex.businessDayConvention();
     cmsRule_             = DateGeneration.Rule.Backward;
     floatRule_           = DateGeneration.Rule.Backward;
     cmsEndOfMonth_       = false;
     floatEndOfMonth_     = false;
     cmsFirstDate_        = null;
     cmsNextToLastDate_   = null;
     floatFirstDate_      = null;
     floatNextToLastDate_ = null;
     cmsDayCount_         = new Actual360();
     floatDayCount_       = iborIndex.dayCounter();
     engine_ = new DiscountingSwapEngine(swapIndex.forwardingTermStructure());
 }
Exemplo n.º 7
0
        public List <CashFlow> cashFlows(double amount)
        {
            Date refDate = index_.forwardingTermStructure().link.referenceDate();

            Schedule schedule = new Schedule(refDate,
                                             refDate + new Period(index_.tenor().length() * size_,
                                                                  index_.tenor().units()),
                                             index_.tenor(), index_.fixingCalendar(),
                                             index_.businessDayConvention(),
                                             index_.businessDayConvention(),
                                             DateGeneration.Rule.Forward, false);

            IborLeg cashflows = (IborLeg) new IborLeg(schedule, index_)
                                .withFixingDays(index_.fixingDays())
                                .withPaymentDayCounter(index_.dayCounter())
                                .withNotionals(amount)
                                .withPaymentAdjustment(index_.businessDayConvention());

            return(cashflows.value());
        }
Exemplo n.º 8
0
        public FraRateHelper(double rate, int monthsToStart, IborIndex i) : base(rate)
        {
            periodToStart_ = new Period(monthsToStart, TimeUnit.Months);

            iborIndex_ = new IborIndex("no-fix",  // never take fixing into account
                                       i.tenor(), i.fixingDays(), new Currency(),
                                       i.fixingCalendar(), i.businessDayConvention(),
                                       i.endOfMonth(), i.dayCounter(), termStructureHandle_);

            initializeDates();
        }
Exemplo n.º 9
0
        public FRARateHelper(double rate, int monthsToStart, IborIndex i)
            : base(rate)
        {
            periodToStart_ = new Period(monthsToStart, TimeUnit.Months);

            iborIndex_ = new IborIndex("no-fix",  // never take fixing into account
                                       i.tenor(), i.fixingDays(), new Currency(),
                                       i.fixingCalendar(), i.businessDayConvention(),
                                       i.endOfMonth(), i.dayCounter(), termStructureHandle_);

            initializeDates();
        }
Exemplo n.º 10
0
        public FuturesRateHelper(double price, Date immDate, IborIndex i, double convAdj)
            : base(price)
        {
            convAdj_ = new Handle<Quote>(new SimpleQuote(convAdj));

            if (!IMM.isIMMdate(immDate, false)) throw new ArgumentException(immDate + "is not a valid IMM date");
            earliestDate_ = immDate;

            Calendar cal = i.fixingCalendar();
            latestDate_ = cal.advance(immDate, i.tenor(), i.businessDayConvention());
            yearFraction_ = i.dayCounter().yearFraction(earliestDate_, latestDate_);
        }
Exemplo n.º 11
0
        public SwaptionHelper(Period maturity,
                              Period length,
                              Handle <Quote> volatility,
                              IborIndex index,
                              Period fixedLegTenor,
                              DayCounter fixedLegDayCounter,
                              DayCounter floatingLegDayCounter,
                              Handle <YieldTermStructure> termStructure,
                              bool calibrateVolatility /*= false*/)
            : base(volatility, termStructure, calibrateVolatility)
        {
            Calendar calendar   = index.fixingCalendar();
            Period   indexTenor = index.tenor();
            int      fixingDays = index.fixingDays();

            Date exerciseDate = calendar.advance(termStructure.link.referenceDate(),
                                                 maturity,
                                                 index.businessDayConvention());
            Date startDate = calendar.advance(exerciseDate,
                                              fixingDays, TimeUnit.Days,
                                              index.businessDayConvention());
            Date endDate = calendar.advance(startDate, length,
                                            index.businessDayConvention());

            Schedule fixedSchedule = new Schedule(startDate, endDate, fixedLegTenor, calendar,
                                                  index.businessDayConvention(),
                                                  index.businessDayConvention(),
                                                  DateGeneration.Rule.Forward, false);
            Schedule floatSchedule = new Schedule(startDate, endDate, index.tenor(), calendar,
                                                  index.businessDayConvention(),
                                                  index.businessDayConvention(),
                                                  DateGeneration.Rule.Forward, false);

            IPricingEngine swapEngine = new DiscountingSwapEngine(termStructure);

            VanillaSwap temp = new VanillaSwap(VanillaSwap.Type.Receiver, 1.0,
                                               fixedSchedule, 0.0, fixedLegDayCounter,
                                               floatSchedule, index, 0.0, floatingLegDayCounter);

            temp.setPricingEngine(swapEngine);
            exerciseRate_ = temp.fairRate();
            swap_         = new VanillaSwap(VanillaSwap.Type.Receiver, 1.0,
                                            fixedSchedule, exerciseRate_, fixedLegDayCounter,
                                            floatSchedule, index, 0.0, floatingLegDayCounter);
            swap_.setPricingEngine(swapEngine);

            Exercise exercise = new EuropeanExercise(exerciseDate);

            swaption_    = new Swaption(swap_, exercise);
            marketValue_ = blackPrice(volatility_.link.value());
        }
Exemplo n.º 12
0
        public FuturesRateHelper(double price, Date immDate, IborIndex i, double convAdj)
            : base(price)
        {
            convAdj_ = new Handle <Quote>(new SimpleQuote(convAdj));

            if (!IMM.isIMMdate(immDate, false))
            {
                throw new ArgumentException(immDate + "is not a valid IMM date");
            }
            earliestDate_ = immDate;

            Calendar cal = i.fixingCalendar();

            latestDate_   = cal.advance(immDate, i.tenor(), i.businessDayConvention());
            yearFraction_ = i.dayCounter().yearFraction(earliestDate_, latestDate_);
        }
Exemplo n.º 13
0
        public SwaptionHelper(Period maturity,
            Period length,
            Handle<Quote> volatility,
            IborIndex index,
            Period fixedLegTenor,
            DayCounter fixedLegDayCounter,
            DayCounter floatingLegDayCounter,
            Handle<YieldTermStructure> termStructure,
            bool calibrateVolatility /*= false*/)
            : base(volatility,termStructure, calibrateVolatility)
        {
            Calendar calendar = index.fixingCalendar();
            Period indexTenor = index.tenor();
            int fixingDays = index.fixingDays();

            Date exerciseDate   = calendar.advance(termStructure.link.referenceDate(),
                                                maturity,
                                                index.businessDayConvention());
            Date startDate      = calendar.advance(exerciseDate,
                                                fixingDays, TimeUnit.Days,
                                                index.businessDayConvention());
            Date endDate        = calendar.advance(startDate, length,
                                                index.businessDayConvention());

            Schedule fixedSchedule=new Schedule(startDate, endDate, fixedLegTenor, calendar,
                                            index.businessDayConvention(),
                                            index.businessDayConvention(),
                                            DateGeneration.Rule.Forward, false);
            Schedule floatSchedule=new Schedule(startDate, endDate, index.tenor(), calendar,
                                            index.businessDayConvention(),
                                            index.businessDayConvention(),
                                            DateGeneration.Rule.Forward, false);

            IPricingEngine swapEngine=new DiscountingSwapEngine(termStructure);

            VanillaSwap temp=new VanillaSwap(VanillaSwap.Type.Receiver, 1.0,
                                        fixedSchedule, 0.0, fixedLegDayCounter,
                                        floatSchedule, index, 0.0, floatingLegDayCounter);
            temp.setPricingEngine(swapEngine);
            exerciseRate_ = temp.fairRate();
            swap_ = new VanillaSwap(VanillaSwap.Type.Receiver, 1.0,
                            fixedSchedule, exerciseRate_, fixedLegDayCounter,
                            floatSchedule, index, 0.0, floatingLegDayCounter);
            swap_.setPricingEngine(swapEngine);

            Exercise exercise=new EuropeanExercise(exerciseDate);
            swaption_ = new Swaption(swap_, exercise);
            marketValue_ = blackPrice(volatility_.link.value());
        }
Exemplo n.º 14
0
        public MakeVanillaSwap(Period swapTenor, IborIndex index, double? fixedRate, Period forwardStart) {
            swapTenor_ = swapTenor;
            iborIndex_ = index;
            fixedRate_ = fixedRate;
            forwardStart_ = forwardStart;
            effectiveDate_ = null;
            fixedCalendar_ = floatCalendar_ = index.fixingCalendar();
            
            type_ = VanillaSwap.Type.Payer;
            nominal_ = 1.0;
            fixedTenor_ = new Period(1, TimeUnit.Years);
            floatTenor_ = index.tenor();
            fixedConvention_ = fixedTerminationDateConvention_ = BusinessDayConvention.ModifiedFollowing;
            floatConvention_ = floatTerminationDateConvention_ = index.businessDayConvention();
            fixedRule_ = floatRule_ = DateGeneration.Rule.Backward;
            fixedEndOfMonth_ = floatEndOfMonth_ = false;
            fixedFirstDate_ = fixedNextToLastDate_ = floatFirstDate_ = floatNextToLastDate_ = null;
            floatSpread_ = 0.0;
            fixedDayCount_ = new Thirty360(Thirty360.Thirty360Convention.BondBasis);
            floatDayCount_ = index.dayCounter();

            engine_ = new DiscountingSwapEngine(index.forwardingTermStructure());
        }
Exemplo n.º 15
0
        protected override void initializeDates()
        {
            earliestDate_ = calendar_.advance(evaluationDate_, new Period(settlementDays_, TimeUnit.Days),
                                              BusinessDayConvention.Following);

            Date maturity = earliestDate_ + tenor_;

            // dummy BMA index with curve/swap arguments
            BMAIndex clonedIndex = new BMAIndex(termStructureHandle_);

            Schedule bmaSchedule = new MakeSchedule().from(earliestDate_).to(maturity)
                                   .withTenor(bmaPeriod_)
                                   .withCalendar(bmaIndex_.fixingCalendar())
                                   .withConvention(bmaConvention_)
                                   .backwards()
                                   .value();

            Schedule liborSchedule = new MakeSchedule().from(earliestDate_).to(maturity)
                                     .withTenor(iborIndex_.tenor())
                                     .withCalendar(iborIndex_.fixingCalendar())
                                     .withConvention(iborIndex_.businessDayConvention())
                                     .endOfMonth(iborIndex_.endOfMonth())
                                     .backwards()
                                     .value();

            swap_ = new BMASwap(BMASwap.Type.Payer, 100.0, liborSchedule, 0.75,             // arbitrary
                                0.0, iborIndex_, iborIndex_.dayCounter(), bmaSchedule, clonedIndex, bmaDayCount_);
            swap_.setPricingEngine(new DiscountingSwapEngine(iborIndex_.forwardingTermStructure()));

            Date d             = calendar_.adjust(swap_.maturityDate(), BusinessDayConvention.Following);
            int  w             = d.weekday();
            Date nextWednesday = (w >= 4) ? d + new Period((11 - w), TimeUnit.Days) :
                                 d + new Period((4 - w), TimeUnit.Days);

            latestDate_ = clonedIndex.valueDate(clonedIndex.fixingCalendar().adjust(nextWednesday));
        }
Exemplo n.º 16
0
        public MakeBasisSwap(Period swapTenor, IborIndex index1, IborIndex index2, Period forwardStart)
        {
            swapTenor_      = swapTenor;
            iborIndex1_     = index1;
            iborIndex2_     = index2;
            forwardStart_   = forwardStart;
            effectiveDate_  = null;
            float1Calendar_ = float2Calendar_ = index1.fixingCalendar();

            type_             = BasisSwap.Type.Payer;
            nominal_          = 1.0;
            float1Tenor_      = index1.tenor();
            float2Tenor_      = index2.tenor();
            float1Convention_ = float1TerminationDateConvention_ = index1.businessDayConvention();
            float2Convention_ = float2TerminationDateConvention_ = index2.businessDayConvention();
            float1Rule_       = float2Rule_ = DateGeneration.Rule.Backward;
            float1EndOfMonth_ = float2EndOfMonth_ = false;
            float1FirstDate_  = float1NextToLastDate_ = float2FirstDate_ = float2NextToLastDate_ = null;
            float1Spread_     = float2Spread_ = 0.0;
            float1DayCount_   = index1.dayCounter();
            float2DayCount_   = index2.dayCounter();

            engine_ = new DiscountingBasisSwapEngine(index1.forwardingTermStructure(), index2.forwardingTermStructure());
        }
Exemplo n.º 17
0
        public MakeBasisSwap(Period swapTenor, IborIndex index1, IborIndex index2, Period forwardStart)
        {
            swapTenor_ = swapTenor;
             iborIndex1_ = index1;
             iborIndex2_ = index2;
             forwardStart_ = forwardStart;
             effectiveDate_ = null;
             float1Calendar_ = float2Calendar_ = index1.fixingCalendar();

             type_ = BasisSwap.Type.Payer;
             nominal_ = 1.0;
             float1Tenor_ = index1.tenor();
             float2Tenor_ = index2.tenor();
             float1Convention_ = float1TerminationDateConvention_ = index1.businessDayConvention();
             float2Convention_ = float2TerminationDateConvention_ = index2.businessDayConvention();
             float1Rule_ = float2Rule_ = DateGeneration.Rule.Backward;
             float1EndOfMonth_ = float2EndOfMonth_ = false;
             float1FirstDate_ = float1NextToLastDate_ = float2FirstDate_ = float2NextToLastDate_ = null;
             float1Spread_ = float2Spread_ = 0.0;
             float1DayCount_ = index1.dayCounter();
             float2DayCount_ = index2.dayCounter();

             engine_ = new DiscountingBasisSwapEngine(index1.forwardingTermStructure(), index2.forwardingTermStructure());
        }
Exemplo n.º 18
0
        public MakeVanillaSwap(Period swapTenor, IborIndex index, double?fixedRate, Period forwardStart)
        {
            swapTenor_     = swapTenor;
            iborIndex_     = index;
            fixedRate_     = fixedRate;
            forwardStart_  = forwardStart;
            effectiveDate_ = null;
            fixedCalendar_ = floatCalendar_ = index.fixingCalendar();

            type_            = VanillaSwap.Type.Payer;
            nominal_         = 1.0;
            fixedTenor_      = new Period(1, TimeUnit.Years);
            floatTenor_      = index.tenor();
            fixedConvention_ = fixedTerminationDateConvention_ = BusinessDayConvention.ModifiedFollowing;
            floatConvention_ = floatTerminationDateConvention_ = index.businessDayConvention();
            fixedRule_       = floatRule_ = DateGeneration.Rule.Backward;
            fixedEndOfMonth_ = floatEndOfMonth_ = false;
            fixedFirstDate_  = fixedNextToLastDate_ = floatFirstDate_ = floatNextToLastDate_ = null;
            floatSpread_     = 0.0;
            fixedDayCount_   = new Thirty360(Thirty360.Thirty360Convention.BondBasis);
            floatDayCount_   = index.dayCounter();

            engine_ = new DiscountingSwapEngine(index.forwardingTermStructure());
        }
Exemplo n.º 19
0
        public AssetSwap(bool payBondCoupon,
                       Bond bond,
                       double bondCleanPrice,
                       IborIndex iborIndex,
                       double spread,
                       Schedule floatSchedule = null,
                       DayCounter floatingDayCount = null,
                       bool parAssetSwap = true)
            : base(2)
        {
            bond_ = bond;
             bondCleanPrice_ = bondCleanPrice;
             nonParRepayment_ = 100;
             spread_ = spread;
             parSwap_ = parAssetSwap;

             Schedule schedule = floatSchedule;
             if (floatSchedule == null)
            schedule = new Schedule(bond_.settlementDate(),
                                    bond_.maturityDate(),
                                    iborIndex.tenor(),
                                    iborIndex.fixingCalendar(),
                                    iborIndex.businessDayConvention(),
                                    iborIndex.businessDayConvention(),
                                    DateGeneration.Rule.Backward,
                                    false); // endOfMonth

             // the following might become an input parameter
             BusinessDayConvention paymentAdjustment = BusinessDayConvention.Following;

             Date finalDate = schedule.calendar().adjust(schedule.endDate(), paymentAdjustment);
             Date adjBondMaturityDate = schedule.calendar().adjust(bond_.maturityDate(), paymentAdjustment);

             Utils.QL_REQUIRE( finalDate == adjBondMaturityDate, () =>
                          "adjusted schedule end date (" +
                          finalDate +
                          ") must be equal to adjusted bond maturity date (" +
                          adjBondMaturityDate + ")");

             // bondCleanPrice must be the (forward) clean price
             // at the floating schedule start date
             upfrontDate_ = schedule.startDate();
             double dirtyPrice = bondCleanPrice_ +
                             bond_.accruedAmount(upfrontDate_);

             double notional = bond_.notional(upfrontDate_);
             /* In the market asset swap, the bond is purchased in return for
            payment of the full price. The notional of the floating leg is
            then scaled by the full price. */
             if (!parSwap_)
            notional *= dirtyPrice / 100.0;

             if (floatingDayCount == null)
            legs_[1] = new IborLeg(schedule, iborIndex)
                .withSpreads(spread)
                .withNotionals(notional)
                .withPaymentAdjustment(paymentAdjustment);
             else
            legs_[1] = new IborLeg(schedule, iborIndex)
                .withSpreads(spread)
                .withPaymentDayCounter(floatingDayCount)
                .withNotionals(notional)
                .withPaymentAdjustment(paymentAdjustment);

             foreach (CashFlow c in legs_[1])
            c.registerWith(update);

             List<CashFlow> bondLeg = bond_.cashflows();
             foreach (CashFlow c in bondLeg)
             {
            // whatever might be the choice for the discounting engine
            // bond flows on upfrontDate_ must be discarded
            bool upfrontDateBondFlows = false;
            if (!(c.hasOccurred(upfrontDate_, upfrontDateBondFlows)))
               legs_[0].Add(c);
             }

             Utils.QL_REQUIRE( !legs_[0].empty(), () => "empty bond leg to start with" );

             // special flows
             if (parSwap_)
             {
            // upfront on the floating leg
            double upfront = (dirtyPrice - 100.0) / 100.0 * notional;
            CashFlow upfrontCashFlow = new SimpleCashFlow(upfront, upfrontDate_);
            legs_[1].Insert(0, upfrontCashFlow);
            // backpayment on the floating leg
            // (accounts for non-par redemption, if any)
            double backPayment = notional;
            CashFlow backPaymentCashFlow = new SimpleCashFlow(backPayment, finalDate);
            legs_[1].Add(backPaymentCashFlow);
             }
             else
             {
            // final notional exchange
            CashFlow finalCashFlow = new SimpleCashFlow(notional, finalDate);
            legs_[1].Add(finalCashFlow);
             }

             Utils.QL_REQUIRE( !legs_[0].empty(), () => "empty bond leg" );

             foreach (CashFlow c in legs_[0])
            c.registerWith(update);

             if (payBondCoupon)
             {
            payer_[0] = -1.0;
            payer_[1] = +1.0;
             }
             else
             {
            payer_[0] = +1.0;
            payer_[1] = -1.0;
             }
        }
Exemplo n.º 20
0
            public CommonVars()
            {
                settlementDays = 2;
                nominal = 1000000.0;
                fixedConvention = BusinessDayConvention.Unadjusted;

                fixedFrequency = Frequency.Annual;
                fixedDayCount = new Thirty360();

                index =new Euribor6M(termStructure);
                floatingConvention = index.businessDayConvention();
                floatingTenor = index.tenor();
                calendar = index.fixingCalendar();
                today = calendar.adjust(Date.Today);
                Settings.setEvaluationDate(today);
                settlement = calendar.advance(today, settlementDays, TimeUnit.Days);

                termStructure.linkTo(Utilities.flatRate(settlement, 0.05, new Actual365Fixed()));
            }
Exemplo n.º 21
0
        public AssetSwap(bool parAssetSwap,
                       Bond bond,
                       double bondCleanPrice,
                       double nonParRepayment,
                       double gearing,
                       IborIndex iborIndex,
                       double spread = 0.0,
                       DayCounter floatingDayCount = null,
                       Date dealMaturity = null,
                       bool payBondCoupon = false)
            : base(2)
        {
            bond_ = bond;
             bondCleanPrice_ = bondCleanPrice;
             nonParRepayment_ = nonParRepayment;
             spread_ = spread;
             parSwap_ = parAssetSwap;

             Schedule tempSch = new Schedule(bond_.settlementDate(),
                                         bond_.maturityDate(),
                                         iborIndex.tenor(),
                                         iborIndex.fixingCalendar(),
                                         iborIndex.businessDayConvention(),
                                         iborIndex.businessDayConvention(),
                                         DateGeneration.Rule.Backward,
                                         false); // endOfMonth

             if (dealMaturity == null)
            dealMaturity = bond_.maturityDate();

             Utils.QL_REQUIRE( dealMaturity <= tempSch.dates().Last(), () =>
                     "deal maturity " + dealMaturity +
                     " cannot be later than (adjusted) bond maturity " +
                     tempSch.dates().Last());
             Utils.QL_REQUIRE( dealMaturity > tempSch.dates()[0], () =>
                     "deal maturity " + dealMaturity +
                     " must be later than swap start date " +
                     tempSch.dates()[0]);

             // the following might become an input parameter
             BusinessDayConvention paymentAdjustment = BusinessDayConvention.Following;

             Date finalDate = tempSch.calendar().adjust(dealMaturity, paymentAdjustment);
             Schedule schedule = tempSch.until(finalDate);

             // bondCleanPrice must be the (forward) clean price
             // at the floating schedule start date
             upfrontDate_ = schedule.startDate();
             double dirtyPrice = bondCleanPrice_ +
                             bond_.accruedAmount(upfrontDate_);

             double notional = bond_.notional(upfrontDate_);
             /* In the market asset swap, the bond is purchased in return for
            payment of the full price. The notional of the floating leg is
            then scaled by the full price. */
             if (!parSwap_)
            notional *= dirtyPrice / 100.0;

             if (floatingDayCount == null)
            legs_[1] = new IborLeg(schedule, iborIndex)
                  .withSpreads(spread)
                  .withGearings(gearing)
                  .withNotionals(notional)
                  .withPaymentAdjustment(paymentAdjustment);
             else
            legs_[1] = new IborLeg(schedule, iborIndex)
                  .withSpreads(spread)
                  .withGearings(gearing)
                  .withPaymentDayCounter(floatingDayCount)
                  .withNotionals(notional)
                  .withPaymentAdjustment(paymentAdjustment);

             foreach (CashFlow c in legs_[1])
            c.registerWith(update);

             List<CashFlow> bondLeg = bond_.cashflows();
             // skip bond redemption
             int i;
             for (i = 0; i < bondLeg.Count && bondLeg[i].date() <= dealMaturity; ++i)
             {
            // whatever might be the choice for the discounting engine
            // bond flows on upfrontDate_ must be discarded
            bool upfrontDateBondFlows = false;
            if (!bondLeg[i].hasOccurred(upfrontDate_, upfrontDateBondFlows))
               legs_[0].Add(bondLeg[i]);
             }
             // if the first skipped cashflow is not the redemption
             // and it is a coupon then add the accrued coupon
             if (i < bondLeg.Count - 1)
             {
            Coupon c = bondLeg[i] as Coupon;
            if (c != null)
            {
               CashFlow accruedCoupon = new SimpleCashFlow(c.accruedAmount(dealMaturity), finalDate);
               legs_[0].Add(accruedCoupon);
            }
             }
             // add the nonParRepayment_
             CashFlow nonParRepaymentFlow = new SimpleCashFlow(nonParRepayment_, finalDate);
             legs_[0].Add(nonParRepaymentFlow);

             Utils.QL_REQUIRE( !legs_[0].empty(), () => "empty bond leg to start with" );

             // special flows
             if (parSwap_)
             {
            // upfront on the floating leg
            double upfront = (dirtyPrice - 100.0) / 100.0 * notional;
            CashFlow upfrontCashFlow = new SimpleCashFlow(upfront, upfrontDate_);
            legs_[1].Insert(0, upfrontCashFlow);
            // backpayment on the floating leg
            // (accounts for non-par redemption, if any)
            double backPayment = notional;
            CashFlow backPaymentCashFlow = new SimpleCashFlow(backPayment, finalDate);
            legs_[1].Add(backPaymentCashFlow);
             }
             else
             {
            // final notional exchange
            CashFlow finalCashFlow = new SimpleCashFlow(notional, finalDate);
            legs_[1].Add(finalCashFlow);
             }

             Utils.QL_REQUIRE( !legs_[0].empty(), () => "empty bond leg" );

             foreach (CashFlow c in legs_[0])
            c.registerWith(update);

             if (payBondCoupon)
             {
            payer_[0] = -1.0;
            payer_[1] = +1.0;
             }
             else
             {
            payer_[0] = +1.0;
            payer_[1] = -1.0;
             }
        }
Exemplo n.º 22
0
        public CapHelper(Period length,
            Handle<Quote> volatility,
            IborIndex index,
            // data for ATM swap-rate calculation
            Frequency fixedLegFrequency,
            DayCounter fixedLegDayCounter,
            bool includeFirstSwaplet,
            Handle<YieldTermStructure> termStructure,
            bool calibrateVolatility /*= false*/)
            : base(volatility, termStructure, calibrateVolatility)
        {
            Period indexTenor = index.tenor();
            double fixedRate = 0.04; // dummy value
            Date startDate, maturity;
            if (includeFirstSwaplet) {
                startDate = termStructure.link.referenceDate();
                maturity = termStructure.link.referenceDate() + length;
            } else {
                startDate = termStructure.link.referenceDate() + indexTenor;
                maturity = termStructure.link.referenceDate() + length;
            }
            IborIndex dummyIndex=new
                IborIndex("dummy",
                          indexTenor,
                          index.fixingDays(),
                          index.currency(),
                          index.fixingCalendar(),
                          index.businessDayConvention(),
                          index.endOfMonth(),
                          termStructure.link.dayCounter(),
                          termStructure);

            List<double> nominals = new InitializedList<double>(1,1.0);

            Schedule floatSchedule=new Schedule(startDate, maturity,
                                   index.tenor(), index.fixingCalendar(),
                                   index.businessDayConvention(),
                                   index.businessDayConvention(),
                                   DateGeneration.Rule.Forward, false);
            List<CashFlow> floatingLeg;
            IborLeg iborLeg = (IborLeg) new IborLeg(floatSchedule, index)
                                            .withFixingDays(0)
                                            .withNotionals(nominals)
                                            .withPaymentAdjustment(index.businessDayConvention());
            floatingLeg = iborLeg.value();
            Schedule fixedSchedule=new Schedule(startDate, maturity, new Period(fixedLegFrequency),
                                   index.fixingCalendar(),
                                   BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                   DateGeneration.Rule.Forward, false);
            List<CashFlow> fixedLeg = new FixedRateLeg(fixedSchedule)
                .withCouponRates(fixedRate, fixedLegDayCounter)
                .withNotionals(nominals)
                .withPaymentAdjustment(index.businessDayConvention());

            Swap swap = new Swap(floatingLeg, fixedLeg);
            swap.setPricingEngine(new DiscountingSwapEngine(termStructure));
            double bp = 1.0e-4;
            double fairRate = fixedRate - (double)(swap.NPV()/(swap.legBPS(1) / bp));
            List<double> exerciceRate = new InitializedList<double>(1,fairRate);
            cap_ = new Cap(floatingLeg, exerciceRate);
            marketValue_ = blackPrice(volatility_.link.value());
        }
Exemplo n.º 23
0
        public CapHelper(Period length,
                         Handle <Quote> volatility,
                         IborIndex index,
                         // data for ATM swap-rate calculation
                         Frequency fixedLegFrequency,
                         DayCounter fixedLegDayCounter,
                         bool includeFirstSwaplet,
                         Handle <YieldTermStructure> termStructure,
                         bool calibrateVolatility /*= false*/)
            : base(volatility, termStructure, calibrateVolatility)
        {
            Period indexTenor = index.tenor();
            double fixedRate = 0.04; // dummy value
            Date   startDate, maturity;

            if (includeFirstSwaplet)
            {
                startDate = termStructure.link.referenceDate();
                maturity  = termStructure.link.referenceDate() + length;
            }
            else
            {
                startDate = termStructure.link.referenceDate() + indexTenor;
                maturity  = termStructure.link.referenceDate() + length;
            }
            IborIndex dummyIndex = new
                                   IborIndex("dummy",
                                             indexTenor,
                                             index.fixingDays(),
                                             index.currency(),
                                             index.fixingCalendar(),
                                             index.businessDayConvention(),
                                             index.endOfMonth(),
                                             termStructure.link.dayCounter(),
                                             termStructure);

            List <double> nominals = new InitializedList <double>(1, 1.0);

            Schedule floatSchedule = new Schedule(startDate, maturity,
                                                  index.tenor(), index.fixingCalendar(),
                                                  index.businessDayConvention(),
                                                  index.businessDayConvention(),
                                                  DateGeneration.Rule.Forward, false);
            List <CashFlow> floatingLeg;
            IborLeg         iborLeg = (IborLeg) new IborLeg(floatSchedule, index)
                                      .withFixingDays(0)
                                      .withNotionals(nominals)
                                      .withPaymentAdjustment(index.businessDayConvention());

            floatingLeg = iborLeg.value();
            Schedule fixedSchedule = new Schedule(startDate, maturity, new Period(fixedLegFrequency),
                                                  index.fixingCalendar(),
                                                  BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                                  DateGeneration.Rule.Forward, false);
            List <CashFlow> fixedLeg = new FixedRateLeg(fixedSchedule)
                                       .withCouponRates(fixedRate, fixedLegDayCounter)
                                       .withNotionals(nominals)
                                       .withPaymentAdjustment(index.businessDayConvention());

            Swap swap = new Swap(floatingLeg, fixedLeg);

            swap.setPricingEngine(new DiscountingSwapEngine(termStructure));
            double        bp           = 1.0e-4;
            double        fairRate     = fixedRate - (double)(swap.NPV() / (swap.legBPS(1) / bp));
            List <double> exerciceRate = new InitializedList <double>(1, fairRate);

            cap_         = new Cap(floatingLeg, exerciceRate);
            marketValue_ = blackPrice(volatility_.link.value());
        }
Exemplo n.º 24
0
        public AssetSwap(bool parAssetSwap,
                         Bond bond,
                         double bondCleanPrice,
                         double nonParRepayment,
                         double gearing,
                         IborIndex iborIndex,
                         double spread = 0.0,
                         DayCounter floatingDayCount = null,
                         Date dealMaturity           = null,
                         bool payBondCoupon          = false)
            : base(2)
        {
            bond_            = bond;
            bondCleanPrice_  = bondCleanPrice;
            nonParRepayment_ = nonParRepayment;
            spread_          = spread;
            parSwap_         = parAssetSwap;

            Schedule tempSch = new Schedule(bond_.settlementDate(),
                                            bond_.maturityDate(),
                                            iborIndex.tenor(),
                                            iborIndex.fixingCalendar(),
                                            iborIndex.businessDayConvention(),
                                            iborIndex.businessDayConvention(),
                                            DateGeneration.Rule.Backward,
                                            false); // endOfMonth

            if (dealMaturity == null)
            {
                dealMaturity = bond_.maturityDate();
            }

            Utils.QL_REQUIRE(dealMaturity <= tempSch.dates().Last(), () =>
                             "deal maturity " + dealMaturity +
                             " cannot be later than (adjusted) bond maturity " +
                             tempSch.dates().Last());
            Utils.QL_REQUIRE(dealMaturity > tempSch.dates()[0], () =>
                             "deal maturity " + dealMaturity +
                             " must be later than swap start date " +
                             tempSch.dates()[0]);

            // the following might become an input parameter
            BusinessDayConvention paymentAdjustment = BusinessDayConvention.Following;

            Date     finalDate = tempSch.calendar().adjust(dealMaturity, paymentAdjustment);
            Schedule schedule  = tempSch.until(finalDate);

            // bondCleanPrice must be the (forward) clean price
            // at the floating schedule start date
            upfrontDate_ = schedule.startDate();
            double dirtyPrice = bondCleanPrice_ +
                                bond_.accruedAmount(upfrontDate_);

            double notional = bond_.notional(upfrontDate_);

            /* In the market asset swap, the bond is purchased in return for
             * payment of the full price. The notional of the floating leg is
             * then scaled by the full price. */
            if (!parSwap_)
            {
                notional *= dirtyPrice / 100.0;
            }

            if (floatingDayCount == null)
            {
                legs_[1] = new IborLeg(schedule, iborIndex)
                           .withSpreads(spread)
                           .withGearings(gearing)
                           .withNotionals(notional)
                           .withPaymentAdjustment(paymentAdjustment);
            }
            else
            {
                legs_[1] = new IborLeg(schedule, iborIndex)
                           .withSpreads(spread)
                           .withGearings(gearing)
                           .withPaymentDayCounter(floatingDayCount)
                           .withNotionals(notional)
                           .withPaymentAdjustment(paymentAdjustment);
            }

            foreach (CashFlow c in legs_[1])
            {
                c.registerWith(update);
            }


            List <CashFlow> bondLeg = bond_.cashflows();
            // skip bond redemption
            int i;

            for (i = 0; i < bondLeg.Count && bondLeg[i].date() <= dealMaturity; ++i)
            {
                // whatever might be the choice for the discounting engine
                // bond flows on upfrontDate_ must be discarded
                bool upfrontDateBondFlows = false;
                if (!bondLeg[i].hasOccurred(upfrontDate_, upfrontDateBondFlows))
                {
                    legs_[0].Add(bondLeg[i]);
                }
            }
            // if the first skipped cashflow is not the redemption
            // and it is a coupon then add the accrued coupon
            if (i < bondLeg.Count - 1)
            {
                Coupon c = bondLeg[i] as Coupon;
                if (c != null)
                {
                    CashFlow accruedCoupon = new SimpleCashFlow(c.accruedAmount(dealMaturity), finalDate);
                    legs_[0].Add(accruedCoupon);
                }
            }
            // add the nonParRepayment_
            CashFlow nonParRepaymentFlow = new SimpleCashFlow(nonParRepayment_, finalDate);

            legs_[0].Add(nonParRepaymentFlow);

            Utils.QL_REQUIRE(!legs_[0].empty(), () => "empty bond leg to start with");

            // special flows
            if (parSwap_)
            {
                // upfront on the floating leg
                double   upfront         = (dirtyPrice - 100.0) / 100.0 * notional;
                CashFlow upfrontCashFlow = new SimpleCashFlow(upfront, upfrontDate_);
                legs_[1].Insert(0, upfrontCashFlow);
                // backpayment on the floating leg
                // (accounts for non-par redemption, if any)
                double   backPayment         = notional;
                CashFlow backPaymentCashFlow = new SimpleCashFlow(backPayment, finalDate);
                legs_[1].Add(backPaymentCashFlow);
            }
            else
            {
                // final notional exchange
                CashFlow finalCashFlow = new SimpleCashFlow(notional, finalDate);
                legs_[1].Add(finalCashFlow);
            }

            Utils.QL_REQUIRE(!legs_[0].empty(), () => "empty bond leg");

            foreach (CashFlow c in legs_[0])
            {
                c.registerWith(update);
            }

            if (payBondCoupon)
            {
                payer_[0] = -1.0;
                payer_[1] = +1.0;
            }
            else
            {
                payer_[0] = +1.0;
                payer_[1] = -1.0;
            }
        }
Exemplo n.º 25
0
        public AssetSwap(bool payBondCoupon,
                         Bond bond,
                         double bondCleanPrice,
                         IborIndex iborIndex,
                         double spread,
                         Schedule floatSchedule      = null,
                         DayCounter floatingDayCount = null,
                         bool parAssetSwap           = true)
            : base(2)
        {
            bond_            = bond;
            bondCleanPrice_  = bondCleanPrice;
            nonParRepayment_ = 100;
            spread_          = spread;
            parSwap_         = parAssetSwap;

            Schedule schedule = floatSchedule;

            if (floatSchedule == null)
            {
                schedule = new Schedule(bond_.settlementDate(),
                                        bond_.maturityDate(),
                                        iborIndex.tenor(),
                                        iborIndex.fixingCalendar(),
                                        iborIndex.businessDayConvention(),
                                        iborIndex.businessDayConvention(),
                                        DateGeneration.Rule.Backward,
                                        false); // endOfMonth
            }
            // the following might become an input parameter
            BusinessDayConvention paymentAdjustment = BusinessDayConvention.Following;

            Date finalDate           = schedule.calendar().adjust(schedule.endDate(), paymentAdjustment);
            Date adjBondMaturityDate = schedule.calendar().adjust(bond_.maturityDate(), paymentAdjustment);

            Utils.QL_REQUIRE(finalDate == adjBondMaturityDate, () =>
                             "adjusted schedule end date (" +
                             finalDate +
                             ") must be equal to adjusted bond maturity date (" +
                             adjBondMaturityDate + ")");

            // bondCleanPrice must be the (forward) clean price
            // at the floating schedule start date
            upfrontDate_ = schedule.startDate();
            double dirtyPrice = bondCleanPrice_ +
                                bond_.accruedAmount(upfrontDate_);

            double notional = bond_.notional(upfrontDate_);

            /* In the market asset swap, the bond is purchased in return for
             * payment of the full price. The notional of the floating leg is
             * then scaled by the full price. */
            if (!parSwap_)
            {
                notional *= dirtyPrice / 100.0;
            }

            if (floatingDayCount == null)
            {
                legs_[1] = new IborLeg(schedule, iborIndex)
                           .withSpreads(spread)
                           .withNotionals(notional)
                           .withPaymentAdjustment(paymentAdjustment);
            }
            else
            {
                legs_[1] = new IborLeg(schedule, iborIndex)
                           .withSpreads(spread)
                           .withPaymentDayCounter(floatingDayCount)
                           .withNotionals(notional)
                           .withPaymentAdjustment(paymentAdjustment);
            }

            foreach (CashFlow c in legs_[1])
            {
                c.registerWith(update);
            }

            List <CashFlow> bondLeg = bond_.cashflows();

            foreach (CashFlow c in bondLeg)
            {
                // whatever might be the choice for the discounting engine
                // bond flows on upfrontDate_ must be discarded
                bool upfrontDateBondFlows = false;
                if (!(c.hasOccurred(upfrontDate_, upfrontDateBondFlows)))
                {
                    legs_[0].Add(c);
                }
            }

            Utils.QL_REQUIRE(!legs_[0].empty(), () => "empty bond leg to start with");

            // special flows
            if (parSwap_)
            {
                // upfront on the floating leg
                double   upfront         = (dirtyPrice - 100.0) / 100.0 * notional;
                CashFlow upfrontCashFlow = new SimpleCashFlow(upfront, upfrontDate_);
                legs_[1].Insert(0, upfrontCashFlow);
                // backpayment on the floating leg
                // (accounts for non-par redemption, if any)
                double   backPayment         = notional;
                CashFlow backPaymentCashFlow = new SimpleCashFlow(backPayment, finalDate);
                legs_[1].Add(backPaymentCashFlow);
            }
            else
            {
                // final notional exchange
                CashFlow finalCashFlow = new SimpleCashFlow(notional, finalDate);
                legs_[1].Add(finalCashFlow);
            }

            Utils.QL_REQUIRE(!legs_[0].empty(), () => "empty bond leg");

            foreach (CashFlow c in legs_[0])
            {
                c.registerWith(update);
            }

            if (payBondCoupon)
            {
                payer_[0] = -1.0;
                payer_[1] = +1.0;
            }
            else
            {
                payer_[0] = +1.0;
                payer_[1] = -1.0;
            }
        }