Exemple #1
0
        public override void calculate()
        {
            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();
            }

            DiscretizedSwap swap  = new DiscretizedSwap(arguments_, referenceDate, dayCounter);
            List <double>   times = swap.mandatoryTimes();
            Lattice         lattice;

            if (lattice_ != null)
            {
                lattice = lattice_;
            }
            else
            {
                TimeGrid timeGrid = new TimeGrid(times, times.Count, timeSteps_);
                lattice = model_.link.tree(timeGrid);
            }

            swap.initialize(lattice, times.Last());
            swap.rollback(0.0);

            results_.value = swap.presentValue();
        }
        public DiscretizedSwaption(Swaption.Arguments args,
                                    Date referenceDate,
                                    DayCounter dayCounter)
            : base(new DiscretizedSwap(args, referenceDate, dayCounter), args.exercise.type(), new List<double>())
        {
            arguments_=args;
            exerciseTimes_ = new InitializedList<double>(arguments_.exercise.dates().Count);
            for (int i = 0; i < exerciseTimes_.Count; ++i)
                exerciseTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            arguments_.exercise.date(i));

            // Date adjustments can get time vectors out of synch.
            // Here, we try and collapse similar dates which could cause
            // a mispricing.
            for (int i=0; i<arguments_.exercise.dates().Count; i++) {
                Date exerciseDate = arguments_.exercise.date(i);
            for (int j = 0; j < arguments_.fixedPayDates.Count; j++) {
                if (withinNextWeek(exerciseDate,
                                   arguments_.fixedPayDates[j])
                    // coupons in the future are dealt with below
                    && arguments_.fixedResetDates[j] < referenceDate)
                    arguments_.fixedPayDates[j] = exerciseDate;
            }
            for (int j = 0; j < arguments_.fixedResetDates.Count; j++) {
                if (withinPreviousWeek(exerciseDate,
                                       arguments_.fixedResetDates[j]))
                    arguments_.fixedResetDates[j] = exerciseDate;
            }
            for (int j = 0; j < arguments_.floatingResetDates.Count; j++) {
                if (withinPreviousWeek(exerciseDate,
                                       arguments_.floatingResetDates[j]))
                    arguments_.floatingResetDates[j] = exerciseDate;
            }
        }

        double lastFixedPayment =
            dayCounter.yearFraction(referenceDate,
                                    arguments_.fixedPayDates.Last() );
        double lastFloatingPayment =
            dayCounter.yearFraction(referenceDate,
                                    arguments_.floatingPayDates.Last());
        lastPayment_ = Math.Max(lastFixedPayment,lastFloatingPayment);

        underlying_ =   new DiscretizedSwap(arguments_,
                                            referenceDate,
                                            dayCounter);

        }
        public DiscretizedSwaption(Swaption.Arguments args,
                                   Date referenceDate,
                                   DayCounter dayCounter)
            : base(new DiscretizedSwap(args, referenceDate, dayCounter), args.exercise.type(), new List <double>())
        {
            arguments_     = args;
            exerciseTimes_ = new InitializedList <double>(arguments_.exercise.dates().Count);
            for (int i = 0; i < exerciseTimes_.Count; ++i)
            {
                exerciseTimes_[i] =
                    dayCounter.yearFraction(referenceDate,
                                            arguments_.exercise.date(i));
            }

            // Date adjustments can get time vectors out of synch.
            // Here, we try and collapse similar dates which could cause
            // a mispricing.
            for (int i = 0; i < arguments_.exercise.dates().Count; i++)
            {
                Date exerciseDate = arguments_.exercise.date(i);
                for (int j = 0; j < arguments_.fixedPayDates.Count; j++)
                {
                    if (withinNextWeek(exerciseDate,
                                       arguments_.fixedPayDates[j])
                        // coupons in the future are dealt with below
                        && arguments_.fixedResetDates[j] < referenceDate)
                    {
                        arguments_.fixedPayDates[j] = exerciseDate;
                    }
                }
                for (int j = 0; j < arguments_.fixedResetDates.Count; j++)
                {
                    if (withinPreviousWeek(exerciseDate,
                                           arguments_.fixedResetDates[j]))
                    {
                        arguments_.fixedResetDates[j] = exerciseDate;
                    }
                }
                for (int j = 0; j < arguments_.floatingResetDates.Count; j++)
                {
                    if (withinPreviousWeek(exerciseDate,
                                           arguments_.floatingResetDates[j]))
                    {
                        arguments_.floatingResetDates[j] = exerciseDate;
                    }
                }
            }

            double lastFixedPayment =
                dayCounter.yearFraction(referenceDate,
                                        arguments_.fixedPayDates.Last());
            double lastFloatingPayment =
                dayCounter.yearFraction(referenceDate,
                                        arguments_.floatingPayDates.Last());

            lastPayment_ = Math.Max(lastFixedPayment, lastFloatingPayment);

            underlying_ = new DiscretizedSwap(arguments_,
                                              referenceDate,
                                              dayCounter);
        }