Ejemplo n.º 1
0
        public static TradingData fetchRandomSeries(int timestepRange)
        {
            TradingData series;

            do
            {
                Random rnd                    = new Random();
                int    startIndex             = rnd.Next(0, allData.Length - timestepRange + 1);
                TimeStepDataPiece[] randomSet = new TimeStepDataPiece[timestepRange];
                for (int i = 0; i < timestepRange; ++i)
                {
                    randomSet[i] = allData[startIndex + i];
                }
                series = new TradingData(randomSet);
            } while (series.MaximumGainFactor < 1.3 || series.MaximumLossFactor < 1.6);
            return(series);
        }
Ejemplo n.º 2
0
        public static void initializeData()
        {
            Console.Write("Loading data set... ");
            // A piece of data looks like the following.
            // {"date":1482565500,"high":7.22192054,"low":7.22192054,"open":7.22192054,"close":7.22192054,"volume":0,"quoteVolume":0,"weightedAverage":7.22192054}
            JArray dataArray = JArray.Parse(File.ReadAllText(StorageLayer.FILE_IO_PATH + "eth_esdt_poloniex.json"));

            allData = new TimeStepDataPiece[dataArray.Count];
            int[] cciRanges = new int[] { 2, 5, 10, 20, 50, 100, 200, 500, 1000 };
            MovingAverageTracker[] movingAverageTrackers = new MovingAverageTracker[cciRanges.Length];
            int index = 0;

            foreach (int cciRange in cciRanges)
            {
                movingAverageTrackers[index++] = new MovingAverageTracker(cciRange);
            }
            index = 0;
            foreach (JObject o in dataArray.Children <JObject>())
            {
                double high            = -1.0;
                double low             = -1.0;
                double close           = -1.0;
                double weightedAverage = -1.0;
                foreach (JProperty p in o.Properties())
                {
                    string name  = p.Name;
                    string value = (string)p.Value;
                    switch (name)
                    {
                    case "high":
                        high = Double.Parse(value);
                        break;

                    case "low":
                        low = Double.Parse(value);
                        break;

                    case "close":
                        close = Double.Parse(value);
                        break;

                    case "weightedAverage":
                        weightedAverage = Double.Parse(value);
                        break;
                    }
                }
                if (high < 0.0 || low < 0.0 || close < 0.0 || weightedAverage < 0.0)
                {
                    throw new Exception("One of the following properties: {\"high\", \"low\", \"close\". \"weightedAverage\"} was not found in the current piece of JSON data.\n " + o.ToString());
                }
                double   typicalPrice = (high + low + close) / 3.0;
                double[] ccis         = new double[cciRanges.Length];
                int      cciIndex     = 0;
                foreach (MovingAverageTracker mat in movingAverageTrackers)
                {
                    mat.feedNextValue(typicalPrice);
                    // CCI calculation. Divided by 1.5 rather than .0015 so that the majority range from -1 to 1 rahter than -100 to 100.
                    ccis[cciIndex++] = (typicalPrice - mat.MovingAverage) / (mat.calcStdDev() * 1.5);
                }
                allData[index++] = new TimeStepDataPiece(typicalPrice, ccis, cciRanges);
            }
            Console.WriteLine("Loaded.");
        }