コード例 #1
0
        protected SwaptionVolatilityCube(Handle <SwaptionVolatilityStructure> atmVol,
                                         List <Period> optionTenors,
                                         List <Period> swapTenors,
                                         List <double> strikeSpreads,
                                         List <List <Handle <Quote> > > volSpreads,
                                         SwapIndex swapIndexBase,
                                         SwapIndex shortSwapIndexBase,
                                         bool vegaWeightedSmileFit)
            : base(optionTenors, swapTenors, 0, atmVol.link.calendar(), atmVol.link.businessDayConvention(),
                   atmVol.link.dayCounter())
        {
            atmVol_               = atmVol;
            nStrikes_             = strikeSpreads.Count;
            strikeSpreads_        = strikeSpreads;
            localStrikes_         = new InitializedList <double>(nStrikes_);
            localSmile_           = new List <double>(nStrikes_);
            volSpreads_           = volSpreads;
            swapIndexBase_        = swapIndexBase;
            shortSwapIndexBase_   = shortSwapIndexBase;
            vegaWeightedSmileFit_ = vegaWeightedSmileFit;

            Utils.QL_REQUIRE(!atmVol_.empty(), () => "atm vol handle not linked to anything");
            for (int i = 1; i < nStrikes_; ++i)
            {
                Utils.QL_REQUIRE(strikeSpreads_[i - 1] < strikeSpreads_[i], () =>
                                 "non increasing strike spreads: " + i + " is " + strikeSpreads_[i - 1] + ", " +
                                 (i + 1) + " is " + strikeSpreads_[i]);
            }

            Utils.QL_REQUIRE(!volSpreads_.empty(), () => "empty vol spreads matrix");

            Utils.QL_REQUIRE(nOptionTenors_ * nSwapTenors_ == volSpreads_.Count, () =>
                             "mismatch between number of option tenors * swap tenors (" +
                             nOptionTenors_ * nSwapTenors_ + ") and number of rows (" +
                             volSpreads_.Count + ")");

            for (int i = 0; i < volSpreads_.Count; i++)
            {
                Utils.QL_REQUIRE(nStrikes_ == volSpreads_[i].Count, () =>
                                 "mismatch between number of strikes (" + nStrikes_ +
                                 ") and number of columns (" + volSpreads_[i].Count +
                                 ") in the " + (i + 1) + " row");
            }

            atmVol_.registerWith(update);
            atmVol_.link.enableExtrapolation();

            swapIndexBase_.registerWith(update);
            shortSwapIndexBase_.registerWith(update);

            Utils.QL_REQUIRE(shortSwapIndexBase_.tenor() < swapIndexBase_.tenor(), () =>
                             "short index tenor (" + shortSwapIndexBase_.tenor() +
                             ") is not less than index tenor (" +
                             swapIndexBase_.tenor() + ")");

            registerWithVolatilitySpread();
            Settings.registerWith(update);
            evaluationDate_ = Settings.evaluationDate();
        }
コード例 #2
0
ファイル: SwapSpreadIndex.cs プロジェクト: igitur/qlnet
        public SwapSpreadIndex(String familyName,
                               SwapIndex swapIndex1,
                               SwapIndex swapIndex2,
                               double gearing1 = 1.0,
                               double gearing2 = -1.0)
            : base(familyName, swapIndex1.tenor(), // does not make sense, but we have to provide one
                   swapIndex1.fixingDays(), swapIndex1.currency(), swapIndex1.fixingCalendar(), swapIndex1.dayCounter())
        {
            swapIndex1_ = swapIndex1;
            swapIndex2_ = swapIndex2;
            gearing1_   = gearing1;
            gearing2_   = gearing2;

            swapIndex1_.registerWith(update);
            swapIndex2_.registerWith(update);

            name_ = swapIndex1_.name() + "(" + gearing1 + ") + "
                    + swapIndex2_.name() + "(" + gearing1 + ")";

            Utils.QL_REQUIRE(swapIndex1_.fixingDays() == swapIndex2_.fixingDays(), () =>
                             "index1 fixing days ("
                             + swapIndex1_.fixingDays() + ")"
                             + "must be equal to index2 fixing days ("
                             + swapIndex2_.fixingDays() + ")");

            Utils.QL_REQUIRE(swapIndex1_.fixingCalendar() == swapIndex2_.fixingCalendar(), () =>
                             "index1 fixingCalendar ("
                             + swapIndex1_.fixingCalendar() + ")"
                             + "must be equal to index2 fixingCalendar ("
                             + swapIndex2_.fixingCalendar() + ")");

            Utils.QL_REQUIRE(swapIndex1_.currency() == swapIndex2_.currency(), () =>
                             "index1 currency (" + swapIndex1_.currency() + ")"
                             + "must be equal to index2 currency ("
                             + swapIndex2_.currency() + ")");

            Utils.QL_REQUIRE(swapIndex1_.dayCounter() == swapIndex2_.dayCounter(), () =>
                             "index1 dayCounter ("
                             + swapIndex1_.dayCounter() + ")"
                             + "must be equal to index2 dayCounter ("
                             + swapIndex2_.dayCounter() + ")");

            Utils.QL_REQUIRE(swapIndex1_.fixedLegTenor() == swapIndex2_.fixedLegTenor(), () =>
                             "index1 fixedLegTenor ("
                             + swapIndex1_.fixedLegTenor() + ")"
                             + "must be equal to index2 fixedLegTenor ("
                             + swapIndex2_.fixedLegTenor());

            Utils.QL_REQUIRE(swapIndex1_.fixedLegConvention() == swapIndex2_.fixedLegConvention(), () =>
                             "index1 fixedLegConvention ("
                             + swapIndex1_.fixedLegConvention() + ")"
                             + "must be equal to index2 fixedLegConvention ("
                             + swapIndex2_.fixedLegConvention());
        }
コード例 #3
0
ファイル: CmsRateBond.cs プロジェクト: akasolace/qlnet
         public CmsRateBond(int settlementDays,
                            double faceAmount,
                            Schedule schedule,
                            SwapIndex index,
                            DayCounter paymentDayCounter,
                            BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
                            int fixingDays = 0,
                            List<double> gearings = null,
                            List<double> spreads = null,
                            List<double> caps = null,
                            List<double> floors = null,
                            bool inArrears = false,
                            double redemption = 100.0,
                            Date issueDate = null)
             : base(settlementDays, schedule.calendar(), issueDate) 
         {
             // Optional value check
             if ( gearings == null ) gearings = new List<double>(){1};
             if ( spreads == null ) spreads = new List<double>(){0};
             if (caps == null) caps = new List<double>();
             if (floors == null) floors = new List<double>();

             maturityDate_ = schedule.endDate();
             cashflows_ = new CmsLeg(schedule, index)
                            .withPaymentDayCounter(paymentDayCounter)
                            .withFixingDays(fixingDays)
                            .withGearings(gearings)
                            .withSpreads(spreads)
                            .withCaps(caps)
                            .withFloors(floors)
                            .inArrears(inArrears)
                            .withNotionals(faceAmount)
                            .withPaymentAdjustment(paymentConvention); 
              
             addRedemptionsToCashflows(new List<double>() { redemption });

             if (cashflows().Count == 0)
                throw new ApplicationException("bond with no cashflows!");
             if (redemptions_.Count != 1)
                throw new ApplicationException("multiple redemptions created");

             index.registerWith(update);

        
        }
コード例 #4
0
      public AmortizingCmsRateBond( int settlementDays,
                               List<double> notionals,
                               Schedule schedule,
                               SwapIndex index,
                               DayCounter paymentDayCounter,
                               BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
                               int fixingDays = 0,
                               List<double> gearings = null,
                               List<double> spreads = null,
                               List<double> caps = null,
                               List<double> floors = null,
                               bool inArrears = false,
                               Date issueDate = null)
         :base(settlementDays, schedule.calendar(), issueDate)
      {
         // Optional value check
         if ( gearings == null ) gearings = new List<double>(){1.0};
         if ( spreads == null ) spreads = new List<double>(){0};
         if (caps == null) caps = new List<double>();
         if (floors == null) floors = new List<double>();

         maturityDate_ = schedule.endDate();

         cashflows_ = new CmsLeg(schedule, index)
             .withPaymentDayCounter(paymentDayCounter)
             .withFixingDays(fixingDays)
             .withGearings(gearings)
             .withSpreads(spreads)
             .withCaps(caps)
             .withFloors(floors)
             .inArrears(inArrears)
             .withNotionals(notionals)
             .withPaymentAdjustment(paymentConvention);

         addRedemptionsToCashflows();

         Utils.QL_REQUIRE( !cashflows().empty(), () => "bond with no cashflows!" );

         index.registerWith(update);
        
      }
コード例 #5
0
        public CmsRateBond(int settlementDays,
                           double faceAmount,
                           Schedule schedule,
                           SwapIndex index,
                           DayCounter paymentDayCounter,
                           BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
                           int fixingDays         = 0,
                           List <double> gearings = null,
                           List <double> spreads  = null,
                           List <double?> caps    = null,
                           List <double?> floors  = null,
                           bool inArrears         = false,
                           double redemption      = 100.0,
                           Date issueDate         = null)
            : base(settlementDays, schedule.calendar(), issueDate)
        {
            // Optional value check
            if (gearings == null)
            {
                gearings = new List <double>()
                {
                    1
                }
            }
            ;
            if (spreads == null)
            {
                spreads = new List <double>()
                {
                    0
                }
            }
            ;
            if (caps == null)
            {
                caps = new List <double?>();
            }
            if (floors == null)
            {
                floors = new List <double?>();
            }

            maturityDate_ = schedule.endDate();
            cashflows_    = new CmsLeg(schedule, index)
                            .withPaymentDayCounter(paymentDayCounter)
                            .withFixingDays(fixingDays)
                            .withGearings(gearings)
                            .withSpreads(spreads)
                            .withCaps(caps)
                            .withFloors(floors)
                            .inArrears(inArrears)
                            .withNotionals(faceAmount)
                            .withPaymentAdjustment(paymentConvention);

            addRedemptionsToCashflows(new List <double>()
            {
                redemption
            });

            Utils.QL_REQUIRE(cashflows().Count != 0, () => "bond with no cashflows!");
            Utils.QL_REQUIRE(redemptions_.Count == 1, () => "multiple redemptions created");
            index.registerWith(update);
        }
    }
}