示例#1
0
        public static DBTitle LoadFromBTD(BinaryReader SR)
        {
            DBTitle ret = null;

            String titlename = SR.ReadString();
            int    seriesn   = SR.ReadInt32();

            if (titlename.Equals("") || seriesn <= 0)
            {
                return(null);
            }

            ret = new DBTitle(titlename);
            for (int k = 0; k < seriesn; k++)
            {
                String seriename = SR.ReadString();
                int    valuesn   = SR.ReadInt32();

                if (seriename.Equals("") || valuesn <= 0)
                {
                    return(null);
                }

                double[] newserie = new double[valuesn];

                for (int w = 0; w < valuesn; w++)
                {
                    newserie[w] = SR.ReadDouble();
                }

                ret.AddSerie(seriename, newserie);
            }

            return(ret);
        }
示例#2
0
        public DBTitle(DBTitle val)
        {
            this.name = val.name;
            names     = new LinkedList <String>();
            vals      = new LinkedList <double[]>();

            for (int i = 0; i < val.names.Count; i++)
            {
                AddSerie(val.names.ElementAt(i), val.vals.ElementAt(i));
            }
        }
示例#3
0
        public static DBTitle LoadFromTrade(StreamReader SR)
        {
            DBTitle ret = null;
            String  line;
            int     state     = 0;
            int     seriesn   = 0;
            String  seriename = "";

            double[]         serievals = null;
            int              i         = 0;
            NumberFormatInfo ni        = (NumberFormatInfo)CultureInfo.InstalledUICulture.NumberFormat.Clone();

            ni.NumberDecimalSeparator = ".";



            while ((line = SR.ReadLine()) != null)
            {
                line = line.Trim();

                if (line.Equals(""))
                {
                    continue;
                }

                else if (state == 1 && line.StartsWith("</title>"))
                {
                    return(ret);
                }

                else if (state == 0 && line.StartsWith("<name>"))
                {
                    String sname = line.Replace("<name>", "").Replace("</name>", "").Trim();
                    ret   = new DBTitle(sname);
                    state = 1;
                }
                else if (state == 1 && line.StartsWith("<seriesn>"))
                {
                    try { seriesn = Int32.Parse(line.Replace("<seriesn>", "").Replace("</seriesn>", "").Trim()); }
                    catch (FormatException) { return(null); }
                }
                else if (state == 1 && line.StartsWith("<serie>"))
                {
                    seriename = "";
                    serievals = null;
                    state     = 2;
                }
                else if (state == 2 && line.StartsWith("</serie>"))
                {
                    if (seriename.Equals("") || serievals == null)
                    {
                        return(null);
                    }

                    ret.AddSerie(seriename, serievals);
                    state = 1;
                }
                else if (state == 2 && line.StartsWith("<name>"))
                {
                    seriename = line.Replace("<name>", "").Replace("</name>", "").Trim();
                }
                else if (state == 2 && line.StartsWith("<valuesn>"))
                {
                    int dim;

                    try { dim = Int32.Parse(line.Replace("<valuesn>", "").Replace("</valuesn>", "").Trim()); }
                    catch (FormatException) { return(null); }

                    //                    MessageBox.Show("series are: " + dim + "\n" + "name is: " + seriename);
                    serievals = new double[dim];
                    i         = 0;
                }
                else if (state == 2 && line.StartsWith("<value>"))
                {
                    double v;

                    try { v = Double.Parse(line.Replace("<value>", "").Replace("</value>", "").Trim(), ni); }
                    catch (FormatException) { return(null); }

                    serievals[i++] = v;
                }
//                else
//                    MessageBox.Show(state + " (" + line + ")");
            }

            return(null);
        }
示例#4
0
        private static bool evaluate_subexpr(String expression, DBTrade db)
        {
            String lefttitle  = "";
            String leftfield  = "";
            String righttitle = "";
            String rightfield = "";
            String command    = "";

            double[]         parms = new double[10];
            NumberFormatInfo ni    = (NumberFormatInfo)CultureInfo.InstalledUICulture.NumberFormat.Clone();

            ni.NumberDecimalSeparator = ".";

            expression = expression.Trim();

            if (expression.Contains('='))
            {
                leftfield = expression.Substring(0, expression.IndexOf('=')).Trim();

                // per farlo bene, x.(__) x è un nome di titolo?
                if (leftfield.Contains('.'))
                {
                    lefttitle = leftfield.Substring(0, leftfield.IndexOf('.'));
                    leftfield = leftfield.Substring(leftfield.IndexOf('.') + 1);
                }
                expression = expression.Substring(expression.IndexOf('=') + 1).Trim();
            }
            // lefttitle e leftfield apposto.

            expression = expression.Replace(")", "");
            if (!expression.Contains('('))
            {
                return(false);
            }
            command    = expression.Substring(0, expression.IndexOf('('));
            expression = expression.Substring(expression.IndexOf('(') + 1);


            String[] otherparms = expression.Trim().Split(',');
            if (!otherparms[0].Contains('.'))
            {
                return(false);
            }

            righttitle = otherparms[0].Substring(0, otherparms[0].IndexOf('.'));
            rightfield = otherparms[0].Substring(otherparms[0].IndexOf('.') + 1);


            for (int j = 1; j < otherparms.Length; j++)
            {
                try { parms[j - 1] = Double.Parse(otherparms[j], ni); }
                catch (FormatException) { return(false); }
            }

            if (lefttitle.Equals(""))       // if not specified left title
            {
                lefttitle = righttitle;
            }

            // now left* right*, command, parms are ok
//            MessageBox.Show(lefttitle + "." + leftfield + " = "+command+"(" + righttitle + "." + rightfield+")");
            DBTitle srcTitle = db.getByName(righttitle);
            DBTitle dstTitle = db.getByName(lefttitle);

            if (srcTitle == null || dstTitle == null)
            {
                return(false);
            }

            double[] srcSerie = srcTitle.GetSerieByName(rightfield);
            if (srcSerie == null)
            {
                return(false);
            }



            double[] result = null;
            if (command.Equals("const"))
            {
                result = TI.calculate_const(srcSerie.Length, parms[0]);
            }
            else if (command.Equals("mm"))
            {
                result = TI.calculate_mm(srcSerie, (int)parms[0]);
            }
            else if (command.Equals("emm"))
            {
                result = TI.calculate_emm(srcSerie, (int)parms[0], parms[1]);
            }

            else if (command.Equals("d") || command.Equals("d-"))
            {
                result = TI.calculate_d(srcSerie, (int)parms[0]);
            }
            else if (command.Equals("d%") || command.Equals("d-%") || command.Equals("dperc") || command.Equals("d-perc"))
            {
                result = TI.calculate_dperc(srcSerie, (int)parms[0]);
            }
            else if (command.Equals("d2") || command.Equals("d2-"))
            {
                result = TI.calculate_d2(srcSerie, (int)parms[0]);
            }

            else if (command.Equals("sigma"))
            {
                result = TI.calculate_sigma(srcSerie, (int)parms[0]);
            }
            else if (command.Equals("esigma"))
            {
                result = TI.calculate_esigma(srcSerie, (int)parms[0], parms[1]);
            }

            else if (command.Equals("BBhigh"))
            {
                result = TI.calculate_BBhigh(srcSerie, (int)parms[0], parms[1]);
            }
            else if (command.Equals("BBlow"))
            {
                result = TI.calculate_BBlow(srcSerie, (int)parms[0], parms[1]);
            }
            else if (command.Equals("BBWp"))
            {
                result = TI.calculate_BBWp(srcSerie, (int)parms[0], parms[1]);
            }
            else if (command.Equals("BBBp"))
            {
                result = TI.calculate_BBBp(srcSerie, (int)parms[0], parms[1]);
            }

            else if (command.Equals("range"))
            {
                result = TI.calculate_range(srcSerie, (int)parms[0]);
            }
            else if (command.Equals("stochK"))
            {
                result = TI.calculate_stochasticK(srcSerie, (int)parms[0], parms[1]);
            }

            else if (command.Equals("RSIC"))
            {
                result = TI.calculate_RSIC(srcSerie, (int)parms[0]);
            }
            else if (command.Equals("RSIV"))
            {
                result = TI.calculate_RSIV(srcSerie, (int)parms[0]);
            }



            else if (command.Equals("rand"))
            {
                result = TI.calculate_rand(srcSerie, parms[0], parms[1]);
            }



            if (result != null)
            {
                dstTitle.AddSerie(leftfield, result);
                return(true);
            }
            else
            {
                return(false);
            }
        }