closestTime() public method

public closestTime ( double t ) : double
t double
return double
        public DiscretizedVanillaOption(VanillaOption.Arguments args, StochasticProcess process, TimeGrid grid) {
            arguments_ = args;

            stoppingTimes_ = new InitializedList<double>(args.exercise.dates().Count);
            for (int i=0; i<stoppingTimes_.Count; ++i) {
                stoppingTimes_[i] = process.time(args.exercise.date(i));
                if (!grid.empty()) {
                    // adjust to the given grid
                    stoppingTimes_[i] = grid.closestTime(stoppingTimes_[i]);
                }
            }
        }
Esempio n. 2
0
        public DiscretizedVanillaOption(VanillaOption.Arguments args, StochasticProcess process, TimeGrid grid)
        {
            arguments_ = args;

            stoppingTimes_ = new InitializedList <double>(args.exercise.dates().Count);
            for (int i = 0; i < stoppingTimes_.Count; ++i)
            {
                stoppingTimes_[i] = process.time(args.exercise.date(i));
                if (!grid.empty())
                {
                    // adjust to the given grid
                    stoppingTimes_[i] = grid.closestTime(stoppingTimes_[i]);
                }
            }
        }
Esempio n. 3
0
        public DiscretizedBarrierOption(BarrierOption.Arguments args, StochasticProcess process, TimeGrid grid = null)
        {
            arguments_ = args;
            vanilla_   = new DiscretizedVanillaOption(arguments_, process, grid);

            Utils.QL_REQUIRE(args.exercise.dates().Count > 0, () => "specify at least one stopping date");

            stoppingTimes_ = new InitializedList <double>(args.exercise.dates().Count);
            for (int i = 0; i < stoppingTimes_.Count; ++i)
            {
                stoppingTimes_[i] = process.time(args.exercise.date(i));
                if (grid != null && !grid.empty())
                {
                    // adjust to the given grid
                    stoppingTimes_[i] = grid.closestTime(stoppingTimes_[i]);
                }
            }
        }
Esempio n. 4
0
        public DiscretizedConvertible(ConvertibleBond.option.Arguments args,
                                      GeneralizedBlackScholesProcess process, TimeGrid grid)
        {
            arguments_ = args;
            process_   = process;

            dividendValues_ = new Vector(arguments_.dividends.Count, 0.0);

            Date settlementDate = process.riskFreeRate().link.referenceDate();

            for (int i = 0; i < arguments_.dividends.Count; i++)
            {
                if (arguments_.dividends[i].date() >= settlementDate)
                {
                    dividendValues_[i] = arguments_.dividends[i].amount() *
                                         process.riskFreeRate().link.discount(arguments_.dividends[i].date());
                }
            }

            DayCounter dayCounter     = process.riskFreeRate().currentLink().dayCounter();
            Date       bondSettlement = arguments_.settlementDate;

            stoppingTimes_ = new InitializedList <double>(arguments_.exercise.dates().Count, 0.0);
            for (var i = 0; i < stoppingTimes_.Count; i++)
            {
                stoppingTimes_[i] = dayCounter.yearFraction(bondSettlement, arguments_.exercise.date(i));
            }

            callabilityTimes_ = new InitializedList <double>(arguments_.callabilityDates.Count, 0.0);
            for (var i = 0; i < callabilityTimes_.Count; i++)
            {
                callabilityTimes_[i] = dayCounter.yearFraction(bondSettlement, arguments_.callabilityDates[i]);
            }

            couponTimes_ = new InitializedList <double>(arguments_.couponDates.Count, 0.0);
            for (var i = 0; i < couponTimes_.Count; i++)
            {
                couponTimes_[i] = dayCounter.yearFraction(bondSettlement, arguments_.couponDates[i]);
            }

            dividendTimes_ = new InitializedList <double>(arguments_.dividendDates.Count, 0.0);
            for (var i = 0; i < dividendTimes_.Count; i++)
            {
                dividendTimes_[i] = dayCounter.yearFraction(bondSettlement, arguments_.dividendDates[i]);
            }

            if (!grid.empty())
            {
                // adjust times to grid
                for (var i = 0; i < stoppingTimes_.Count; i++)
                {
                    stoppingTimes_[i] = grid.closestTime(stoppingTimes_[i]);
                }

                for (var i = 0; i < couponTimes_.Count; i++)
                {
                    couponTimes_[i] = grid.closestTime(couponTimes_[i]);
                }

                for (var i = 0; i < dividendTimes_.Count; i++)
                {
                    dividendTimes_[i] = grid.closestTime(dividendTimes_[i]);
                }

                for (var i = 0; i < callabilityTimes_.Count; i++)
                {
                    callabilityTimes_[i] = grid.closestTime(callabilityTimes_[i]);
                }
            }
        }