コード例 #1
0
        internal static DiscreteSurface ProcessMultiDimensionalPricingData(MultiDimensionalPricingData data, DateTime baseDate)
        {
            var points = data.point.Select(point => new PricingDataPoint2D(point, baseDate)).Cast <IPoint>().ToList();
            var result = new DiscreteSurface(points);

            return(result);
        }
コード例 #2
0
        internal static DiscreteSurface ProcessMultiDimensionalPricingData(MultiDimensionalPricingData data)
        {
            var points = (from point in data.point let baseDate = data.valuationDateSpecified ? (DateTime?)data.valuationDate : null select new PricingDataPoint2D(point, baseDate)).Cast <IPoint>().ToList();
            var result = new DiscreteSurface(points);//todo THERE REMAINS A PROBLEM WITH THIS CONSTRUCTOR.

            return(result);
        }
コード例 #3
0
ファイル: TestSurfaces.cs プロジェクト: zhangz/Highlander.Net
        TestDiscreteSurface2()
        {
            var curve     = new DiscreteSurface(_rows, _pointCoords, VMatrix);
            var result    = curve.GetMatrixOfValues();
            var rowlength = result.RowCount;
            var columns   = result.ColumnCount;
            var length    = curve.GetPointList().Count - 1;

            for (int i = 0; i < length; i++)
            {
                var point = curve.GetPointList()[i];
                Debug.Print("FunctionValue : {0} X Coord : {1} Y Coord : {2}",
                            point.FunctionValue, point.Coords[0], point.Coords[1]);
                //                    Assert.AreEqual(result[i, j], point.FunctionValue);
            }
            for (int j = 0; j < columns; j++)
            {
                for (int i = 0; i < rowlength; i++)
                {
                    Assert.AreEqual(result[i, j], VMatrix[i, j]);
                    Debug.Print("Matrix : {0} i : {1} j : {2}",
                                result[i, j], i, j);
                }
                //                    Assert.AreEqual(result[i, j], point.FunctionValue);
            }
        }
コード例 #4
0
        TestDiscreteSurface()
        {
            IDiscreteSpace curve = new DiscreteSurface(_rows, _pointCoords, VMatrix);

            for (int i = 0; i < curve.GetPointList().Count; i++)
            {
                IPoint point = curve.GetPointList()[i];
                Console.WriteLine(point.FunctionValue);
            }
        }
コード例 #5
0
ファイル: TestSurfaces.cs プロジェクト: zhangz/Highlander.Net
        TestInterpolatedSurface()
        {
            var curve       = new DiscreteSurface(_rows, _pointCoords, VMatrix);
            var interpCurve = new InterpolatedSurface(curve, new LinearInterpolation(), true);

            for (int i = 0; i < curve.GetPointList().Count; i++)
            {
                IPoint point = curve.GetPointList()[i];
                var    val   = interpCurve.Value(point);
                Console.WriteLine(point.FunctionValue);
            }
        }
コード例 #6
0
        public void ValueTestSixteenPoints()
        {
            List <IPoint> points
                = new List <IPoint>
                {
                new Point2D(3, 1, 5.2),
                new Point2D(3, 3, 7.9),
                new Point2D(3, 8, 8.7),
                new Point2D(3, 9, 8.9),
                new Point2D(7, 1, 8.1),
                new Point2D(7, 3, 12.4),
                new Point2D(7, 8, 12.5),
                new Point2D(7, 9, 14.7),
                new Point2D(8, 1, 8.2),
                new Point2D(8, 3, 12.2),
                new Point2D(8, 8, 12.7),
                new Point2D(8, 9, 13.6),
                new Point2D(9, 1, 8.3),
                new Point2D(9, 3, 12.2),
                new Point2D(9, 8, 12.6),
                new Point2D(9, 9, 12.9),
                };
            DiscreteSpace       surface = new DiscreteSurface(points);
            InterpolatedSurface interp  = new InterpolatedSurface(surface, new LinearInterpolation(), true);

            // Actual points
            Assert.AreEqual(5.2, interp.Value(new Point2D(3, 1, 0)));
            Assert.AreEqual(7.9, interp.Value(new Point2D(3, 3, 0)));
            Assert.AreEqual(8.7, interp.Value(new Point2D(3, 8, 0)));
            Assert.AreEqual(8.9, interp.Value(new Point2D(3, 9, 0)));
            Assert.AreEqual(8.1, interp.Value(new Point2D(7, 1, 0)));
            Assert.AreEqual(12.4, interp.Value(new Point2D(7, 3, 0)));
            Assert.AreEqual(12.5, interp.Value(new Point2D(7, 8, 0)));
            Assert.AreEqual(14.7, interp.Value(new Point2D(7, 9, 0)));
            Assert.AreEqual(8.2, interp.Value(new Point2D(8, 1, 0)));
            Assert.AreEqual(12.2, interp.Value(new Point2D(8, 3, 0)));
            Assert.AreEqual(12.7, interp.Value(new Point2D(8, 8, 0)));
            Assert.AreEqual(13.6, interp.Value(new Point2D(8, 9, 0)));
            Assert.AreEqual(8.3, interp.Value(new Point2D(9, 1, 0)));
            Assert.AreEqual(12.2, interp.Value(new Point2D(9, 3, 0)));
            Assert.AreEqual(12.6, interp.Value(new Point2D(9, 8, 0)));
            Assert.AreEqual(12.9, interp.Value(new Point2D(9, 9, 0)));
            // Interpolate
            Assert.AreEqual(12.42, interp.Value(new Point2D(7.5, 5, 0)));
            Assert.AreEqual(7.4750000000000005, interp.Value(new Point2D(4, 2, 0)));
            Assert.AreEqual(12.95, interp.Value(new Point2D(8.5, 8.5, 0)));
            // Past the boundary
            Assert.AreEqual(5.2, interp.Value(new Point2D(2, 0, 0)));
            Assert.AreEqual(12.9, interp.Value(new Point2D(10, 10, 0)));
            Assert.AreEqual(14.7, interp.Value(new Point2D(7, 10, 0)));
        }
コード例 #7
0
ファイル: TestSurfaces.cs プロジェクト: zhangz/Highlander.Net
        public void TestDiscreteSurfaceValues()
        {
            var curve = new DiscreteSurface(_rows, _pointCoords, VMatrix);

            for (int i = 0; i < curve.GetPointList().Count; i++)
            {
                var point   = curve.GetPointList()[i];
                var closest = curve.GetClosestValues(point);
                foreach (var close in closest)
                {
                    Console.WriteLine(" X: {0} Y : {1} Value1 : {2} Value2 : {3}", close.Coords[0],
                                      close.Coords[1], close.Coords[2], close.FunctionValue);
                }
            }
        }
コード例 #8
0
ファイル: TestSurfaces.cs プロジェクト: zhangz/Highlander.Net
        public void TestDiscreteSurfaceClosestValues()
        {
            var curve   = new DiscreteSurface(_rows, _pointCoords, VMatrix);
            var point   = new Point2D(0.3, 0.5);
            var closest = curve.GetClosestValues(point);

            Assert.AreEqual(closest[0].Coords[0], 0.22);
            Assert.AreEqual(closest[0].Coords[1], 0.5d);
            Assert.AreEqual(closest[0].FunctionValue, 0.055d);
            Assert.AreEqual(closest[1].Coords[0], 0.22d);
            Assert.AreEqual(closest[1].Coords[1], 0.5d);
            Assert.AreEqual(closest[1].FunctionValue, 0.055d);
            Assert.AreEqual(closest[2].Coords[0], 1.0d);
            Assert.AreEqual(closest[2].Coords[1], 0.5d);
            Assert.AreEqual(closest[2].FunctionValue, 0.075d);
            Assert.AreEqual(closest[3].Coords[0], 1.0d);
            Assert.AreEqual(closest[3].Coords[1], 0.5d);
            Assert.AreEqual(closest[3].FunctionValue, 0.075d);
        }
コード例 #9
0
        TestDiscreteSurfaceFromPointList()
        {
            var pointList = new List <IPoint>();

            for (var j = 0; j < _pointCoords.Length; j++)
            {
                for (var i = 0; i < _rows.Length; i++)
                {
                    var point = new Point2D(_rows[i], _pointCoords[j], VMatrix[i, j]);
                    pointList.Add(point);
                }
            }
            IDiscreteSpace curve = new DiscreteSurface(pointList);

            for (int i = 0; i < curve.GetPointList().Count; i++)
            {
                IPoint point = curve.GetPointList()[i];
                Console.WriteLine(point.FunctionValue);
            }
        }