Пример #1
0
        void IDataminingDatabase.addIndicator(WalkerIndicator indicator, string instrument, string fieldId)
        {
            var collection = mongodb.getDB().GetCollection("prices");

            long start = database.getFirstTimestamp();
            long end   = database.getLastTimestamp();

            string name = "Indicator " + indicator.getName() + " " + instrument + " " + fieldId;

            progress.setProgress(name, 0);
            int  done  = 0;
            long count = 0;

            var docs = collection.FindAs <BsonDocument>(Query.And(Query.Exists(fieldId), Query.EQ("instrument", instrument), Query.LT("timestamp", end), Query.GTE("timestamp", start))).SetSortOrder(SortBy.Ascending("timestamp"));

            docs.SetFlags(QueryFlags.NoCursorTimeout);
            count = docs.Count();

            foreach (var doc in docs)
            {
                progress.setProgress(name, Convert.ToInt32(Convert.ToDouble(done) / Convert.ToDouble(count) * 100d));
                done++;

                indicator.setNextData(doc["timestamp"].AsInt64, doc[fieldId].AsDouble);

                collection.FindAndModify(new FindAndModifyArgs()
                {
                    Query  = Query.EQ("_id", doc["_id"]),
                    Update = Update.Set(indicator.getName() + "_" + fieldId, indicator.getIndicator().value)
                });
            }

            progress.remove(name);
        }
        public double[] getPrediction(long timestamp)
        {
            if (indicator.isValid(timestamp) == false)
            {
                return new double[] { double.NaN, double.NaN, double.NaN, double.NaN, double.NaN }
            }
            ;
            else
            {
                double buyRatio = double.NaN, sellRatio = double.NaN, max = double.NaN, min = double.NaN, actual = double.NaN;

                //Search in outcomeCodeSamplingTable
                double v = indicator.getIndicator();
                for (int i = 0; i < outcomeCodeSamplingTable.Length; i++)
                {
                    bool lastElement = i == outcomeCodeSamplingTable.Length - 1;
                    if (lastElement ||
                        (outcomeCodeSamplingTable[i + 1][(int)SampleValuesOutcomeCodesIndices.Start] > v && outcomeCodeSamplingTable[i][(int)SampleValuesOutcomeCodesIndices.Start] <= v))
                    {
                        buyRatio  = outcomeCodeSamplingTable[i][(int)SampleValuesOutcomeCodesIndices.BuyRatio];
                        sellRatio = outcomeCodeSamplingTable[i][(int)SampleValuesOutcomeCodesIndices.SellRatio];
                        break;
                    }
                }

                //Search in outcomeSamplingTable
                for (int i = 0; i < outcomeSamplingTable.Length; i++)
                {
                    bool lastElement = i == outcomeSamplingTable.Length - 1;
                    if (lastElement ||
                        (outcomeSamplingTable[i + 1][(int)SampleValuesOutcomeIndices.Start] > v && outcomeSamplingTable[i][(int)SampleValuesOutcomeIndices.Start] <= v))
                    {
                        min    = outcomeSamplingTable[i][(int)SampleValuesOutcomeIndices.MinAvg];
                        max    = outcomeSamplingTable[i][(int)SampleValuesOutcomeIndices.MaxAvg];
                        actual = outcomeSamplingTable[i][(int)SampleValuesOutcomeIndices.ActualAvg];
                        break;
                    }
                }

                return(new double[] { buyRatio, sellRatio, min, max, actual });
            }
        }