Esempio n. 1
0
        public SwaptionHelper(Period maturity,
                              Period length,
                              Handle <Quote> volatility,
                              IborIndex index,
                              Period fixedLegTenor,
                              DayCounter fixedLegDayCounter,
                              DayCounter floatingLegDayCounter,
                              Handle <YieldTermStructure> termStructure,
                              CalibrationErrorType errorType = CalibrationErrorType.RelativePriceError,
                              double?strike  = null,
                              double nominal = 1.0)
            : base(volatility, termStructure, errorType)
        {
            exerciseDate_          = null;
            endDate_               = null;
            maturity_              = maturity;
            length_                = length;
            fixedLegTenor_         = fixedLegTenor;
            index_                 = index;
            fixedLegDayCounter_    = fixedLegDayCounter;
            floatingLegDayCounter_ = floatingLegDayCounter;
            strike_                = strike;
            nominal_               = nominal;

            index_.registerWith(update);
        }
Esempio n. 2
0
        public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index, DayCounter paymentDayCounter,
                                BusinessDayConvention paymentConvention, int fixingDays, List<double> gearings, List<double> spreads,
                                List<double> caps, List<double> floors, bool inArrears, double redemption, Date issueDate)
            : base(settlementDays, schedule.calendar(), issueDate) {
            maturityDate_ = schedule.endDate();
            cashflows_ = new IborLeg(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);
        }
Esempio n. 3
0
        public SwaptionHelper( Period maturity,
            Period length,
            Handle<Quote> volatility,
            IborIndex index,
            Period fixedLegTenor,
            DayCounter fixedLegDayCounter,
            DayCounter floatingLegDayCounter,
            Handle<YieldTermStructure> termStructure,
            CalibrationErrorType errorType = CalibrationErrorType.RelativePriceError,
            double? strike = null,
            double nominal = 1.0)
            : base(volatility, termStructure, errorType)
        {
            exerciseDate_ = null;
            endDate_ = null;
            maturity_ = maturity;
            length_ = length;
            fixedLegTenor_ = fixedLegTenor;
            index_ = index;
            fixedLegDayCounter_ = fixedLegDayCounter;
            floatingLegDayCounter_ = floatingLegDayCounter;
            strike_ = strike;
            nominal_ = nominal;

            index_ .registerWith(update);
        }
Esempio n. 4
0
        public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index, DayCounter paymentDayCounter,
                                BusinessDayConvention paymentConvention, int fixingDays, List <double> gearings, List <double> spreads,
                                List <double> caps, List <double> floors, bool inArrears, double redemption, Date issueDate)
            : base(settlementDays, schedule.calendar(), issueDate)
        {
            maturityDate_ = schedule.endDate();
            cashflows_    = new IborLeg(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);
        }
Esempio n. 5
0
        public SwaptionHelper(Date exerciseDate,
                              Period length,
                              Handle <Quote> volatility,
                              IborIndex index,
                              Period fixedLegTenor,
                              DayCounter fixedLegDayCounter,
                              DayCounter floatingLegDayCounter,
                              Handle <YieldTermStructure> termStructure,
                              CalibrationErrorType errorType = CalibrationErrorType.RelativePriceError,
                              double?strike       = null,
                              double nominal      = 1.0,
                              VolatilityType type = VolatilityType.ShiftedLognormal,
                              double shift        = 0.0)
            : base(volatility, termStructure, errorType, type, shift)
        {
            exerciseDate_          = exerciseDate;
            endDate_               = null;
            maturity_              = new Period(0, TimeUnit.Days);
            length_                = length;
            fixedLegTenor_         = fixedLegTenor;
            index_                 = index;
            fixedLegDayCounter_    = fixedLegDayCounter;
            floatingLegDayCounter_ = floatingLegDayCounter;
            strike_                = strike;
            nominal_               = nominal;

            index_.registerWith(update);
        }
Esempio n. 6
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 Exception("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);
        }
Esempio n. 7
0
        //public FloatingRateBond(int settlementDays, double faceAmount, Date startDate, Date maturityDate, Frequency couponFrequency,
        //                        Calendar calendar, IborIndex index, DayCounter accrualDayCounter,
        //                        BusinessDayConvention accrualConvention = Following,
        //                        BusinessDayConvention paymentConvention = Following,
        //                        int fixingDays = Null<Natural>(),
        //                        List<double> gearings = std::vector<Real>(1, 1.0),
        //                        List<double> spreads = std::vector<Spread>(1, 0.0),
        //                        List<double> caps = std::vector<Rate>(),
        //                        List<double> floors = std::vector<Rate>(),
        //                        bool inArrears = false,
        //                        double redemption = 100.0,
        //                        Date issueDate = Date(),
        //                        Date stubDate = Date(),
        //                        DateGeneration.Rule rule = DateGeneration::Backward,
        //                        bool endOfMonth = false)
        public FloatingRateBond(int settlementDays, double faceAmount, Date startDate, Date maturityDate, Frequency couponFrequency,
                                Calendar calendar, IborIndex index, DayCounter accrualDayCounter,
                                BusinessDayConvention accrualConvention, BusinessDayConvention paymentConvention,
                                int fixingDays, List <double> gearings, List <double> spreads, List <double?> caps,
                                List <double?> floors, bool inArrears, double redemption, Date issueDate,
                                Date stubDate, DateGeneration.Rule rule, bool endOfMonth)
            : base(settlementDays, calendar, issueDate)
        {
            maturityDate_ = maturityDate;

            Date firstDate = null, nextToLastDate = null;

            switch (rule)
            {
            case DateGeneration.Rule.Backward:
                firstDate      = null;
                nextToLastDate = stubDate;
                break;

            case DateGeneration.Rule.Forward:
                firstDate      = stubDate;
                nextToLastDate = null;
                break;

            case DateGeneration.Rule.Zero:
            case DateGeneration.Rule.ThirdWednesday:
            case DateGeneration.Rule.Twentieth:
            case DateGeneration.Rule.TwentiethIMM:
                Utils.QL_FAIL("stub date (" + stubDate + ") not allowed with " + rule + " DateGeneration::Rule");
                break;

            default:
                Utils.QL_FAIL("unknown DateGeneration::Rule (" + rule + ")");
                break;
            }

            Schedule schedule = new Schedule(startDate, maturityDate_, new Period(couponFrequency), calendar_,
                                             accrualConvention, accrualConvention, rule, endOfMonth, firstDate, nextToLastDate);

            cashflows_ = new IborLeg(schedule, index)
                         .withPaymentDayCounter(accrualDayCounter)
                         .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);
        }
Esempio n. 8
0
        protected OptionletStripper(CapFloorTermVolSurface termVolSurface, IborIndex iborIndex,
                                    Handle <YieldTermStructure> discount = null,
                                    VolatilityType type = VolatilityType.ShiftedLognormal,
                                    double displacement = 0.0)
        {
            termVolSurface_ = termVolSurface;
            iborIndex_      = iborIndex;
            discount_       = discount ?? new Handle <YieldTermStructure>();
            nStrikes_       = termVolSurface.strikes().Count;
            volatilityType_ = type;
            displacement_   = displacement;


            if (volatilityType_ == VolatilityType.Normal)
            {
                Utils.QL_REQUIRE(displacement_.IsEqual(0.0), () =>
                                 "non-null displacement is not allowed with Normal model");
            }

            termVolSurface.registerWith(update);
            iborIndex_.registerWith(update);
            discount_.registerWith(update);
            Settings.registerWith(update);

            Period indexTenor       = iborIndex_.tenor();
            Period maxCapFloorTenor = termVolSurface.optionTenors().Last();

            // optionlet tenors and capFloor lengths
            optionletTenors_.Add(indexTenor);
            capFloorLengths_.Add(optionletTenors_.Last() + indexTenor);
            Utils.QL_REQUIRE(maxCapFloorTenor >= capFloorLengths_.Last(), () =>
                             "too short (" + maxCapFloorTenor + ") capfloor term vol termVolSurface");
            Period nextCapFloorLength = capFloorLengths_.Last() + indexTenor;

            while (nextCapFloorLength <= maxCapFloorTenor)
            {
                optionletTenors_.Add(capFloorLengths_.Last());
                capFloorLengths_.Add(nextCapFloorLength);
                nextCapFloorLength += indexTenor;
            }
            nOptionletTenors_ = optionletTenors_.Count;

            optionletVolatilities_ = new InitializedList <List <double> >(nOptionletTenors_);
            for (int x = 0; x < nOptionletTenors_; x++)
            {
                optionletVolatilities_[x] = new InitializedList <double>(nStrikes_);
            }
            optionletStrikes_ = new InitializedList <List <double> >(nOptionletTenors_);
            for (int x = 0; x < nOptionletTenors_; x++)
            {
                optionletStrikes_[x] = new List <double>(termVolSurface.strikes());
            }

            optionletDates_          = new InitializedList <Date>(nOptionletTenors_);
            optionletTimes_          = new InitializedList <double>(nOptionletTenors_);
            atmOptionletRate_        = new InitializedList <double>(nOptionletTenors_);
            optionletPaymentDates_   = new InitializedList <Date>(nOptionletTenors_);
            optionletAccrualPeriods_ = new InitializedList <double>(nOptionletTenors_);
        }
Esempio n. 9
0
        public SwapIndex(string familyName, Period tenor, int settlementDays, Currency currency, Calendar calendar, Period fixedLegTenor, BusinessDayConvention fixedLegConvention, DayCounter fixedLegDayCounter, IborIndex iborIndex, Handle<YieldTermStructure> discountingTermStructure)
            : base(familyName, tenor, settlementDays, currency, calendar, fixedLegDayCounter)
        {
            tenor_ = tenor;
            iborIndex_ = iborIndex;
            fixedLegTenor_ = fixedLegTenor;
            fixedLegConvention_ = fixedLegConvention;
            exogenousDiscount_ = true;

            discount_ = discountingTermStructure ?? new Handle<YieldTermStructure>();

            iborIndex_.registerWith(update);
        }
Esempio n. 10
0
        public SwapIndex(string familyName, Period tenor, int settlementDays, Currency currency, Calendar calendar, Period fixedLegTenor, BusinessDayConvention fixedLegConvention, DayCounter fixedLegDayCounter, IborIndex iborIndex, Handle <YieldTermStructure> discountingTermStructure)
            : base(familyName, tenor, settlementDays, currency, calendar, fixedLegDayCounter)
        {
            tenor_              = tenor;
            iborIndex_          = iborIndex;
            fixedLegTenor_      = fixedLegTenor;
            fixedLegConvention_ = fixedLegConvention;
            exogenousDiscount_  = true;

            discount_ = discountingTermStructure ?? new Handle <YieldTermStructure>();

            iborIndex_.registerWith(update);
        }
Esempio n. 11
0
      public AmortizingFloatingRateBond(int settlementDays,
                                        List<double> notionals,
                                        Schedule schedule,
                                        IborIndex index,
                                        DayCounter accrualDayCounter,
                                        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)
      {
         if ( gearings == null ) 
            gearings = new List<double>() {1, 1.0};

         if (spreads == null)
            spreads = new List<double>() { 1, 0.0 };

         if (caps == null)
            caps = new List<double>() ;

         if (floors == null)
            floors = new List<double>();

         maturityDate_ = schedule.endDate();


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

         addRedemptionsToCashflows();

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

         index.registerWith(update);

      }
Esempio n. 12
0
        //public SwapRateHelper(double rate, SwapIndex swapIndex)
        //    : this(rate, swapIndex, new SimpleQuote()) { }
        //public SwapRateHelper(double rate, SwapIndex swapIndex, Quote spread)
        //    : this(rate, swapIndex, spread, new Period(0, TimeUnit.Days)) { }
        public SwapRateHelper(double rate, SwapIndex swapIndex, Handle <Quote> spread, Period fwdStart)
            : base(rate)
        {
            tenor_           = swapIndex.tenor();
            calendar_        = swapIndex.fixingCalendar();
            fixedConvention_ = swapIndex.fixedLegConvention();
            fixedFrequency_  = swapIndex.fixedLegTenor().frequency();
            fixedDayCount_   = swapIndex.dayCounter();
            iborIndex_       = swapIndex.iborIndex();
            spread_          = spread;
            fwdStart_        = fwdStart;

            // add observers
            iborIndex_.registerWith(update);
            spread_.registerWith(update);

            initializeDates();
        }
Esempio n. 13
0
        //public SwapRateHelper(Quote rate, SwapIndex swapIndex) :
        //    this(rate, swapIndex, new SimpleQuote(), new Period(0, TimeUnit.Days)) { }
        //public SwapRateHelper(Quote rate, SwapIndex swapIndex, Quote spread) :
        //    this(rate, swapIndex, spread, new Period(0, TimeUnit.Days)) { }
        public SwapRateHelper(Handle<Quote> rate, SwapIndex swapIndex, Handle<Quote> spread, Period fwdStart)
            : base(rate)
        {
            tenor_ = swapIndex.tenor();
            calendar_ = swapIndex.fixingCalendar();
            fixedConvention_ = swapIndex.fixedLegConvention();
            fixedFrequency_ = swapIndex.fixedLegTenor().frequency();
            fixedDayCount_ = swapIndex.dayCounter();
            iborIndex_ = swapIndex.iborIndex();
            spread_ = spread;
            fwdStart_ = fwdStart;

            // add observers
            iborIndex_.registerWith(update);
            spread_.registerWith(update);

            initializeDates();
        }
Esempio n. 14
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,
            CalibrationErrorType errorType = CalibrationErrorType.RelativePriceError)
            : base(volatility, termStructure, errorType)
        {
            length_ = length;
            index_ = index;
            fixedLegFrequency_ = fixedLegFrequency;
            fixedLegDayCounter_ = fixedLegDayCounter;
            includeFirstSwaplet_ = includeFirstSwaplet;

            index_.registerWith(update);
        }
Esempio n. 15
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,
                         CalibrationErrorType errorType = CalibrationErrorType.RelativePriceError)
            : base(volatility, termStructure, errorType)
        {
            length_              = length;
            index_               = index;
            fixedLegFrequency_   = fixedLegFrequency;
            fixedLegDayCounter_  = fixedLegDayCounter;
            includeFirstSwaplet_ = includeFirstSwaplet;

            index_.registerWith(update);
        }
Esempio n. 16
0
        public BMASwapRateHelper(Handle<Quote> liborFraction, Period tenor,  int settlementDays, Calendar calendar,
                          // bma leg
                          Period bmaPeriod, BusinessDayConvention bmaConvention, DayCounter bmaDayCount, BMAIndex bmaIndex,
                          // ibor leg
                          IborIndex iborIndex)
            : base(liborFraction)
        {
            tenor_ = tenor;
            settlementDays_ = settlementDays;
            calendar_ = calendar;
            bmaPeriod_ = bmaPeriod;
            bmaConvention_ = bmaConvention;
            bmaDayCount_ = bmaDayCount;
            bmaIndex_ = bmaIndex;
            iborIndex_ = iborIndex;

            iborIndex_.registerWith(update);
            bmaIndex_.registerWith(update);

            initializeDates();
        }
Esempio n. 17
0
        public BMASwapRateHelper(Handle <Quote> liborFraction, Period tenor, int settlementDays, Calendar calendar,
                                 // bma leg
                                 Period bmaPeriod, BusinessDayConvention bmaConvention, DayCounter bmaDayCount, BMAIndex bmaIndex,
                                 // ibor leg
                                 IborIndex iborIndex)
            : base(liborFraction)
        {
            tenor_          = tenor;
            settlementDays_ = settlementDays;
            calendar_       = calendar;
            bmaPeriod_      = bmaPeriod;
            bmaConvention_  = bmaConvention;
            bmaDayCount_    = bmaDayCount;
            bmaIndex_       = bmaIndex;
            iborIndex_      = iborIndex;

            iborIndex_.registerWith(update);
            bmaIndex_.registerWith(update);

            initializeDates();
        }
Esempio n. 18
0
        //public SwapRateHelper(double rate, Period tenor, Calendar calendar,
        //               Frequency fixedFrequency, BusinessDayConvention fixedConvention, DayCounter fixedDayCount,
        //               IborIndex iborIndex) :
        //    this(rate, tenor, calendar, fixedFrequency, fixedConvention, fixedDayCount, iborIndex,
        //         new SimpleQuote(), new Period(0, TimeUnit.Days)) { }
        //public SwapRateHelper(double rate, Period tenor, Calendar calendar,
        //               Frequency fixedFrequency, BusinessDayConvention fixedConvention, DayCounter fixedDayCount,
        //               IborIndex iborIndex, Quote spread) :
        //    this(rate, tenor, calendar, fixedFrequency, fixedConvention, fixedDayCount, iborIndex,
        //         spread, new Period(0, TimeUnit.Days)) { }
        public SwapRateHelper(double rate, Period tenor, Calendar calendar,
                              // fixed leg
                              Frequency fixedFrequency, BusinessDayConvention fixedConvention, DayCounter fixedDayCount,
                              // floating leg
                              IborIndex iborIndex, Handle <Quote> spread, Period fwdStart)
            : base(rate)
        {
            tenor_           = tenor;
            calendar_        = calendar;
            fixedConvention_ = fixedConvention;
            fixedFrequency_  = fixedFrequency;
            fixedDayCount_   = fixedDayCount;
            iborIndex_       = iborIndex;
            spread_          = spread;
            fwdStart_        = fwdStart;

            // add observers
            iborIndex_.registerWith(update);
            spread_.registerWith(update);

            initializeDates();
        }
Esempio n. 19
0
        public FloatingCatBond(int settlementDays,
                               double faceAmount,
                               Schedule schedule,
                               IborIndex iborIndex,
                               DayCounter paymentDayCounter,
                               NotionalRisk notionalRisk,
                               BusinessDayConvention paymentConvention = QLNet.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, notionalRisk)
        {
            maturityDate_ = schedule.endDate();

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

            addRedemptionsToCashflows(new InitializedList <double>(1, redemption));

            Utils.QL_REQUIRE(!cashflows().empty(), () => "bond with no cashflows!");
            Utils.QL_REQUIRE(redemptions_.Count == 1, () => "multiple redemptions created");

            iborIndex.registerWith(update);
        }
Esempio n. 20
0
        //public SwapRateHelper(double rate, Period tenor, Calendar calendar,
        //               Frequency fixedFrequency, BusinessDayConvention fixedConvention, DayCounter fixedDayCount,
        //               IborIndex iborIndex) :
        //    this(rate, tenor, calendar, fixedFrequency, fixedConvention, fixedDayCount, iborIndex,
        //         new SimpleQuote(), new Period(0, TimeUnit.Days)) { }
        //public SwapRateHelper(double rate, Period tenor, Calendar calendar,
        //               Frequency fixedFrequency, BusinessDayConvention fixedConvention, DayCounter fixedDayCount,
        //               IborIndex iborIndex, Quote spread) :
        //    this(rate, tenor, calendar, fixedFrequency, fixedConvention, fixedDayCount, iborIndex,
        //         spread, new Period(0, TimeUnit.Days)) { }
        public SwapRateHelper(double rate, Period tenor, Calendar calendar,
            // fixed leg
                       Frequency fixedFrequency, BusinessDayConvention fixedConvention, DayCounter fixedDayCount,
            // floating leg
                       IborIndex iborIndex, Handle<Quote> spread, Period fwdStart)
            : base(rate)
        {
            tenor_ = tenor;
            calendar_ = calendar;
            fixedConvention_ = fixedConvention;
            fixedFrequency_ = fixedFrequency;
            fixedDayCount_ = fixedDayCount;
            iborIndex_ = iborIndex;
            spread_ = spread;
            fwdStart_ = fwdStart;

            // add observers
            iborIndex_.registerWith(update);
            spread_.registerWith(update);

            initializeDates();
        }
Esempio n. 21
0
        //public FloatingRateBond(int settlementDays, double faceAmount, Date startDate, Date maturityDate, Frequency couponFrequency,
        //                        Calendar calendar, IborIndex index, DayCounter accrualDayCounter,
        //                        BusinessDayConvention accrualConvention = Following,
        //                        BusinessDayConvention paymentConvention = Following,
        //                        int fixingDays = Null<Natural>(),
        //                        List<double> gearings = std::vector<Real>(1, 1.0),
        //                        List<double> spreads = std::vector<Spread>(1, 0.0),
        //                        List<double> caps = std::vector<Rate>(),
        //                        List<double> floors = std::vector<Rate>(),
        //                        bool inArrears = false,
        //                        double redemption = 100.0,
        //                        Date issueDate = Date(),
        //                        Date stubDate = Date(),
        //                        DateGeneration.Rule rule = DateGeneration::Backward,
        //                        bool endOfMonth = false)
        public FloatingRateBond(int settlementDays, double faceAmount, Date startDate, Date maturityDate, Frequency couponFrequency,
                                Calendar calendar, IborIndex index, DayCounter accrualDayCounter,
                                BusinessDayConvention accrualConvention, BusinessDayConvention paymentConvention,
                                int fixingDays, List<double> gearings, List<double> spreads, List<double> caps,
                                List<double> floors, bool inArrears, double redemption, Date issueDate,
                                Date stubDate, DateGeneration.Rule rule, bool endOfMonth)
            : base(settlementDays, calendar, issueDate) {

            maturityDate_ = maturityDate;

            Date firstDate, nextToLastDate;
            switch (rule) {
                case DateGeneration.Rule.Backward:
                    firstDate = null;
                    nextToLastDate = stubDate;
                    break;
                case DateGeneration.Rule.Forward:
                    firstDate = stubDate;
                    nextToLastDate = null;
                    break;
              case DateGeneration.Rule.Zero:
              case DateGeneration.Rule.ThirdWednesday:
              case DateGeneration.Rule.Twentieth:
              case DateGeneration.Rule.TwentiethIMM:
                    throw new ApplicationException("stub date (" + stubDate + ") not allowed with " + rule + " DateGeneration::Rule");
                default:
                    throw new ApplicationException("unknown DateGeneration::Rule (" + rule + ")");
            }

            Schedule schedule = new Schedule(startDate, maturityDate_, new Period(couponFrequency), calendar_,
                                             accrualConvention, accrualConvention, rule, endOfMonth, firstDate, nextToLastDate);

            cashflows_ = new IborLeg(schedule, index)
                            .withPaymentDayCounter(accrualDayCounter)
                            .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);
        }
        public AmortizingFloatingRateBond(int settlementDays,
                                          List <double> notionals,
                                          Schedule schedule,
                                          IborIndex index,
                                          DayCounter accrualDayCounter,
                                          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)
        {
            if (gearings == null)
            {
                gearings = new List <double>()
                {
                    1, 1.0
                }
            }
            ;

            if (spreads == null)
            {
                spreads = new List <double>()
                {
                    1, 0.0
                }
            }
            ;

            if (caps == null)
            {
                caps = new List <double>();
            }

            if (floors == null)
            {
                floors = new List <double>();
            }

            maturityDate_ = schedule.endDate();


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

            addRedemptionsToCashflows();

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

            index.registerWith(update);
        }
    }
}
Esempio n. 23
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);
        }