/// <summary> /// Create a burlish stoer rational interpolation based on arbitrary points. /// </summary> /// <param name="points">The sample points t. Supports both lists and arrays.</param> /// <param name="values">The sample point values x(t). Supports both lists and arrays.</param> /// <returns> /// An interpolation scheme optimized for the given sample points and values, /// which can then be used to compute interpolations and extrapolations /// on arbitrary points. /// </returns> public static IInterpolation RationalWithPoles(IList <double> points, IList <double> values) { var method = new BulirschStoerRationalInterpolation(); method.Initialize(points, values); return(method); }
public void FitsAtSamplePoints() { IInterpolation interpolation = BulirschStoerRationalInterpolation.Interpolate(_t, _x); for (int i = 0; i < _x.Length; i++) { Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); } }
/// <summary> /// Discount factor /// </summary> /// <param name="date"></param> /// <returns></returns> public double GetDiscountFactors(DateTime date) { // Convert dates to contineous time in untis of years var t = Utilities.ConvertToDayCountFraction(SettleDate, date); var interpolation = new BulirschStoerRationalInterpolation(T.ToArray(), DiscountFactor.ToArray()); return(interpolation.Interpolate(t)); }
public void FitsAtArbitraryPointsWithMaple( [Values(0.1, 0.4, 1.1, 3.01, 3.02, 3.03, 3.1, 3.2, 4.5, 10.0, -10.0)] double t, [Values(.19389203383553566255, .88132900698869875369, 3.5057665681580626913, 1548.7666642693586902, 3362.2564334253633516, -22332.603641443806014, -440.30323769822443789, -202.42421196280566349, 21.208249625210155439, -4.8936986959784751517, -3.6017584308603731307)] double x, [Values(1e-14, 1e-14, 1e-15, 1e-10, 1e-10, 1e-8, 1e-11, 1e-12, 1e-12, 1e-13, 1e-13)] double maxAbsoluteError) { IInterpolation interpolation = new BulirschStoerRationalInterpolation(_t, _x); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); }
public void FitsAtSamplePoints() { IInterpolation interpolation = new BulirschStoerRationalInterpolation(_t, _x); for (int i = 0; i < _x.Length; i++) { Assert.AreEqual(_x[i], interpolation.Interpolate(_t[i]), "A Exact Point " + i); } }
public void FitsAtArbitraryPointsWithMaple( [Values(0.1, 0.4, 1.1, 3.01, 3.02, 3.03, 3.1, 3.2, 4.5, 10.0, -10.0)] double t, [Values(.19389203383553566255, .88132900698869875369, 3.5057665681580626913, 1548.7666642693586902, 3362.2564334253633516, -22332.603641443806014, -440.30323769822443789, -202.42421196280566349, 21.208249625210155439, -4.8936986959784751517, -3.6017584308603731307)] double x, [Values(1e-14, 1e-14, 1e-15, 1e-10, 1e-10, 1e-8, 1e-11, 1e-12, 1e-12, 1e-13, 1e-13)] double maxAbsoluteError) { IInterpolation interpolation = new BulirschStoerRationalInterpolation(_t, _x); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); }
/// <summary> /// Discount factors /// </summary> /// <param name="dates"></param> /// <returns></returns> public Vector <double> GetDiscountFactors(DateTime[] dates) { // Convert dates to contineous time in untis of years var t = Vector <double> .Build.DenseOfArray(Utilities.ConvertToDayCountFraction(SettleDate, dates)); var interpolation = new BulirschStoerRationalInterpolation(T.ToArray(), DiscountFactor.ToArray()); var result = Vector <double> .Build.Dense(t.Count); t.Map(p => interpolation.Interpolate(p), result); return(result); }
public void FewSamples() { Assert.That(() => BulirschStoerRationalInterpolation.Interpolate(new double[0], new double[0]), Throws.ArgumentException); Assert.That(BulirschStoerRationalInterpolation.Interpolate(new[] { 1.0 }, new[] { 2.0 }).Interpolate(1.0), Is.EqualTo(2.0)); }
public void FitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError) { IInterpolation interpolation = BulirschStoerRationalInterpolation.Interpolate(_t, _x); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); }
/// <summary> /// Create a Bulirsch Stoer rational interpolation based on arbitrary points. /// </summary> /// <param name="points">The sample points t.</param> /// <param name="values">The sample point values x(t).</param> /// <returns> /// An interpolation scheme optimized for the given sample points and values, /// which can then be used to compute interpolations and extrapolations /// on arbitrary points. /// </returns> /// <remarks> /// if your data is already sorted in arrays, consider to use /// MathNet.Numerics.Interpolation.BulirschStoerRationalInterpolation.InterpolateSorted /// instead, which is more efficient. /// </remarks> public static IInterpolation RationalWithPoles(IEnumerable <double> points, IEnumerable <double> values) { return(BulirschStoerRationalInterpolation.Interpolate(points, values)); }
public void FitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError) { IInterpolation interpolation = new BulirschStoerRationalInterpolation(_t, _x); Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t); }
private static void checkSplines(Commons.SplineBox spline, Chart chart) { spline.dict = new Dictionary <double, double>(); Commons.xlist = Commons.X.ToList <double>(); Commons.ylist = Commons.Y.ToList <double>(); double step = 0.3; if (spline.POWER == 1) { spline.dict = new Dictionary <double, double>(); LinearSplineInterpolation splineInterpol = new LinearSplineInterpolation(); splineInterpol.Init(Commons.xlist, Commons.ylist); for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step) { // spline.listX.Add(i); spline.dict.Add(i, splineInterpol.Interpolate(i)); //spline.listY.Add(splineInterpol.Interpolate(i)); } } else if (spline.POWER == 2) { spline.dict = new Dictionary <double, double>(); QuadraticSpline quadraticSplineInterpol = new QuadraticSpline(); quadraticSplineInterpol.Init(Commons.xlist, Commons.ylist); for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step) { //spline.listX.Add(i); //spline.listY.Add(quadraticSplineInterpol.Interpolate(i)); spline.dict.Add(i, quadraticSplineInterpol.Interpolate(i)); } } else if (spline.POWER > 2 && spline.POWER < 5) { spline.dict = new Dictionary <double, double>(); CubicSplineInterpolation cubicSplineInterpol = new CubicSplineInterpolation(); cubicSplineInterpol.Init(Commons.xlist, Commons.ylist); for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step) { //spline.listX.Add(i); //spline.listY.Add(cubicSplineInterpol.Interpolate(i)); spline.dict.Add(i, cubicSplineInterpol.Interpolate(i)); } } else if (spline.POWER >= 5) { spline.dict = new Dictionary <double, double>(); BulirschStoerRationalInterpolation nevilleInterpol = new BulirschStoerRationalInterpolation(Commons.X, Commons.Y); for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step) { spline.dict.Add(i, nevilleInterpol.Interpolate(i)); } } /* * switch(spline.POWER) * { * case 1: * LinearSplineInterpolation splineInterpol = new LinearSplineInterpolation(); * splineInterpol.Init(Commons.xlist, Commons.ylist); * for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i+=step) * { * // spline.listX.Add(i); * spline.dict.Add(i, splineInterpol.Interpolate(i)); * //spline.listY.Add(splineInterpol.Interpolate(i)); * } * break; * case 2: * //MessageBox.Show("do not work for now"); * QuadraticSpline quadraticSplineInterpol = new QuadraticSpline(); * quadraticSplineInterpol.Init(Commons.xlist, Commons.ylist); * for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step) * { * //spline.listX.Add(i); * //spline.listY.Add(quadraticSplineInterpol.Interpolate(i)); * spline.dict.Add(i, quadraticSplineInterpol.Interpolate(i)); * } * break; * case 3: * CubicSplineInterpolation cubicSplineInterpol = new CubicSplineInterpolation(); * cubicSplineInterpol.Init(Commons.xlist, Commons.ylist); * for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step) * { * //spline.listX.Add(i); * //spline.listY.Add(cubicSplineInterpol.Interpolate(i)); * spline.dict.Add(i, cubicSplineInterpol.Interpolate(i)); * } * break; * default: * CubicSplineInterpolation cubicSplineInterpol1 = new CubicSplineInterpolation(); * QuadraticSpline quadraticSplineInterpol1 = new QuadraticSpline(); * //MathNet.Numerics.Interpolation.NevillePolynomialInterpolation * BulirschStoerRationalInterpolation nevilleInterpol = new BulirschStoerRationalInterpolation(Commons.X, Commons.Y); * NevillePolynomialInterpolation logLinearInterpol = new NevillePolynomialInterpolation(Commons.X, Commons.Y); * cubicSplineInterpol1.Init(Commons.xlist, Commons.ylist); * quadraticSplineInterpol1.Init(Commons.xlist, Commons.ylist); * for (double i = Convert.ToInt32(Commons.X[0]); i < Commons.X[Commons.X.Length - 1]; i += step) * { * //spline.listX.Add(i); * //spline.listY.Add(cubicSplineInterpol1.Interpolate(i)); * // if (Commons.xlist.Contains(i)&&spline.POWER%2!=0) * * ///if (spline.POWER % 2 != 0) * // spline.dict.Add(i, cubicSplineInterpol1.Interpolate(i + spline.POWER * 1.5)); * //else spline.dict.Add(i, quadraticSplineInterpol1.Interpolate(i + spline.POWER * 1.5)); * * ///spline.dict.Add(i, nevilleInterpol.Interpolate(i)); * //spline.dict.Add(i, logLinearInterpol.Interpolate(i)); * //else if (Commons.xlist.Contains(i) && spline.POWER%2==0) * // spline.dict.Add(i, quadraticSplineInterpol1.Interpolate(i+spline.POWER*1.5)); * } * break; * }*/ }