コード例 #1
0
        public void TestLogLinearInterpolation()
        {
            double[] t             = { 0.0, 1.0, 2.0, 3.0, 5.0 };
            double[] y             = { 1.0, .98, .95, .93, .88 };
            double[] exp           = SetUp();
            Random   r             = new Random(Environment.TickCount);
            var      interpolation = new LogLinearInterpolation();

            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}");
            }
            interpolation.Initialize(t, y);
            double[] a = { 2.4, 10.9 };
            double[] b = { 0.941948898488354, 0.724019983080858 };
            double   c = 1e-15;

            for (var i = 0; i < a.Length; i++)
            {
                var val = interpolation.ValueAt(a[i], true);
                Assert.AreEqual(b[i], val, c);
            }
        }
コード例 #2
0
        public void TestInterpolatedCurve2()
        {
            IInterpolation     interp      = new LogLinearInterpolation();
            DiscreteCurve      curve       = new DiscreteCurve(_pointCoords, _pointValues2);
            IInterpolatedSpace interpCurve = new InterpolatedCurve(curve, interp, true);

            foreach (double point in _testPointArray)
            {
                IPoint p = new Point1D(point);
                Console.WriteLine(interpCurve.Value(p));
            }
        }
コード例 #3
0
        public void TestLogLinearInterpolation()
        {
            double[]       exp           = SetUp();
            Random         r             = new Random(Environment.TickCount);
            IInterpolation interpolation = new LogLinearInterpolation();

            //            IList list = new ArrayList(exp.ToGeneralVector().StorageArray);
            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}");
            }
        }
コード例 #4
0
ファイル: Math.cs プロジェクト: xdfjord/EliteQuant_Excel
        public static string eqMathLogLinearInterpolation(
            [ExcelArgument(Description = "interpolation obj id")] string objId,
            [ExcelArgument(Description = "variable x ")] double[] x,
            [ExcelArgument(Description = "variable y ")] double[] y)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (x.Length != y.Length)
                {
                    return("size mismatch");
                }

                QlArray xa = new QlArray((uint)x.Length);
                QlArray ya = new QlArray((uint)y.Length);

                for (uint i = 0; i < x.Length; i++)
                {
                    xa.set(i, x[i]);
                    ya.set(i, y[i]);
                }

                LogLinearInterpolation interp = new LogLinearInterpolation(xa, ya);

                // Store the futures and return its id
                string id = "Int@" + objId;
                OHRepository.Instance.storeObject(id, interp, callerAddress);
                id += "#" + (String)DateTime.Now.ToString(@"HH:mm:ss");
                return(id);
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
コード例 #5
0
ファイル: Math.cs プロジェクト: xdfjord/EliteQuant_Excel
        public static object eqMathGet1DInterpolation(
            [ExcelArgument(Description = "interpolation obj id")] string objId,
            [ExcelArgument(Description = "variable x ")] double x,
            [ExcelArgument(Description = "Linear/LogLinear ")] string type)
        {
            if (ExcelUtil.CallFromWizard())
            {
                return("");
            }

            string callerAddress = "";

            callerAddress = ExcelUtil.getActiveCellAddress();

            try
            {
                if (type.ToUpper() == "LINEAR")
                {
                    LinearInterpolation interp = OHRepository.Instance.getObject <LinearInterpolation>(objId);
                    double ret = interp.call(x, true);

                    return(ret);
                }
                else if (type.ToUpper() == "LOGLINEAR")
                {
                    LogLinearInterpolation interp = OHRepository.Instance.getObject <LogLinearInterpolation>(objId);
                    double ret = interp.call(x, true);

                    return(ret);
                }
                else
                {
                    return("Unknown interpolation type");
                }
            }
            catch (Exception e)
            {
                ExcelUtil.logError(callerAddress, System.Reflection.MethodInfo.GetCurrentMethod().Name.ToString(), e.Message);
                return(e.Message);
            }
        }
コード例 #6
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(LogLinearInterpolation obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
コード例 #7
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(LogLinearInterpolation obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }