Ejemplo n.º 1
0
        //@}
        public override void calculate()
        {
            if (!(base.arguments_.settlementType == Settlement.Type.Physical))
            {
                throw new ArgumentException("cash-settled swaptions not priced with tree engine");
            }
            if (base.model_ == null)
            {
                throw new ArgumentException("no model specified");
            }

            Date       referenceDate;
            DayCounter dayCounter;

            ITermStructureConsistentModel tsmodel =
                (ITermStructureConsistentModel)base.model_.link;

            try {
                if (tsmodel != null)
                {
                    referenceDate = tsmodel.termStructure().link.referenceDate();
                    dayCounter    = tsmodel.termStructure().link.dayCounter();
                }
                else
                {
                    referenceDate = termStructure_.link.referenceDate();
                    dayCounter    = termStructure_.link.dayCounter();
                }
            }
            catch {
                referenceDate = termStructure_.link.referenceDate();
                dayCounter    = termStructure_.link.dayCounter();
            }

            DiscretizedSwaption swaption = new DiscretizedSwaption(arguments_, referenceDate, dayCounter);
            Lattice             lattice;

            if (lattice_ != null)
            {
                lattice = lattice_;
            }
            else
            {
                List <double> times    = swaption.mandatoryTimes();
                TimeGrid      timeGrid = new TimeGrid(times, times.Count, timeSteps_);
                lattice = model_.link.tree(timeGrid);
            }

            List <double> stoppingTimes = new InitializedList <double>(arguments_.exercise.dates().Count);

            for (int i = 0; i < stoppingTimes.Count; ++i)
            {
                stoppingTimes[i] =
                    dayCounter.yearFraction(referenceDate,
                                            arguments_.exercise.date(i));
            }

            swaption.initialize(lattice, stoppingTimes.Last());

            double nextExercise;

            /*std::find_if(stoppingTimes.begin(),
             *            stoppingTimes.end(),
             *            std::bind2nd(std::greater_equal<Time>(), 0.0));*/

            List <double> listExercise = new List <double>();

            listExercise.AddRange(stoppingTimes.FindAll(x => x >= 0));
            nextExercise = listExercise[0];
            swaption.rollback(nextExercise);

            results_.value = swaption.presentValue();
        }
Ejemplo n.º 2
0
        public override void calculate()
        {
            Utils.QL_REQUIRE(arguments_.settlementMethod != Settlement.Method.ParYieldCurve, () =>
                             "cash-settled (ParYieldCurve) swaptions not priced with tree engine");

            Utils.QL_REQUIRE(model_ != null, () => "no model specified");

            Date       referenceDate;
            DayCounter dayCounter;

            ITermStructureConsistentModel tsmodel =
                (ITermStructureConsistentModel)base.model_.link;

            try
            {
                if (tsmodel != null)
                {
                    referenceDate = tsmodel.termStructure().link.referenceDate();
                    dayCounter    = tsmodel.termStructure().link.dayCounter();
                }
                else
                {
                    referenceDate = termStructure_.link.referenceDate();
                    dayCounter    = termStructure_.link.dayCounter();
                }
            }
            catch
            {
                referenceDate = termStructure_.link.referenceDate();
                dayCounter    = termStructure_.link.dayCounter();
            }

            DiscretizedSwaption swaption = new DiscretizedSwaption(arguments_, referenceDate, dayCounter);
            Lattice             lattice;

            if (lattice_ != null)
            {
                lattice = lattice_;
            }
            else
            {
                List <double> times    = swaption.mandatoryTimes();
                TimeGrid      timeGrid = new TimeGrid(times, times.Count, timeSteps_);
                lattice = model_.link.tree(timeGrid);
            }

            List <double> stoppingTimes = new InitializedList <double>(arguments_.exercise.dates().Count);

            for (int i = 0; i < stoppingTimes.Count; ++i)
            {
                stoppingTimes[i] =
                    dayCounter.yearFraction(referenceDate,
                                            arguments_.exercise.date(i));
            }

            swaption.initialize(lattice, stoppingTimes.Last());

            double nextExercise;

            List <double> listExercise = new List <double>();

            listExercise.AddRange(stoppingTimes.FindAll(x => x >= 0));
            nextExercise = listExercise[0];
            swaption.rollback(nextExercise);

            results_.value = swaption.presentValue();
        }