Pelsser.SquaredGaussianModel.CalculateValueForCache C# (CSharp) Method

CalculateValueForCache() private method

Precalculates several values and functions of the model in order to cache them for later use.
private CalculateValueForCache ( double dates ) : void
dates double /// The vector of dates which will be used to simulate the model. ///
return void
        internal void CalculateValueForCache(double[] dates)
        {
            this.CacheDates = new double[dates.Length];
            dates.CopyTo(this.CacheDates, 0);

            double dt = dates[1] - dates[0];
            double INT = Int(0, dates[0]);
            this.alphaT = new double[dates.Length];
            this.cDeltaT = new double[dates.Length];
            this.dDeltaT = new double[dates.Length];

            this.dDeltaT[0] = 1;
            this.cDeltaT[0] = 0;
            this.alphaT[0] = F(dates[0], dt) + 2 * Math.Exp(-this.alpha1Temp * dates[0]) * INT;

            DateTime t0 = DateTime.Now;

            for (int i = 1; i < dates.Length; i++)
            {
                double current = dates[i];

                // If it's not like this keep the last calculated value.
                if (i < dates.Length - 1)
                    dt = dates[i + 1] - current;
                INT += Int(dates[i - 1], current);

                if (double.IsNaN(INT))
                {
                    throw new Exception(string.Format("Pelsser model: error while initializing: a={0} s={1}, Int({2},{3})",
                                                      this.alpha1Temp, this.sigma1Temp, dates[i - 1], current));
                }

                this.alphaT[i] = F(current, dt) + 2 * Math.Exp(-this.alpha1Temp * current) * INT;
                this.cDeltaT[i] = C(current);
                this.dDeltaT[i] = D(current);
            }

            DateTime t1 = DateTime.Now;
            DateTime t2 = DateTime.Now;
        }