public void TestPiecewiseConstantRateInterpolation()
        {
            Random r = new Random(Environment.TickCount);

            TearDown();
            IInterpolation interpolation = new PiecewiseConstantZeroRateInterpolation();

            interpolation.Initialize(_times, _rates);
            for (int i = 0; i < 10; ++i)
            {
                double time       = i;
                double interpRate = interpolation.ValueAt(time, true);
                Debug.WriteLine($"interpolatedRate : {interpRate} Time: {time}");
            }
            int index = 0;

            foreach (double time in _times)
            {
                if (time != 0.0)
                {
                    double interpRate  = interpolation.ValueAt(time, true);
                    double interpValue = _rates[index];
                    Assert.AreEqual(interpRate, interpValue, 10 - 8);
                }
                index++;
            }
        }
Example #2
0
        public void TestPiecewiseRateInterpolatedCurve()
        {
            var                interp      = new PiecewiseConstantZeroRateInterpolation();//PWL requires the first point to be after the first 2 in the curve..
            DiscreteCurve      curve       = new DiscreteCurve(_pointCoords, _pointValues);
            IInterpolatedSpace interpCurve = new InterpolatedCurve(curve, interp, true);

            foreach (double point in _testPointArray)
            {
                IPoint p    = new Point1D(point);
                double val  = interpCurve.Value(p);
                double rate = val;
                Console.WriteLine(val);
                Console.WriteLine(rate);
            }
        }
        public void TestPiecewiseZeroRateConstantInterpolation()
        {
            TearDown();
            double[] exp           = SetUp();
            Random   r             = new Random(Environment.TickCount);
            var      interpolation = new PiecewiseConstantZeroRateInterpolation();

            interpolation.Initialize(_times, exp);
            for (int i = 0; i < 10; ++i)
            {
                double time       = i + r.Next(-10000, 10000) / 10000;
                double interpRate = interpolation.ValueAt(time, true);
                Debug.WriteLine($"interpolatedRate : {interpRate} Time: {time}");
            }
        }