static void OldMain(string[] args)
        {
            FileDataBaseProvider dbProvider = new FileDataBaseProvider("../../../../../Data/EURUSD.csv");
            DataBase inputDb = dbProvider.GetDataBase();
            inputDb.PrintDBProperties();

            DataBase indicatorsDb = new DataBase("indicators DB");
            indicatorsDb["openChangeInd"] = IndicatorsCalculator.CalcChangeIndicator(inputDb["open"]);
            indicatorsDb["openChangeIndMAvg20"] = IndicatorsCalculator.CalcMovingMean(indicatorsDb["openChangeInd"], 20);
            indicatorsDb["openChangeIndMAvg50"] = IndicatorsCalculator.CalcMovingMean(indicatorsDb["openChangeInd"], 50);
            indicatorsDb["%RInd10"] = IndicatorsCalculator.CalcPercentRIndicator(inputDb["high"],inputDb["low"], inputDb["close"], 10);
            indicatorsDb["%RInd20"] = IndicatorsCalculator.CalcPercentRIndicator(inputDb["high"], inputDb["low"], inputDb["close"], 20);
            indicatorsDb["%RInd10Mod"] = IndicatorsCalculator.CalcPercentRIndicatorModified(inputDb["high"], inputDb["low"], inputDb["close"], 10);
            indicatorsDb["%RInd20Mod"] = IndicatorsCalculator.CalcPercentRIndicatorModified(inputDb["high"], inputDb["low"], inputDb["close"], 20);
            indicatorsDb["WilliamsAccDistr"] = IndicatorsCalculator.CalcWilliamsAccumulationDistributionIndicator(inputDb["high"], inputDb["low"], inputDb["close"]);
            indicatorsDb.PrintDBProperties();

            var plotter = Plotter.GetInstance();
            plotter.AddPlot(inputDb["close"].GetRange(1000, 200), "close");
            //plotter.AddPlot(indicatorsDb["openChangeInd"].GetRange(1000, 500), "openChangeInd");
            //plotter.AddPlot(indicatorsDb["openChangeIndMAvg20"].GetRange(1000, 500), "openChangeIndMAvg20");
            //plotter.AddPlot(indicatorsDb["openChangeIndMAvg50"].GetRange(1000, 500), "openChangeIndMAvg50");
            //plotter.AddPlot(indicatorsDb["%RInd10"].GetRange(1000, 500), "RInd10");
            //plotter.AddPlot(indicatorsDb["%RInd20"].GetRange(1000, 500), "RInd20");
            plotter.AddPlot(indicatorsDb["WilliamsAccDistr"].GetRange(1000, 200), "WilliamsAccDistr");

            Console.WriteLine("Press any button");
            Console.ReadKey();
        }
        public DataPoint Cut(DataBase db, int offset)
        {
            int dataSize = db.CountVectorElements;
            if (dataSize < offset + forwardStepsToPredict_)
                throw new ArgumentOutOfRangeException();
            if (offset < Helpers.ModifiedFibbonacci(backTicksPerIndicator_ - 1))
                throw new ArgumentOutOfRangeException(String.Format(
                    "offset should be > {0}",
                    Helpers.ModifiedFibbonacci(backTicksPerIndicator_ - 1).ToString()));

            DataPoint outputPoint = new DataPoint();

            //changing loops with their places would speed it up, but this possition will make output more understandable
            foreach(string currIndicator in indicatorsToUseNames_)
            {
                for (int i = 0; i < backTicksPerIndicator_; i++)
                {
                    int currIndex = offset - Helpers.ModifiedFibbonacci(i);

                    outputPoint.input.Add(db[currIndicator][currIndex]);
                }
            }

            outputPoint.output = db[outputName_][offset + forwardStepsToPredict_];

            return outputPoint;
        }
        public DataBase GetDataBase()
        {
            if (db != null)
                return db;

            db = new DataBase("DB from File");
            using (StreamReader sr = new StreamReader(filePath))
            {
                string line = sr.ReadLine(); //1st line is not needed (for now)
                while ((line = sr.ReadLine()) != null)
                {
                    string[] splittedLine = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (splittedLine[0] == "5") //just take 5 - min data
                    {
                        db["open"].Add(Convert.ToDouble(splittedLine[4], doubleFormatProvider));
                        db["high"].Add(Convert.ToDouble(splittedLine[2], doubleFormatProvider));
                        db["low"].Add(Convert.ToDouble(splittedLine[3], doubleFormatProvider));
                        db["close"].Add(Convert.ToDouble(splittedLine[5], doubleFormatProvider));
                    }

                }
            }

            return db;
        }
        public void DataPointCutterCutMethodShouldThrowTest()
        {
            DataBase db = new DataBase(new List<double> { 1.0d, 2.0d, 3.0d, 4.0d, 5.0d }, "test");

            DataPointCutter cutter = new DataPointCutter(2, new HashSet<string>() { "test" }, 2, "test");

            DataPoint dataPoint = cutter.Cut(db, 0);
        }
        public void DataBasePlusOperatorShouldFailIfKeysAreSame()
        {
            DataBase db1 = new DataBase();
            db1["a"].Add(1.0d);

            DataBase db2 = new DataBase();
            db2["a"].Add(2.0d);

            db1 += db2;
        }
        public void DataBasePlusOperatorTest()
        {
            DataBase db1 = new DataBase();
            db1["a"].Add(1.0d);

            DataBase db2 = new DataBase();
            db2["b"].Add(2.0d);

            db1 += db2;

            Assert.AreEqual(1.0d, db1["a"][0]);
            Assert.AreEqual(2.0d, db1["b"][0]);
        }
        public void DataPointCutterCutMethodTest()
        {
            DataBase db = new DataBase(new List<double> { 1.0d, 2.0d, 3.0d, 4.0d, 5.0d }, "test");

            DataPointCutter cutter = new DataPointCutter(2, new HashSet<string>() { "test" }, 2, "test");

            DataPoint dataPoint = cutter.Cut(db, 2);

            Assert.AreEqual(2, dataPoint.input.Count);
            Assert.AreEqual(3.0d, dataPoint.input[0]);
            Assert.AreEqual(2.0d, dataPoint.input[1]);

            Assert.AreEqual(5.0d, dataPoint.output);
        }
        public void DataBaseAccessTest()
        {
            DataBase db = new DataBase();

            const double val1 = 2.0d;
            const double val2 = 3.0d;
            const string key = "Dupa";

            db[key].Add(val1);
            db[key].Add(val2);

            Assert.AreEqual(2, db[key].Count);
            Assert.AreEqual(val1, db[key][0]);
            Assert.AreEqual(val2, db[key][1]);
        }
        /// <summary>
        /// joins databases
        /// </summary>
        /// <param name="database">databases cannot contain same keys!</param>
        /// <returns></returns>
        public static DataBase operator +(DataBase db1, DataBase db2)
        {
            DataBase newDb = new DataBase();

            foreach (var item in db1.db)
            {
                if (db2.db.ContainsKey(item.Key))
                    throw new ArgumentException("databases you want to add contains same key");

                newDb[item.Key].AddRange(item.Value);
            }

            foreach (var item in db2.db)
            {
                newDb[item.Key].AddRange(item.Value);
            }

            return newDb;
        }
        public void DataBaseCloneRangeTest()
        {
            DataBase db = new DataBase();

            db["a"].Add(1.0d);
            db["a"].Add(2.0d);
            db["a"].Add(3.0d);

            db["b"].Add(11.0d);
            db["b"].Add(12.0d);
            db["b"].Add(13.0d);

            const int beginIndex = 1;
            const int count = 2;
            DataBase dbClone = db.CloneDbRange(beginIndex, count);

            Assert.AreEqual(2, dbClone.CountVectorElements);
            Assert.AreEqual(2.0d, dbClone["a"][0]);
            Assert.AreEqual(3.0d, dbClone["a"][1]);
            Assert.AreEqual(12.0d, dbClone["b"][0]);
            Assert.AreEqual(13.0d, dbClone["b"][1]);
        }
Beispiel #11
0
        public DataBase CloneDbRange(int beginIndex, int count)
        {
            int dataVectorSize = CountVectorElements;
            if (beginIndex < 0 || beginIndex >= dataVectorSize)
                throw new ArgumentOutOfRangeException("beginIndex");
            if(count < 1)
                throw new ArgumentOutOfRangeException("count");
            if (beginIndex + count > dataVectorSize)
                throw new ArgumentOutOfRangeException("beginIndex + count");

            DataBase dataBase = new DataBase();
            foreach (var item in db)
            {
                dataBase[item.Key] = item.Value.GetRange(beginIndex, count);
            }

            return dataBase;
        }
        public void DataBaseValidationShouldFailOnFDiffNoOfParameters()
        {
            DataBase db = new DataBase();

            db["a"].Add(1.0d);

            db["b"].Add(1.0d);
            db["b"].Add(2.0d);

            db.ValidateDB(); //expect exception
        }
        public void DataBaseValidationShouldCountVectorElementsCorrectly()
        {
            DataBase db = new DataBase();

            db["b"].Add(1.0d);
            db["b"].Add(1.0d);

            Assert.AreEqual(2, db.CountVectorElements);
        }
        public void DataBaseValidationShouldFailOnMinusInfValueInsideDb()
        {
            DataBase db = new DataBase();
            db["a"].Add(Double.NegativeInfinity);

            db.ValidateDB(); //expect exception
        }
        public void DataBaseValidationShouldFailOnNaNValueInsideDb()
        {
            DataBase db = new DataBase();
            db["a"].Add(Double.NaN);

            db.ValidateDB(); //expect exception
        }
        public void DataBaseConstructionTest()
        {
            DataBase db = new DataBase(new List<double>() { 1.0d, 2.0d }, "test5g");

            Assert.AreEqual(2.0d, db["test5g"][1]);
        }
        public void DataBaseValidationShouldPasslOnCorrectNoOfParametes()
        {
            DataBase db = new DataBase();

            db["a"].Add(1.0d);
            db["a"].Add(2.0d);

            db["b"].Add(1.0d);
            db["b"].Add(2.0d);

            db.ValidateDB(); //expect no exception
        }