public DividendSchedule(DividendSchedule other) : this(NQuantLibcPINVOKE.new_DividendSchedule__SWIG_1(DividendSchedule.getCPtr(other)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 2
0
 public option(ConvertibleBond bond,
               Exercise exercise,
               double conversionRatio,
               DividendSchedule dividends,
               CallabilitySchedule callability,
               Handle <Quote> creditSpread,
               List <CashFlow> cashflows,
               DayCounter dayCounter,
               Schedule schedule,
               Date issueDate,
               int settlementDays,
               double redemption)
     : base(new PlainVanillaPayoff(Option.Type.Call, (bond.notionals()[0]) / 100.0 * redemption / conversionRatio),
            exercise)
 {
     bond_            = bond;
     conversionRatio_ = conversionRatio;
     callability_     = callability;
     dividends_       = dividends;
     creditSpread_    = creditSpread;
     cashflows_       = cashflows;
     dayCounter_      = dayCounter;
     issueDate_       = issueDate;
     schedule_        = schedule;
     settlementDays_  = settlementDays;
     redemption_      = redemption;
 }
Esempio n. 3
0
        public ConvertibleFloatingRateBond(Exercise exercise,
                                           double conversionRatio,
                                           DividendSchedule dividends,
                                           CallabilitySchedule callability,
                                           Handle <Quote> creditSpread,
                                           Date issueDate,
                                           int settlementDays,
                                           IborIndex index,
                                           int fixingDays,
                                           List <double> spreads,
                                           DayCounter dayCounter,
                                           Schedule schedule,
                                           double redemption = 100)
            : base(exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays, schedule, redemption)

        {
            // !!! notional forcibly set to 100
            cashflows_ = new IborLeg(schedule, index)
                         .withPaymentDayCounter(dayCounter)
                         .withFixingDays(fixingDays)
                         .withSpreads(spreads)
                         .withNotionals(100.0)
                         .withPaymentAdjustment(schedule.businessDayConvention());

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

            Utils.QL_REQUIRE(redemptions_.Count == 1, "multiple redemptions created");

            option_ = new option(this, exercise, conversionRatio, dividends, callability, creditSpread, cashflows_, dayCounter, schedule,
                                 issueDate, settlementDays, redemption);
        }
Esempio n. 4
0
 public ConvertibleFixedCouponBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, QuoteHandle creditSpread, Date issueDate, int settlementDays, DoubleVector coupons, DayCounter dayCounter, Schedule schedule) : this(NQuantLibcPINVOKE.new_ConvertibleFixedCouponBond__SWIG_1(Exercise.getCPtr(exercise), conversionRatio, DividendSchedule.getCPtr(dividends), CallabilitySchedule.getCPtr(callability), QuoteHandle.getCPtr(creditSpread), Date.getCPtr(issueDate), settlementDays, DoubleVector.getCPtr(coupons), DayCounter.getCPtr(dayCounter), Schedule.getCPtr(schedule)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 5
0
        protected ConvertibleBond(Exercise exercise,
                                  double conversionRatio,
                                  DividendSchedule dividends,
                                  CallabilitySchedule callability,
                                  Handle <Quote> creditSpread,
                                  Date issueDate,
                                  int settlementDays,
                                  Schedule schedule,
                                  double redemption)
            : base(settlementDays, schedule.calendar(), issueDate)
        {
            conversionRatio_ = conversionRatio;
            callability_     = callability;
            dividends_       = dividends;
            creditSpread_    = creditSpread;

            maturityDate_ = schedule.endDate();

            if (!callability.empty())
            {
                Utils.QL_REQUIRE(callability.Last().date() <= maturityDate_, () =>
                                 "last callability date ("
                                 + callability.Last().date()
                                 + ") later than maturity ("
                                 + maturityDate_.ToShortDateString() + ")");
            }

            creditSpread.registerWith(update);
        }
Esempio n. 6
0
        public ConvertibleFixedCouponBond(Exercise exercise,
                                          double conversionRatio,
                                          DividendSchedule dividends,
                                          CallabilitySchedule callability,
                                          Handle <Quote> creditSpread,
                                          Date issueDate,
                                          int settlementDays,
                                          List <double> coupons,
                                          DayCounter dayCounter,
                                          Schedule schedule,
                                          double redemption = 100)
            : base(
                exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays, schedule,
                redemption)
        {
            // !!! notional forcibly set to 100
            cashflows_ = new FixedRateLeg(schedule)
                         .withCouponRates(coupons, dayCounter)
                         .withNotionals(100.0)
                         .withPaymentAdjustment(schedule.businessDayConvention());

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

            Utils.QL_REQUIRE(redemptions_.Count == 1, () => "multiple redemptions created");

            option_ = new option(this, exercise, conversionRatio, dividends, callability, creditSpread, cashflows_,
                                 dayCounter, schedule,
                                 issueDate, settlementDays, redemption);
        }
Esempio n. 7
0
        public FdmDividendHandler(DividendSchedule schedule,
                                  FdmMesher mesher,
                                  Date referenceDate,
                                  DayCounter dayCounter,
                                  int equityDirection)
        {
            x_               = new Vector(mesher.layout().dim()[equityDirection]);
            mesher_          = mesher;
            equityDirection_ = equityDirection;

            dividends_     = new List <double>();
            dividendDates_ = new List <Date>();
            dividendTimes_ = new List <double>();

            foreach (Dividend iter in schedule)
            {
                dividends_.Add(iter.amount());
                dividendDates_.Add(iter.date());
                dividendTimes_.Add(
                    dayCounter.yearFraction(referenceDate, iter.date()));
            }

            Vector tmp     = mesher_.locations(equityDirection);
            int    spacing = mesher_.layout().spacing()[equityDirection];

            for (int i = 0; i < x_.size(); ++i)
            {
                x_[i] = Math.Exp(tmp[i * spacing]);
            }
        }
 public DividendScheduleEnumerator(DividendSchedule collection)
 {
     collectionRef = collection;
     currentIndex  = -1;
     currentObject = null;
     currentSize   = collectionRef.Count;
 }
Esempio n. 9
0
        protected ConvertibleBond( Exercise exercise,
                                 double conversionRatio,
                                 DividendSchedule dividends,
                                 CallabilitySchedule callability,
                                 Handle<Quote> creditSpread,
                                 Date issueDate,
                                 int settlementDays,
                                 Schedule schedule,
                                 double redemption)
            : base(settlementDays, schedule.calendar(), issueDate)
        {
            conversionRatio_ = conversionRatio;
             callability_ = callability;
             dividends_ = dividends;
             creditSpread_ = creditSpread;

             maturityDate_ = schedule.endDate();

             if (!callability.empty())
             {
            Utils.QL_REQUIRE( callability.Last().date() <= maturityDate_, () =>
                              "last callability date ("
                              + callability.Last().date()
                              + ") later than maturity ("
                              + maturityDate_.ToShortDateString() + ")");
            }

             creditSpread.registerWith(update);
        }
 public void SetRange(int index, DividendSchedule values)
 {
     NQuantLibcPINVOKE.DividendSchedule_SetRange(swigCPtr, index, DividendSchedule.getCPtr(values));
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
        public DividendSchedule GetRange(int index, int count)
        {
            global::System.IntPtr cPtr = NQuantLibcPINVOKE.DividendSchedule_GetRange(swigCPtr, index, count);
            DividendSchedule      ret  = (cPtr == global::System.IntPtr.Zero) ? null : new DividendSchedule(cPtr, true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
        public static DividendSchedule Repeat(Dividend value, int count)
        {
            global::System.IntPtr cPtr = NQuantLibcPINVOKE.DividendSchedule_Repeat(Dividend.getCPtr(value), count);
            DividendSchedule      ret  = (cPtr == global::System.IntPtr.Zero) ? null : new DividendSchedule(cPtr, true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Esempio n. 13
0
        //! helper function building a sequence of fixed dividends
        public static DividendSchedule DividendVector(List <Date> dividendDates, List <double> dividends)
        {
            QL_REQUIRE(dividendDates.Count == dividends.Count, () => "size mismatch between dividend dates and amounts");

            DividendSchedule items = new DividendSchedule();

            for (int i = 0; i < dividendDates.Count; i++)
            {
                items.Add(new FixedDividend(dividends[i], dividendDates[i]));
            }
            return(items);
        }
Esempio n. 14
0
            public override void validate()
            {
                base.validate();
                if (cashFlow == null)
                {
                    cashFlow = new DividendSchedule();
                }

                Date exerciseDate = exercise.lastDate();

                for (int i = 0; i < cashFlow.Count; i++)
                {
                    Utils.QL_REQUIRE(cashFlow[i].date() <= exerciseDate, () =>
                                     " dividend date (" + cashFlow[i].date() + ") is later than the exercise date (" + exerciseDate +
                                     ")");
                }
            }
Esempio n. 15
0
        public ConvertibleZeroCouponBond(Exercise exercise,
                                         double conversionRatio,
                                         DividendSchedule dividends,
                                         CallabilitySchedule callability,
                                         Handle <Quote> creditSpread,
                                         Date issueDate,
                                         int settlementDays,
                                         DayCounter dayCounter,
                                         Schedule schedule,
                                         double redemption = 100)
            : base(exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays, schedule, redemption)
        {
            cashflows_ = new List <CashFlow>();

            // !!! notional forcibly set to 100
            setSingleRedemption(100.0, redemption, maturityDate_);

            option_ = new option(this, exercise, conversionRatio, dividends, callability, creditSpread, cashflows_, dayCounter, schedule,
                                 issueDate, settlementDays, redemption);
        }
Esempio n. 16
0
        public static FdmStepConditionComposite vanillaComposite(DividendSchedule cashFlow,
                                                                 Exercise exercise,
                                                                 FdmMesher mesher,
                                                                 FdmInnerValueCalculator calculator,
                                                                 Date refDate,
                                                                 DayCounter dayCounter)
        {
            List <List <double> >           stoppingTimes  = new List <List <double> >();
            List <IStepCondition <Vector> > stepConditions = new List <IStepCondition <Vector> >();

            if (!cashFlow.empty())
            {
                FdmDividendHandler dividendCondition =
                    new FdmDividendHandler(cashFlow, mesher,
                                           refDate, dayCounter, 0);

                stepConditions.Add(dividendCondition);
                stoppingTimes.Add(dividendCondition.dividendTimes());
            }

            Utils.QL_REQUIRE(exercise.type() == Exercise.Type.American ||
                             exercise.type() == Exercise.Type.European ||
                             exercise.type() == Exercise.Type.Bermudan,
                             () => "exercise type is not supported");
            if (exercise.type() == Exercise.Type.American)
            {
                stepConditions.Add(new FdmAmericanStepCondition(mesher, calculator));
            }
            else if (exercise.type() == Exercise.Type.Bermudan)
            {
                FdmBermudanStepCondition bermudanCondition =
                    new FdmBermudanStepCondition(exercise.dates(),
                                                 refDate, dayCounter,
                                                 mesher, calculator);
                stepConditions.Add(bermudanCondition);
                stoppingTimes.Add(bermudanCondition.exerciseTimes());
            }

            return(new FdmStepConditionComposite(stoppingTimes, stepConditions));
        }
Esempio n. 17
0
 public ConvertibleFixedCouponBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, QuoteHandle creditSpread, Date issueDate, int settlementDays, DoubleVector coupons, DayCounter dayCounter, Schedule schedule, double redemption) : this(NQuantLibcPINVOKE.new_ConvertibleFixedCouponBond__SWIG_0(Exercise.getCPtr(exercise), conversionRatio, DividendSchedule.getCPtr(dividends), CallabilitySchedule.getCPtr(callability), QuoteHandle.getCPtr(creditSpread), Date.getCPtr(issueDate), settlementDays, DoubleVector.getCPtr(coupons), DayCounter.getCPtr(dayCounter), Schedule.getCPtr(schedule), redemption), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 18
0
        public override void calculate()
        {
            // 0. Cash dividend model
            Date   exerciseDate   = arguments_.exercise.lastDate();
            double maturity       = process_.time(exerciseDate);
            Date   settlementDate = process_.riskFreeRate().currentLink().referenceDate();

            double           spotAdjustment   = 0.0;
            DividendSchedule dividendSchedule = new DividendSchedule();

            switch (cashDividendModel_)
            {
            case CashDividendModel.Spot:
                dividendSchedule = arguments_.cashFlow;
                break;

            case CashDividendModel.Escrowed:
                foreach (Dividend divIter in dividendSchedule)
                {
                    Date divDate = divIter.date();

                    if (divDate <= exerciseDate && divDate >= settlementDate)
                    {
                        double divAmount = divIter.amount();
                        double discount  =
                            process_.riskFreeRate().currentLink().discount(divDate) /
                            process_.dividendYield().currentLink().discount(divDate);

                        spotAdjustment -= divAmount * discount;
                    }
                }

                Utils.QL_REQUIRE(process_.x0() + spotAdjustment > 0.0,
                                 () => "spot minus dividends becomes negative");
                break;

            default:
                Utils.QL_FAIL("unknwon cash dividend model");
                break;
            }

            // 1. Mesher
            StrikedTypePayoff payoff = arguments_.payoff as StrikedTypePayoff;

            Fdm1dMesher equityMesher =
                new FdmBlackScholesMesher(
                    xGrid_, process_, maturity, payoff.strike(),
                    null, null, 0.0001, 1.5,
                    new Pair <double?, double?>(payoff.strike(), 0.1),
                    dividendSchedule, quantoHelper_,
                    spotAdjustment);

            FdmMesher mesher =
                new FdmMesherComposite(equityMesher);

            // 2. Calculator
            FdmInnerValueCalculator calculator = new FdmLogInnerValue(payoff, mesher, 0);

            // 3. Step conditions
            FdmStepConditionComposite conditions = FdmStepConditionComposite.vanillaComposite(
                arguments_.cashFlow, arguments_.exercise,
                mesher, calculator,
                process_.riskFreeRate().currentLink().referenceDate(),
                process_.riskFreeRate().currentLink().dayCounter());

            // 4. Boundary conditions
            FdmBoundaryConditionSet boundaries = new FdmBoundaryConditionSet();

            // 5. Solver
            FdmSolverDesc solverDesc = new FdmSolverDesc();

            solverDesc.mesher       = mesher;
            solverDesc.bcSet        = boundaries;
            solverDesc.condition    = conditions;
            solverDesc.calculator   = calculator;
            solverDesc.maturity     = maturity;
            solverDesc.dampingSteps = dampingSteps_;
            solverDesc.timeSteps    = tGrid_;

            FdmBlackScholesSolver solver =
                new FdmBlackScholesSolver(
                    new Handle <GeneralizedBlackScholesProcess>(process_),
                    payoff.strike(), solverDesc, schemeDesc_,
                    localVol_, illegalLocalVolOverwrite_);

            double spot = process_.x0();

            results_.value = solver.valueAt(spot);
            results_.delta = solver.deltaAt(spot);
            results_.gamma = solver.gammaAt(spot);
            results_.theta = solver.thetaAt(spot);
        }
Esempio n. 19
0
        public FdmBlackScholesMesher(int size,
                                     GeneralizedBlackScholesProcess process,
                                     double maturity, double strike,
                                     double?xMinConstraint = null,
                                     double?xMaxConstraint = null,
                                     double eps            = 0.0001,
                                     double scaleFactor    = 1.5,
                                     Pair <double?, double?> cPoint
                                     = null,
                                     DividendSchedule dividendSchedule = null,
                                     FdmQuantoHelper fdmQuantoHelper   = null,
                                     double spotAdjustment             = 0.0)
            : base(size)
        {
            double S = process.x0();

            Utils.QL_REQUIRE(S > 0.0, () => "negative or null underlying given");

            dividendSchedule = dividendSchedule == null ? new DividendSchedule() : dividendSchedule;
            List <pair_double> intermediateSteps = new List <pair_double>();

            for (int i = 0; i < dividendSchedule.Count &&
                 process.time(dividendSchedule[i].date()) <= maturity; ++i)
            {
                intermediateSteps.Add(
                    new pair_double(
                        process.time(dividendSchedule[i].date()),
                        dividendSchedule[i].amount()
                        ));
            }

            int intermediateTimeSteps = (int)Math.Max(2, 24.0 * maturity);

            for (int i = 0; i < intermediateTimeSteps; ++i)
            {
                intermediateSteps.Add(
                    new pair_double((i + 1) * (maturity / intermediateTimeSteps), 0.0));
            }

            intermediateSteps.Sort();

            Handle <YieldTermStructure> rTS = process.riskFreeRate();
            Handle <YieldTermStructure> qTS = fdmQuantoHelper != null
                                          ? new Handle <YieldTermStructure>(
                new QuantoTermStructure(process.dividendYield(),
                                        process.riskFreeRate(),
                                        new Handle <YieldTermStructure>(fdmQuantoHelper.foreignTermStructure()),
                                        process.blackVolatility(),
                                        strike,
                                        new Handle <BlackVolTermStructure>(fdmQuantoHelper.fxVolatilityTermStructure()),
                                        fdmQuantoHelper.exchRateATMlevel(),
                                        fdmQuantoHelper.equityFxCorrelation()))
                                          : process.dividendYield();

            double lastDivTime = 0.0;
            double fwd = S + spotAdjustment;
            double mi = fwd, ma = fwd;

            for (int i = 0; i < intermediateSteps.Count; ++i)
            {
                double divTime   = intermediateSteps[i].first;
                double divAmount = intermediateSteps[i].second;

                fwd = fwd / rTS.currentLink().discount(divTime) * rTS.currentLink().discount(lastDivTime)
                      * qTS.currentLink().discount(divTime) / qTS.currentLink().discount(lastDivTime);

                mi = Math.Min(mi, fwd); ma = Math.Max(ma, fwd);

                fwd -= divAmount;

                mi = Math.Min(mi, fwd); ma = Math.Max(ma, fwd);

                lastDivTime = divTime;
            }

            // Set the grid boundaries
            double normInvEps = new InverseCumulativeNormal().value(1 - eps);
            double sigmaSqrtT
                = process.blackVolatility().currentLink().blackVol(maturity, strike)
                  * Math.Sqrt(maturity);

            double?xMin = Math.Log(mi) - sigmaSqrtT * normInvEps * scaleFactor;
            double?xMax = Math.Log(ma) + sigmaSqrtT * normInvEps * scaleFactor;

            if (xMinConstraint != null)
            {
                xMin = xMinConstraint;
            }
            if (xMaxConstraint != null)
            {
                xMax = xMaxConstraint;
            }

            Fdm1dMesher helper;

            if (cPoint != null &&
                cPoint.first != null &&
                Math.Log(cPoint.first.Value) >= xMin && Math.Log(cPoint.first.Value) <= xMax)
            {
                helper = new Concentrating1dMesher(xMin.Value, xMax.Value, size,
                                                   new Pair <double?, double?>(Math.Log(cPoint.first.Value), cPoint.second));
            }
            else
            {
                helper = new Uniform1dMesher(xMin.Value, xMax.Value, size);
            }

            locations_ = helper.locations();
            for (int i = 0; i < locations_.Count; ++i)
            {
                dplus_[i]  = helper.dplus(i);
                dminus_[i] = helper.dminus(i);
            }
        }
Esempio n. 20
0
 public ConvertibleFloatingRateBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, QuoteHandle creditSpread, Date issueDate, int settlementDays, IborIndex index, int fixingDays, DoubleVector spreads, DayCounter dayCounter, Schedule schedule, double redemption) : this(NQuantLibcPINVOKE.new_ConvertibleFloatingRateBond__SWIG_0(Exercise.getCPtr(exercise), conversionRatio, DividendSchedule.getCPtr(dividends), CallabilitySchedule.getCPtr(callability), QuoteHandle.getCPtr(creditSpread), Date.getCPtr(issueDate), settlementDays, IborIndex.getCPtr(index), fixingDays, DoubleVector.getCPtr(spreads), DayCounter.getCPtr(dayCounter), Schedule.getCPtr(schedule), redemption), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Esempio n. 21
0
      public ConvertibleZeroCouponBond(Exercise exercise,
                                        double conversionRatio,
                                        DividendSchedule dividends,
                                        CallabilitySchedule callability,
                                        Handle<Quote> creditSpread,
                                        Date issueDate,
                                        int settlementDays,
                                        DayCounter dayCounter,
                                        Schedule schedule,
                                        double redemption = 100)
         : base(exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays,schedule, redemption) 
      {

         cashflows_ = new List<CashFlow>();

        // !!! notional forcibly set to 100
        setSingleRedemption(100.0, redemption, maturityDate_);

        option_ = new option(this, exercise, conversionRatio, dividends, callability, creditSpread, cashflows_, dayCounter, schedule,
                             issueDate, settlementDays, redemption);
    }
Esempio n. 22
0
        public void testRegression()
        {
            // Testing fixed-coupon convertible bond in known regression case

            Date today    = new Date(23, Month.December, 2008);
            Date tomorrow = today + 1;

            Settings.Instance.setEvaluationDate(tomorrow);

            Handle <Quote> u = new Handle <Quote>(new SimpleQuote(2.9084382818797443));

            List <Date>   dates    = new InitializedList <Date>(25);
            List <double> forwards = new InitializedList <double>(25);

            dates[0]  = new Date(29, Month.December, 2008);  forwards[0] = 0.0025999342800;
            dates[1]  = new Date(5, Month.January, 2009);   forwards[1] = 0.0025999342800;
            dates[2]  = new Date(29, Month.January, 2009);   forwards[2] = 0.0053123275500;
            dates[3]  = new Date(27, Month.February, 2009);  forwards[3] = 0.0197049598721;
            dates[4]  = new Date(30, Month.March, 2009);     forwards[4] = 0.0220524845296;
            dates[5]  = new Date(29, Month.June, 2009);      forwards[5] = 0.0217076395643;
            dates[6]  = new Date(29, Month.December, 2009);  forwards[6] = 0.0230349627478;
            dates[7]  = new Date(29, Month.December, 2010);  forwards[7] = 0.0087631647476;
            dates[8]  = new Date(29, Month.December, 2011);  forwards[8] = 0.0219084299499;
            dates[9]  = new Date(31, Month.December, 2012);  forwards[9] = 0.0244798766219;
            dates[10] = new Date(30, Month.December, 2013);  forwards[10] = 0.0267885498456;
            dates[11] = new Date(29, Month.December, 2014);  forwards[11] = 0.0266922867562;
            dates[12] = new Date(29, Month.December, 2015);  forwards[12] = 0.0271052126386;
            dates[13] = new Date(29, Month.December, 2016);  forwards[13] = 0.0268829891648;
            dates[14] = new Date(29, Month.December, 2017);  forwards[14] = 0.0264594744498;
            dates[15] = new Date(31, Month.December, 2018);  forwards[15] = 0.0273450367424;
            dates[16] = new Date(30, Month.December, 2019);  forwards[16] = 0.0294852614749;
            dates[17] = new Date(29, Month.December, 2020);  forwards[17] = 0.0285556119719;
            dates[18] = new Date(29, Month.December, 2021);  forwards[18] = 0.0305557764659;
            dates[19] = new Date(29, Month.December, 2022);  forwards[19] = 0.0292244738422;
            dates[20] = new Date(29, Month.December, 2023);  forwards[20] = 0.0263917004194;
            dates[21] = new Date(29, Month.December, 2028);  forwards[21] = 0.0239626970243;
            dates[22] = new Date(29, Month.December, 2033);  forwards[22] = 0.0216417108090;
            dates[23] = new Date(29, Month.December, 2038);  forwards[23] = 0.0228343838422;
            dates[24] = new Date(31, Month.December, 2199);  forwards[24] = 0.0228343838422;

            Handle <YieldTermStructure> r = new Handle <YieldTermStructure>(new InterpolatedForwardCurve <BackwardFlat>(dates, forwards, new Actual360()));

            Handle <BlackVolTermStructure> sigma = new Handle <BlackVolTermStructure>(new BlackConstantVol(tomorrow, new NullCalendar(), 21.685235548092248,
                                                                                                           new Thirty360(Thirty360.Thirty360Convention.BondBasis)));

            BlackProcess process = new BlackProcess(u, r, sigma);

            Handle <Quote> spread = new Handle <Quote>(new SimpleQuote(0.11498700678012874));

            Date     issueDate    = new Date(23, Month.July, 2008);
            Date     maturityDate = new Date(1, Month.August, 2013);
            Calendar calendar     = new UnitedStates();
            Schedule schedule     = new MakeSchedule().from(issueDate)
                                    .to(maturityDate)
                                    .withTenor(new Period(6, TimeUnit.Months))
                                    .withCalendar(calendar)
                                    .withConvention(BusinessDayConvention.Unadjusted).value();
            int                 settlementDays  = 3;
            Exercise            exercise        = new EuropeanExercise(maturityDate);
            double              conversionRatio = 100.0 / 20.3175;
            List <double>       coupons         = new InitializedList <double>(schedule.size() - 1, 0.05);
            DayCounter          dayCounter      = new Thirty360(Thirty360.Thirty360Convention.BondBasis);
            CallabilitySchedule no_callability  = new CallabilitySchedule();
            DividendSchedule    no_dividends    = new DividendSchedule();
            double              redemption      = 100.0;

            ConvertibleFixedCouponBond bond = new ConvertibleFixedCouponBond(exercise, conversionRatio,
                                                                             no_dividends, no_callability,
                                                                             spread, issueDate, settlementDays,
                                                                             coupons, dayCounter,
                                                                             schedule, redemption);

            bond.setPricingEngine(new BinomialConvertibleEngine <CoxRossRubinstein> (process, 600));

            try
            {
                double x = bond.NPV(); // should throw; if not, an INF was not detected.
                QAssert.Fail("INF result was not detected: " + x + " returned");
            }
            catch (Exception)
            {
                // as expected. Do nothing.

                // Note: we're expecting an Error we threw, not just any
                // exception.  If something else is thrown, then there's
                // another problem and the test must fail.
            }
        }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(DividendSchedule obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Esempio n. 24
0
 public DividendVanillaOption(StrikedTypePayoff payoff, Exercise exercise,
                              List <Date> dividendDates, List <double> dividends)
     : base(payoff, exercise)
 {
     cashFlow_ = Utils.DividendVector(dividendDates, dividends);
 }
Esempio n. 25
0
      public ConvertibleFixedCouponBond( Exercise exercise,
                                         double conversionRatio,
                                         DividendSchedule dividends,
                                         CallabilitySchedule callability,
                                         Handle<Quote> creditSpread,
                                         Date issueDate,
                                         int settlementDays,
                                         List<double> coupons,
                                         DayCounter dayCounter,
                                         Schedule schedule,
                                         double redemption = 100)
         : base(exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays, schedule, redemption) 
      {

        // !!! notional forcibly set to 100
        cashflows_ = new FixedRateLeg(schedule)
                           .withCouponRates(coupons, dayCounter)
                           .withNotionals(100.0)
                           .withPaymentAdjustment(schedule.businessDayConvention());

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

        Utils.QL_REQUIRE(redemptions_.Count == 1, "multiple redemptions created");

        option_ = new option(this, exercise, conversionRatio, dividends, callability, creditSpread, cashflows_, dayCounter, schedule,
                             issueDate, settlementDays, redemption);
    }
Esempio n. 26
0
 public ConvertibleFloatingRateBond(Exercise exercise, double conversionRatio, DividendSchedule dividends, CallabilitySchedule callability, QuoteHandle creditSpread, Date issueDate, int settlementDays, IborIndex index, int fixingDays, DoubleVector spreads, DayCounter dayCounter, Schedule schedule) : this(NQuantLibcPINVOKE.new_ConvertibleFloatingRateBond__SWIG_1(Exercise.getCPtr(exercise), conversionRatio, DividendSchedule.getCPtr(dividends), CallabilitySchedule.getCPtr(callability), QuoteHandle.getCPtr(creditSpread), Date.getCPtr(issueDate), settlementDays, IborIndex.getCPtr(index), fixingDays, DoubleVector.getCPtr(spreads), DayCounter.getCPtr(dayCounter), Schedule.getCPtr(schedule)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
Esempio n. 27
0
      public ConvertibleFloatingRateBond( Exercise exercise,
                                          double conversionRatio,
                                          DividendSchedule dividends,
                                          CallabilitySchedule callability,
                                          Handle<Quote> creditSpread,
                                          Date issueDate,
                                          int settlementDays,
                                          IborIndex index,
                                          int fixingDays,
                                          List<double> spreads,
                                          DayCounter dayCounter,
                                          Schedule schedule,
                                          double redemption = 100)
         : base(exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays, schedule, redemption) 

      {
        // !!! notional forcibly set to 100
        cashflows_ = new IborLeg(schedule, index)
                        .withPaymentDayCounter(dayCounter)
                        .withFixingDays(fixingDays)
                        .withSpreads(spreads)
                        .withNotionals(100.0)
                        .withPaymentAdjustment(schedule.businessDayConvention());

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

        Utils.QL_REQUIRE( redemptions_.Count == 1, () => "multiple redemptions created" );

        option_ = new option(this, exercise, conversionRatio, dividends, callability, creditSpread, cashflows_, dayCounter, schedule,
                             issueDate, settlementDays, redemption);
    
      }
Esempio n. 28
0
 //public class engine;
 public option( ConvertibleBond bond,
                      Exercise exercise,
                      double conversionRatio,
                      DividendSchedule dividends,
                      CallabilitySchedule callability,
                      Handle<Quote> creditSpread,
                      List<CashFlow> cashflows,
                      DayCounter dayCounter,
                      Schedule schedule,
                      Date issueDate,
                      int settlementDays,
                      double redemption)
    :base(new PlainVanillaPayoff(Option.Type.Call, (bond.notionals()[0])/100.0 *redemption/conversionRatio), exercise)
 {
     bond_ = bond; 
     conversionRatio_ = conversionRatio;
     callability_ = callability; 
     dividends_ = dividends;
     creditSpread_ = creditSpread; 
     cashflows_ = cashflows;
     dayCounter_ = dayCounter; 
     issueDate_ = issueDate; 
     schedule_ = schedule;
     settlementDays_ = settlementDays; 
     redemption_ = redemption;
 }
 public Arguments()
     : base()
 {
     cashFlow = new DividendSchedule();
 }
Esempio n. 30
0
        static void Main(string[] args)
        {
            try
            {
                Option.Type type       = Option.Type.Put;
                double      underlying = 36.0;
                double      spreadRate = 0.005;

                double dividendYield = 0.02;
                double riskFreeRate  = 0.06;
                double volatility    = 0.2;

                int    settlementDays  = 3;
                int    length          = 5;
                double redemption      = 100.0;
                double conversionRatio = redemption / underlying; // at the money

                // set up dates/schedules
                Calendar calendar = new TARGET();
                Date     today    = calendar.adjust(Date.Today);

                Settings.setEvaluationDate(today);
                Date settlementDate = calendar.advance(today, settlementDays, TimeUnit.Days);
                Date exerciseDate   = calendar.advance(settlementDate, length, TimeUnit.Years);
                Date issueDate      = calendar.advance(exerciseDate, -length, TimeUnit.Years);

                BusinessDayConvention convention = BusinessDayConvention.ModifiedFollowing;

                Frequency frequency = Frequency.Annual;

                Schedule schedule = new Schedule(issueDate, exerciseDate,
                                                 new Period(frequency), calendar, convention, convention,
                                                 DateGeneration.Rule.Backward, false);

                DividendSchedule    dividends   = new DividendSchedule();
                CallabilitySchedule callability = new CallabilitySchedule();

                List <double> coupons      = new InitializedList <double>(1, 0.05);
                DayCounter    bondDayCount = new Thirty360();

                int[] callLength = { 2, 4 }; // Call dates, years 2,4.
                int[] putLength  = { 3 };    // Put dates year 3.

                double[] callPrices = { 101.5, 100.85 };
                double[] putPrices  = { 105.0 };

                // Load call schedules
                for (int i = 0; i < callLength.Length; i++)
                {
                    SoftCallability s = new SoftCallability(
                        new Callability.Price(callPrices[i], Callability.Price.Type.Clean), schedule.date(callLength[i]),
                        1.20);
                    callability.Add(s);
                }

                for (int j = 0; j < putLength.Length; j++)
                {
                    Callability s = new Callability(new Callability.Price(putPrices[j], Callability.Price.Type.Clean),
                                                    Callability.Type.Put, schedule.date(putLength[j]));
                    callability.Add(s);
                }

                // Assume dividends are paid every 6 months .
                for (Date d = today + new Period(6, TimeUnit.Months); d < exerciseDate; d += new Period(6, TimeUnit.Months))
                {
                    Dividend div = new FixedDividend(1.0, d);
                    dividends.Add(div);
                }

                DayCounter dayCounter = new Actual365Fixed();
                double     maturity   = dayCounter.yearFraction(settlementDate, exerciseDate);

                Console.WriteLine("option type = " + type);
                Console.WriteLine("Time to maturity = " + maturity);
                Console.WriteLine("Underlying price = " + underlying);
                Console.WriteLine("Risk-free interest rate = {0:0.0%}", riskFreeRate);
                Console.WriteLine("Dividend yield = {0:0.0%}%", dividendYield);
                Console.WriteLine("Volatility = {0:0.0%}%", volatility);
                Console.WriteLine("");


                // write column headings
                int[]  widths     = { 35, 14, 14 };
                int    totalWidth = widths[0] + widths[1] + widths[2];
                string rule       = new string('-', totalWidth);
                string dblrule    = new string('=', totalWidth);

                Console.WriteLine(dblrule);
                Console.WriteLine("Tsiveriotis-Fernandes method");
                Console.WriteLine(dblrule);
                Console.WriteLine("Tree Type                           European     American        ");
                Console.WriteLine(rule);


                Exercise exercise   = new EuropeanExercise(exerciseDate);
                Exercise amexercise = new AmericanExercise(settlementDate, exerciseDate);

                Handle <Quote> underlyingH = new Handle <Quote>(new SimpleQuote(underlying));
                Handle <YieldTermStructure> flatTermStructure =
                    new Handle <YieldTermStructure>(new FlatForward(settlementDate, riskFreeRate, dayCounter));
                Handle <YieldTermStructure> flatDividendTS =
                    new Handle <YieldTermStructure>(new FlatForward(settlementDate, dividendYield, dayCounter));
                Handle <BlackVolTermStructure> flatVolTS =
                    new Handle <BlackVolTermStructure>(new BlackConstantVol(settlementDate, calendar, volatility,
                                                                            dayCounter));

                BlackScholesMertonProcess stochasticProcess =
                    new BlackScholesMertonProcess(underlyingH, flatDividendTS, flatTermStructure, flatVolTS);

                int timeSteps = 801;

                Handle <Quote> creditSpread = new Handle <Quote>(new SimpleQuote(spreadRate));

                Quote rate = new SimpleQuote(riskFreeRate);

                Handle <YieldTermStructure> discountCurve =
                    new Handle <YieldTermStructure>(new FlatForward(today, new Handle <Quote>(rate), dayCounter));

                IPricingEngine engine = new BinomialConvertibleEngine <JarrowRudd>(stochasticProcess, timeSteps);

                ConvertibleFixedCouponBond europeanBond = new ConvertibleFixedCouponBond(exercise, conversionRatio,
                                                                                         dividends, callability, creditSpread, issueDate, settlementDays, coupons, bondDayCount, schedule,
                                                                                         redemption);

                europeanBond.setPricingEngine(engine);

                ConvertibleFixedCouponBond americanBond = new ConvertibleFixedCouponBond(amexercise, conversionRatio,
                                                                                         dividends, callability, creditSpread, issueDate, settlementDays, coupons, bondDayCount, schedule,
                                                                                         redemption);
                americanBond.setPricingEngine(engine);


                Console.WriteLine("Jarrow-Rudd                         {0:0.000000}   {1:0.000000}", europeanBond.NPV(), americanBond.NPV());

                americanBond.setPricingEngine(new BinomialConvertibleEngine <CoxRossRubinstein>(stochasticProcess, timeSteps));
                europeanBond.setPricingEngine(new BinomialConvertibleEngine <CoxRossRubinstein>(stochasticProcess, timeSteps));

                Console.WriteLine("CoxRossRubinstein                   {0:0.000000}   {1:0.000000}", europeanBond.NPV(), americanBond.NPV());

                americanBond.setPricingEngine(new BinomialConvertibleEngine <AdditiveEQPBinomialTree>(stochasticProcess, timeSteps));
                europeanBond.setPricingEngine(new BinomialConvertibleEngine <AdditiveEQPBinomialTree>(stochasticProcess, timeSteps));

                Console.WriteLine("AdditiveEQPBinomialTree             {0:0.000000}   {1:0.000000}", europeanBond.NPV(), americanBond.NPV());

                americanBond.setPricingEngine(new BinomialConvertibleEngine <Trigeorgis>(stochasticProcess, timeSteps));
                europeanBond.setPricingEngine(new BinomialConvertibleEngine <Trigeorgis>(stochasticProcess, timeSteps));

                Console.WriteLine("Trigeorgis                          {0:0.000000}   {1:0.000000}", europeanBond.NPV(), americanBond.NPV());

                americanBond.setPricingEngine(new BinomialConvertibleEngine <Tian>(stochasticProcess, timeSteps));
                europeanBond.setPricingEngine(new BinomialConvertibleEngine <Tian>(stochasticProcess, timeSteps));

                Console.WriteLine("Tian                                {0:0.000000}   {1:0.000000}", europeanBond.NPV(), americanBond.NPV());

                americanBond.setPricingEngine(new BinomialConvertibleEngine <LeisenReimer>(stochasticProcess, timeSteps));
                europeanBond.setPricingEngine(new BinomialConvertibleEngine <LeisenReimer>(stochasticProcess, timeSteps));

                Console.WriteLine("LeisenReimer                        {0:0.000000}   {1:0.000000}", europeanBond.NPV(), americanBond.NPV());

                americanBond.setPricingEngine(new BinomialConvertibleEngine <Joshi4>(stochasticProcess, timeSteps));
                europeanBond.setPricingEngine(new BinomialConvertibleEngine <Joshi4>(stochasticProcess, timeSteps));

                Console.WriteLine("Joshi4                              {0:0.000000}   {1:0.000000}", europeanBond.NPV(), americanBond.NPV());
                Console.WriteLine("===========================================================================");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            Console.ReadKey();
        }