示例#1
0
文件: Math.cs 项目: jmptrader/Pisces
        public static Series Polynomial(Series s, PolynomialEquation[] polyList,
                                        DateTime[] polyDateList1, DateTime[] polyDateList2,
                                        DateTime t1, DateTime t2)
        {
            int    sz   = s.Count;
            Series rval = s.Clone();

            for (int i = 0; i < sz; i++)
            {
                Point point = s[i];
                if (point.BoundedBy(t1, t2))
                {
                    Point newPt = new Point(point.DateTime, Point.MissingValueFlag, PointFlag.Missing);
                    for (int p = 0; p < polyList.Length; p++)
                    {
                        PolynomialEquation poly = polyList[p];

                        if (point.BoundedBy(polyDateList1[p], polyDateList2[p], poly.Min, poly.Max))
                        {
                            double val = poly.Eval(point.Value);
                            if (val < 0)
                            {
                                Console.WriteLine("What we have a negative number?? " + point + " eval = " + poly.Eval(point.Value));
                                // throw new Exception();
                            }
                            newPt = new Point(point.DateTime, val, PointFlag.Computed);
                            break;
                        }
                    }
                    rval.Add(newPt);
                }
            }
            return(rval);
        }
示例#2
0
文件: Math.cs 项目: jmptrader/Pisces
        /// <summary>
        /// Compute a new Time Series based on input series s
        /// and polynomial equation.
        ///
        /// Returned series has a time range specified by t1 and t2.
        /// Points outside the range of the polynomial equation (min,max)
        /// are flaged as Point.MissingValueFlag
        /// </summary>
        /// <param name="s">input time Series</param>
        /// <param name="poly">polynomial equation</param>
        /// <param name="t1">starting time for new series</param>
        /// <param name="t2">ending time for new series</param>
        /// <returns>Time Series</returns>
        public static Series Polynomial(Series s, PolynomialEquation poly,
                                        DateTime t1, DateTime t2)
        {
            int    sz   = s.Count;
            Series rval = s.Clone();

            for (int i = 0; i < sz; i++)
            {
                Point point = s[i];

                if (point.BoundedBy(t1, t2))
                {
                    Point newPt;
                    if (point.BoundedBy(t1, t2, poly.Min, poly.Max))
                    {
                        newPt = new Point(point.DateTime, poly.Eval(point.Value), PointFlag.Computed);
                    }
                    else
                    {
                        newPt = new Point(point.DateTime, Point.MissingValueFlag, PointFlag.Missing);
                    }
                    rval.Add(newPt);
                }
            }

            return(rval);
        }
示例#3
0
        public static DataTable Table(PolynomialEquation eq, double min,
                                      double max, double inc, string title)
        {
            DataTable table = new DataTable("rating");

            for (int i = 0; i < 4; i++) // 4 pairs of GateHeight,Flow
            {
                string colName = "GH" + i;
                table.Columns.Add(colName, typeof(double));
                colName = "Q" + i;
                table.Columns.Add(colName, typeof(double));
            }

            int numEntries   = Convert.ToInt32((max - min) / inc + 2);
            int numPerColumn = 51; //(int)Math.Ceiling((double)numEntries /(double)columnCount);

            int colIndex    = 0;
            int rowIndex    = 0;
            int pageCounter = 0;

            for (double gh = min; gh <= max; gh += inc)
            {
                if (rowIndex >= table.Rows.Count)
                {
                    table.Rows.Add(table.NewRow());
                }
                table.Rows[rowIndex][colIndex]     = gh;
                table.Rows[rowIndex][colIndex + 1] = eq.Eval(gh);

                rowIndex++;
                if (rowIndex >= numPerColumn * (pageCounter + 1))
                {
                    if (colIndex == 6) // new page.
                    {
                        colIndex = 0;
                        //rowIndex keep going..
                        pageCounter++;
                    }
                    else
                    {
                        rowIndex -= numPerColumn;
                        colIndex += 2;
                    }
                }
            }
            return(table);
        }