Beispiel #1
0
        /// <summary>
        /// Add extra dates to make sure that the minimum spacing is not too large to make the Monte Carlo errors bad.
        /// <para/>
        /// At this point the dates are all copied.
        /// </summary>
        public override void Prepare(Date anchorDate)
        {
            _anchorDate = anchorDate;
            fM          = date => _inputRate;
            PM          = date => Math.Exp(-_inputRate * (date - anchorDate) / 365.0);
            double minStepSize = 20;

            allDates.Insert(0, anchorDate);
            allDates = allDates.Distinct().ToList();
            allDates.Sort();
            var newDates = new List <Date>();

            newDates.Add(new Date(allDates[0]));
            for (var i = 1; i < allDates.Count; i++)
            {
                var nSteps = (int)Math.Floor((allDates[i] - allDates[i - 1]) / minStepSize);
                var days   = (allDates[i] - allDates[i - 1]) / (nSteps + 1);
                for (var j = 0; j < nSteps; j++)
                {
                    newDates.Add(new Date(allDates[i - 1].AddTenor(Tenor.FromDays((j + 1) * days))));
                }
                newDates.Add(new Date(allDates[i]));
            }

            allDates       = newDates;
            allDatesDouble = allDates.Select(date => (double)date).ToArray();
        }
        /// <summary>
        /// Add extra dates to make sure that the minimum spacing is not too large to make the Monte Carlo errors bad.
        /// <para/>
        /// At this point the dates are all copied.
        /// </summary>
        public override void Prepare(Date anchorDate)
        {
            _anchorDate = anchorDate;
            _fM = date => _inputRate;
            _pm = date => Math.Exp(-_inputRate * (date - anchorDate) / 365.0);
            double minStepSize = 20;
            _allDates.Insert(0, anchorDate);
            _allDates = _allDates.Distinct().ToList();
            _allDates.Sort();
            var newDates = new List<Date>();
            newDates.Add(new Date(_allDates[0]));
            for (var i = 1; i < _allDates.Count; i++)
            {
                var nSteps = (int) Math.Floor((_allDates[i] - _allDates[i - 1]) / minStepSize);
                var days = (_allDates[i] - _allDates[i - 1]) / (nSteps + 1);
                for (var j = 0; j < nSteps; j++)
                    newDates.Add(new Date(_allDates[i - 1].AddTenor(Tenor.FromDays((j + 1) * days))));
                newDates.Add(new Date(_allDates[i]));
            }

            _allDates = newDates;
            _allDatesDouble = _allDates.Select(date => (double) date).ToArray();
            _dist = new NormalDistribution();
            Generator.Seed = -1585814591; // This magic number is: "HW1FSimulator".GetHashCode();
        }
 public HullWhite1F(Currency currency, double a, double vol, double r0, double rate, Date time0)
 {
     fM             = date => rate;
     PM             = date => Math.Exp(-rate * (date - time0) / 365.0);
     this.a         = a;
     this.vol       = vol;
     this.r0        = r0;
     this.rate      = rate;
     this.time0     = time0;
     forecastTenors = new Dictionary <MarketObservable, Tenor>();
     this.currency  = currency;
 }