private void optimizeInternally(List <string> indicatorsToTry, IndicatorSelector selector)
        {
            while (ended == false)
            {
                try
                {
                    //generator.getGeneratedIndicator(Convert.ToInt32(outcomeTimeframe / 1000 / 15), Convert.ToInt32(outcomeTimeframe * 100 / 1000));
                    int index = getNextIndex();
                    if (index >= indicatorsToTry.Count)
                    {
                        break;
                    }

                    WalkerIndicator   wi = IndicatorGenerator.getIndicatorByString(indicatorsToTry[index]);
                    LearningIndicator li = new LearningIndicator(wi, priceData, outcomeCodeData, outcomeData, outcomeTimeframe, outcomeCodePercent, minPercentThreshold, learningIndicatorSteps, true);

                    selector.pushIndicatorStatistics(li);
                }
                catch (TooLittleValidDataException e)
                {
                    //Logger.log("E:" + e.Message);
                }
                catch (TooLittleStatesException e)
                {
                    //Logger.log("E:" + e.Message);
                }
                catch (Exception e)
                {
                    Logger.log("FATAL:" + e.Message);
                }
            }

            ended = true;
        }
Ejemplo n.º 2
0
        public static double[] getIndicatorValues(double[][] priceData, WalkerIndicator indicator, out double indicatorValidRatio)
        {
            indicatorValidRatio = 0;
            double[] output = new double[priceData.Length];

            for (int i = 0; i < priceData.Length; i++)
            {
                long   timestamp = Convert.ToInt64(priceData[i][(int)PriceDataIndeces.Date]);
                double mid       = (priceData[i][(int)PriceDataIndeces.Ask] + priceData[i][(int)PriceDataIndeces.Bid]) / 2d;
                double value     = indicator.setNextDataAndGetIndicator(timestamp, mid);

                if (double.IsNaN(value) == false && double.IsInfinity(value) == false && indicator.isValid(timestamp))
                {
                    output[i] = value;
                    indicatorValidRatio++;
                }
                else
                {
                    output[i] = double.NaN;
                }
            }

            indicatorValidRatio /= output.Length;

            return(output);
        }
Ejemplo n.º 3
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 WalkerIndicator getGeneratedIndicator(int minTimeFrameSeconds, int maxTimeframeSeconds)
        {
            while (true)
            {
                WalkerIndicator theIndicator = getRandomIndicator(minTimeFrameSeconds, maxTimeframeSeconds);
                if (doneIndicators.ContainsKey(theIndicator.getName()) == false)
                {
                    try {
                        doneIndicators.Add(theIndicator.getName(), true);
                    }
                    catch (Exception e) { Logger.log("#######: " + e.Message); }

                    return(theIndicator);
                }
            }
        }
Ejemplo n.º 5
0
        private void testAndSubmitResult(WalkerIndicator indicator)
        {
            Logger.log("Testing Indicator: " + indicator.getName());

            LearningIndicator li = new LearningIndicator(indicator, priceData, outcomeCodeData, outcomeData, outcomeTimeframe, outcomeCodePercent, 0.5, learningIndicatorSteps, true);

            double[] pp = li.getPredictivePowerArray();

            //Results
            string output = "";

            foreach (double d in pp)
            {
                output += d + ";";
            }

            output += li.getUsedValues() + ";";
            output += indicator.getName().Split('_')[0] + ";" + indicator.getName();

            Logger.log("Result: " + li.getName());
            state = li.getName();
            submitResults(output);
        }
Ejemplo n.º 6
0
        private void maxPpOutcomeCodeBtn_Click(object sender, EventArgs e)
        {
            DataminingInputDialog id = new DataminingInputDialog(new string[] { "instrument", "outcomeCodeId" }, dataminingDb.getInfo());

            id.ShowDialog();

            long operationSum    = 0;
            int  operationsCount = 0;

            if (id.isValidResult())
            {
                string instrument = id.getResult()["instrument"];
                string outcomeId  = id.getResult()["outcomeCodeId"];

                string folderPath = Config.startupPath + "/analysis/";
                if (Directory.Exists(folderPath) == false)
                {
                    Directory.CreateDirectory(folderPath);
                }

                string graphFolderPath = folderPath + "ppForIndicators-" + outcomeId + "/";
                Directory.CreateDirectory(graphFolderPath);

                string indicatorListFilename = folderPath + "ppForIndicators-" + outcomeId + ".csv";
                if (File.Exists(indicatorListFilename) == false)
                {
                    writeTextToFile(indicatorListFilename, "OverHalf;MaxDiff;Direction;LinRegr;LogRegr;Indicator" + Environment.NewLine);
                }

                //Start some threads for
                for (int threadId = 0; threadId < 2; threadId++) //Todo: Do 4 threads
                {
                    new Thread(delegate()
                    {
                        while (true)
                        {
                            try
                            {
                                Stopwatch watch = new Stopwatch();
                                watch.Start();

                                WalkerIndicator indicator = IndicatorGenerator.getRandomIndicator();
                                string indicatorId        = "mid-" + indicator.getName();

                                Logger.log("Start indicator: " + indicatorId, "maxPp");

                                setState("Max pp: avg" + Math.Round(operationSum / 1000d / (operationsCount != 0 ? operationsCount : 1)) + "s" + " n" + operationsCount);

                                try {
                                    dataminingDb.addIndicator(indicator, instrument, "mid");
                                } catch (IndicatorNeverValidException)
                                {
                                    writeTextToFile(indicatorListFilename, "x;x;x;" + indicatorId + Environment.NewLine);
                                    Logger.log("Invalid Indicator " + indicatorId, "maxPp");
                                    continue;
                                }

                                Logger.log("Get info", "maxPp");
                                DistributionRange range = dataminingDb.getInfo(indicatorId).ranges["5"];

                                SampleOutcomeCodeExcelGenerator excel = new SampleOutcomeCodeExcelGenerator(graphFolderPath + indicatorId + ".xls");

                                Logger.log("Start sampling", "maxPp");
                                double[] ppMethod1 = dataminingDb.getOutcomeCodeIndicatorSampling(excel, indicatorId, 20, range, outcomeId, instrument);

                                excel.FinishDoc();

                                /*double[][] inputsTraining = new double[0][], outputsTraining = new double[0][];
                                 * dataminingDb.getInputOutputArrays(new string[] { indicatorId }, outcomeId, instrument, ref inputsTraining, ref outputsTraining, DataGroup.All, 1000 * 20, 0);
                                 *
                                 * double[][] inputsTest = new double[0][], outputsTest = new double[0][];
                                 * dataminingDb.getInputOutputArrays(new string[] { indicatorId }, outcomeId, instrument, ref inputsTest, ref outputsTest, DataGroup.All, 5000, 1);
                                 *
                                 * double ppMethod2 = PredictivePowerAnalyzer.getPredictivePowerWithMl(inputsTraining, outputsTraining, inputsTest, outputsTest, MLMethodForPPAnalysis.LinearRegression);
                                 *
                                 * double ppMethod3 = PredictivePowerAnalyzer.getPredictivePowerWithMl(inputsTraining, outputsTraining, inputsTest, outputsTest, MLMethodForPPAnalysis.LogRegression);*/

                                Logger.log("write to file", "maxPp");
                                //over 0.5, maxDiff, direction
                                string resultLine = ppMethod1[0] + ";" + ppMethod1[1] + ";" + ppMethod1[2] + ";" + "ni" + ";" + "ni" + ";" + indicatorId;
                                writeTextToFile(indicatorListFilename, resultLine + Environment.NewLine);
                                Logger.sendImportantMessage(DateTime.Now.ToShortTimeString() + " - " + resultLine);

                                Logger.log("remove datasets", "maxPp");
                                dataminingDb.removeDataset(indicatorId, instrument);

                                watch.Stop();
                                operationSum += watch.ElapsedMilliseconds;
                                operationsCount++;
                            }
                            catch {
                                Logger.log("Error in thread method", "maxPp");
                            }
                        }
                    }).Start();
                }
            }
        }
        public LearningIndicator(WalkerIndicator indicator, double[][] prices, bool[][] outcomeCodes, double[][] outcomes, long timeframe, double targetPercent, double minPercentThreshold, int steps, bool createStatistics)
        {
            this.targetPercent = targetPercent;
            this.timeframe     = timeframe;

            double validRatio;

            double[] values = IndicatorRunner.getIndicatorValues(prices, indicator.Clone(), out validRatio);
            if (validRatio < 0.5)
            {
                throw new TooLittleValidDataException("Not enough valid values: " + validRatio);
            }

            //May be does not work properly... todo:
            double min, max, usedValuesRatio;

            //DistributionHelper.getMinMax(values, 4, out min, out max);
            DistributionHelper.getMinMax(values, out min, out max);

            outcomeCodeSamplingTable = IndicatorSampler.sampleValuesOutcomeCode(values, outcomeCodes, min, max, steps, out usedValuesRatio);
            if (usedValuesRatio < 0.5)
            {
                throw new TooLittleValidDataException("Not enough sampling for outcomeCode: " + usedValuesRatio);
            }

            outcomeSamplingTable = IndicatorSampler.sampleValuesOutcome(values, prices, outcomes, min, max, out usedValuesRatio, 40);
            if (usedValuesRatio < 0.5)
            {
                throw new TooLittleValidDataException("Not enough sampling for outcome: " + usedValuesRatio);
            }

            this.usedValues = usedValuesRatio;

            if (createStatistics)
            {
                //Predictive power calculation
                predictivePower = new double[33];
                IndicatorSampler.getStatisticsOutcomeCodes(values, outcomeCodes, out predictivePower[0], out predictivePower[1], out predictivePower[2], out predictivePower[3]);
                IndicatorSampler.getStatisticsOutcomes(values, prices, outcomes, out predictivePower[4], out predictivePower[5], out predictivePower[6], out predictivePower[7], out predictivePower[8], out predictivePower[9]);

                DistributionHelper.getSampleOutcomeCodesBuyMaxSellMax(outcomeCodeSamplingTable, minPercentThreshold, out predictivePower[10], out predictivePower[11], out predictivePower[12], out predictivePower[13]);
                DistributionHelper.getSampleOutcomesMinMax(outcomeSamplingTable, minPercentThreshold, out predictivePower[14], out predictivePower[15], out predictivePower[16], out predictivePower[17], out predictivePower[18], out predictivePower[19], out predictivePower[20], out predictivePower[21], out predictivePower[22], out predictivePower[23]);

                //Outcome Code

                List <double> buyCodesDist        = new List <double>(),
                              sellCodesDist       = new List <double>(),
                              buySellDistanceDist = new List <double>(),
                              minMaxDistanceDist  = new List <double>(),
                              minDist             = new List <double>(),
                              maxDist             = new List <double>(),
                              actualDist          = new List <double>();

                double totalCodeSamples = 0;
                foreach (double[] row in outcomeCodeSamplingTable)
                {
                    totalCodeSamples += row[(int)SampleValuesOutcomeCodesIndices.SamplesCount];
                }

                int regardedStates = 0;
                foreach (double[] row in outcomeCodeSamplingTable)
                {
                    if ((row[(int)SampleValuesOutcomeCodesIndices.SamplesCount] / totalCodeSamples) * 100 >= minPercentThreshold) //minPercentThreshold
                    {
                        buyCodesDist.Add(row[(int)SampleValuesOutcomeCodesIndices.BuyRatio]);
                        sellCodesDist.Add(row[(int)SampleValuesOutcomeCodesIndices.SellRatio]);
                        buySellDistanceDist.Add(Math.Abs(row[(int)SampleValuesOutcomeCodesIndices.BuyRatio] - row[(int)SampleValuesOutcomeCodesIndices.SellRatio]));
                        regardedStates++;
                    }
                }

                predictivePower[(int)LearningIndicatorPredictivePowerIndecies.valuesOverMinPercentRatioCode] = Convert.ToDouble(regardedStates) / outcomeCodeSamplingTable.Length;

                if (regardedStates <= 2)
                {
                    throw new TooLittleStatesException("Too little sates: " + regardedStates);
                }

                predictivePower[(int)LearningIndicatorPredictivePowerIndecies.buyCodeStD]             = buyCodesDist.StandardDeviation();
                predictivePower[(int)LearningIndicatorPredictivePowerIndecies.sellCodeStD]            = sellCodesDist.StandardDeviation();
                predictivePower[(int)LearningIndicatorPredictivePowerIndecies.buySellCodeDistanceStD] = buySellDistanceDist.StandardDeviation();

                //Outcome

                double totalSamples = 0;
                foreach (double[] row in outcomeSamplingTable)
                {
                    totalSamples += row[(int)SampleValuesOutcomeIndices.SamplesCount];
                }

                //Avgs
                regardedStates = 0;
                foreach (double[] row in outcomeSamplingTable)
                {
                    if ((row[(int)SampleValuesOutcomeIndices.SamplesCount] / totalSamples) * 100 > minPercentThreshold) //minPercentThreshold
                    {
                        maxDist.Add(row[(int)SampleValuesOutcomeIndices.MaxAvg]);
                        minDist.Add(row[(int)SampleValuesOutcomeIndices.MinAvg]);
                        minMaxDistanceDist.Add(Math.Abs(row[(int)SampleValuesOutcomeIndices.MaxAvg]) + row[(int)SampleValuesOutcomeIndices.MinAvg]);
                        actualDist.Add(row[(int)SampleValuesOutcomeIndices.ActualAvg]);
                        regardedStates++;
                    }
                }

                predictivePower[(int)LearningIndicatorPredictivePowerIndecies.valuesOverMinPercentRatioOutcome] += Convert.ToDouble(regardedStates) / outcomeSamplingTable.Length;

                //avg distances
                predictivePower[(int)LearningIndicatorPredictivePowerIndecies.maxStD]            = maxDist.StandardDeviation();
                predictivePower[(int)LearningIndicatorPredictivePowerIndecies.minStD]            = minDist.StandardDeviation();
                predictivePower[(int)LearningIndicatorPredictivePowerIndecies.minMaxDistanceStd] = minMaxDistanceDist.StandardDeviation();
                predictivePower[(int)LearningIndicatorPredictivePowerIndecies.actualStD]         = actualDist.StandardDeviation();

                if (double.IsNaN(predictivePower[(int)LearningIndicatorPredictivePowerIndecies.buyCodeStD]) ||
                    double.IsNaN(predictivePower[(int)LearningIndicatorPredictivePowerIndecies.sellCodeStD]) ||
                    double.IsNaN(predictivePower[(int)LearningIndicatorPredictivePowerIndecies.buySellCodeDistanceStD]) ||
                    double.IsNaN(predictivePower[(int)LearningIndicatorPredictivePowerIndecies.maxStD]) ||
                    double.IsNaN(predictivePower[(int)LearningIndicatorPredictivePowerIndecies.minStD]) ||
                    double.IsNaN(predictivePower[(int)LearningIndicatorPredictivePowerIndecies.minMaxDistanceStd]) ||
                    double.IsNaN(predictivePower[(int)LearningIndicatorPredictivePowerIndecies.actualStD]))
                {
                    throw new Exception("Not a valid predictive power!");
                }

                //End predictive power calculation
            }

            this.indicator = indicator;
        }
Ejemplo n.º 8
0
        public static WalkerIndicator getRandomIndicator()
        {
            WalkerIndicator theIndicator = null;

            long timeframeOne   = z.Next(1, 2880) * 60 * 1000;
            long timeframeTwo   = z.Next(1, 2880) * 60 * 1000;
            long timeFrameThree = z.Next(1, 2880) * 60 * 1000;

            long timeFrameSmaller = z.Next(1, 2880) * 60 * 1000;

            switch (z.Next(0, 18)) //Todo: set max value for choosing the indicator
            {
            case 0:
                theIndicator = new BolingerBandsIndicator(timeframeOne, getRanDouble(1d, 5d));
                break;

            case 1:
                theIndicator = new MACDContinousIndicator(timeframeOne, timeframeTwo, timeFrameSmaller);
                break;

            case 2:
                theIndicator = new MACDIndicator(timeframeOne, timeframeTwo, timeFrameSmaller);
                break;

            case 3:
                theIndicator = new MovingAveragePriceSubtractionIndicator(timeframeOne);
                break;

            case 4:
                theIndicator = new MovingAverageSubtractionCrossoverIndicator(timeframeOne, timeframeTwo);
                break;

            case 5:
                theIndicator = new MovingAverageSubtractionIndicator(timeframeOne, timeframeTwo);
                break;

            case 6:
                theIndicator = new RangeIndicator(timeframeOne);
                break;

            case 7:
                theIndicator = new RSIBorderCrossoverIndicator(timeframeOne, getRanDouble(0.1, 0.4));
                break;

            case 8:
                theIndicator = new RSIBorderIndicator(timeframeOne, getRanDouble(0.1, 0.4));
                break;

            case 9:
                theIndicator = new RSIIndicator(timeframeOne);
                break;

            case 10:
                theIndicator = new RSIMACrossoverContinousIndicator(timeframeOne, timeFrameSmaller);
                break;

            case 11:
                theIndicator = new RSIMACrossoverIndicator(timeframeOne, timeFrameSmaller);
                break;

            case 12:
                theIndicator = new StandartDeviationIndicator(timeframeOne);
                break;

            case 13:
                theIndicator = new StochBorderCrossoverIndicator(timeframeOne, getRanDouble(0.1, 0.4));
                break;

            case 14:
                theIndicator = new StochBorderIndicator(timeframeOne, getRanDouble(0.1, 0.4));
                break;

            case 15:
                theIndicator = new StochIndicator(timeframeOne);
                break;

            case 16:
                theIndicator = new VolumeAtPriceIndicator(timeframeOne, getRanDouble(0.0003, 0.002), z.Next(1000 * 30, 1000 * 60 * 10));
                break;     //Not sure about stepsize todo

            case 17:
                theIndicator = new TimeOfDayIndicator();     //Only once?
                break;

            case 18:
                theIndicator = new TimeDayOfWeekIndicator();     //Todo: Only once?
                break;

            default:
                throw new Exception("Fired a unexpected random value");
            }

            return(theIndicator);
        }
        public static WalkerIndicator getIndicatorByString(string input)
        {
            string[] args;

            if (input.Contains("_") == false)
            {
                args = new string[] { input }
            }
            ;
            else
            {
                args = input.Split('_');
            }

            WalkerIndicator selected = null;

            if (args[0] == BolingerBandsIndicator.Name)
            {
                selected = new BolingerBandsIndicator(long.Parse(args[1]), double.Parse(args[2]));
            }

            if (args[0] == MACDContinousIndicator.Name)
            {
                selected = new MACDContinousIndicator(long.Parse(args[1]), long.Parse(args[2]), long.Parse(args[3]));
            }

            if (args[0] == MACDIndicator.Name)
            {
                selected = new MACDIndicator(long.Parse(args[1]), long.Parse(args[2]), long.Parse(args[3]));
            }

            if (args[0] == MovingAverageIndicator.Name)
            {
                selected = new MovingAverageIndicator(long.Parse(args[1]));
            }

            if (args[0] == MovingAveragePriceSubtractionIndicator.Name)
            {
                selected = new MovingAveragePriceSubtractionIndicator(long.Parse(args[1]));
            }

            if (args[0] == MovingAverageSubtractionIndicator.Name)
            {
                selected = new MovingAverageSubtractionIndicator(long.Parse(args[1]), long.Parse(args[2]));
            }

            if (args[0] == MovingAverageSubtractionCrossoverIndicator.Name)
            {
                selected = new MovingAverageSubtractionCrossoverIndicator(long.Parse(args[1]), long.Parse(args[2]));
            }

            if (args[0] == RangeIndicator.Name)
            {
                selected = new RangeIndicator(long.Parse(args[1]));
            }

            if (args[0] == RSIBorderCrossoverIndicator.Name)
            {
                selected = new RSIBorderCrossoverIndicator(long.Parse(args[1]), double.Parse(args[2]));
            }

            if (args[0] == RSIBorderIndicator.Name)
            {
                selected = new RSIBorderIndicator(long.Parse(args[1]), double.Parse(args[2]));
            }

            if (args[0] == RSIIndicator.Name)
            {
                selected = new RSIIndicator(long.Parse(args[1]));
            }

            if (args[0] == RSIMACrossoverContinousIndicator.Name)
            {
                selected = new RSIMACrossoverContinousIndicator(long.Parse(args[1]), long.Parse(args[2]));
            }

            if (args[0] == RSIMACrossoverIndicator.Name)
            {
                selected = new RSIMACrossoverIndicator(long.Parse(args[1]), long.Parse(args[2]));
            }

            if (args[0] == StandartDeviationIndicator.Name)
            {
                selected = new StandartDeviationIndicator(long.Parse(args[1]));
            }

            if (args[0] == StochBorderCrossoverIndicator.Name)
            {
                selected = new StochBorderCrossoverIndicator(long.Parse(args[1]), double.Parse(args[2]));
            }

            if (args[0] == StochBorderIndicator.Name)
            {
                selected = new StochBorderIndicator(long.Parse(args[1]), double.Parse(args[2]));
            }

            if (args[0] == StochIndicator.Name)
            {
                selected = new StochIndicator(long.Parse(args[1]));
            }

            if (args[0] == TestIndicator.Name)
            {
                selected = new TestIndicator();
            }

            if (args[0] == TimeDayOfWeekIndicator.Name)
            {
                selected = new TimeDayOfWeekIndicator();
            }

            if (args[0] == TimeOfDayIndicator.Name)
            {
                selected = new TimeOfDayIndicator();
            }

            if (args[0] == TimeOpeningHoursIndicator.Name)
            {
                selected = new TimeOpeningHoursIndicator();
            }

            if (args[0] == VolumeAtPriceIndicator.Name)
            {
                selected = new VolumeAtPriceIndicator(long.Parse(args[1]), double.Parse(args[2]), long.Parse(args[3]));
            }

            if (selected == null)
            {
                throw new Exception("Name not found: " + args[0]);
            }

            if (selected.getName() != input)
            {
                throw new Exception(input + " != " + selected.getName());
            }

            return(selected);
        }
Ejemplo n.º 10
0
        public void updateIndicators(long timeframeToLookBack, long timeframeToLookBackForIndicatorInit, IndicatorSelector indicatorSelector)
        {
            List <double[]> selectedPriceData = new List <double[]>();

            for (int i = priceData.Count - 1; i > 0; i--)
            {
                if (Convert.ToInt64(priceData[i][(int)PriceDataIndeces.Date]) > timestampNow - timeframeToLookBack)
                {
                    selectedPriceData.Insert(0, priceData[i]); //Todo: List direction correct?
                }
                else
                {
                    break;
                }
            }

            double[][] selectedPriceDataArray = selectedPriceData.ToArray();
            double     s;

            double[][] outcomeData = OutcomeGenerator.getOutcome(selectedPriceDataArray, outcomeTimeframe, out s);
            if (s < 0.6)
            {
                throw new Exception("s < o.6: " + s);
            }

            //bool[][] outcomeCodeData = OutcomeGenerator.getOutcomeCode(selectedPriceDataArray, outcomeData, outcomeCodePercent, out s);
            bool[][] outcomeCodeFirstData = OutcomeGenerator.getOutcomeCodeFirst(selectedPriceDataArray, outcomeTimeframe, outcomeCodePercent, out s);
            if (s < 0.6)
            {
                throw new Exception("s < o.6: " + s);
            }

            string[] indicatorIds;

            //This part can be skipped by caching todo: get from outside
            double hash = outcomeTimeframe + selectedPriceData[0].Sum() + selectedPriceData[selectedPriceData.Count - 1].Sum() + selectedPriceData[selectedPriceData.Count / 2].Sum();
            string optimalIndicatorsFileName = cachePath + "/" + "optimalIndicatorsIn_" + hash + "_" + selectedPriceData[selectedPriceData.Count - 1][(int)PriceDataIndeces.Date] + "_" + timeframeToLookBack + "_" + outcomeCodePercent + ".txt";

            if (cachePath != null && File.Exists(optimalIndicatorsFileName))
            {
                indicatorIds = File.ReadAllText(optimalIndicatorsFileName).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                Logger.log("Loaded optimal indicators from file: " + optimalIndicatorsFileName);
            }
            else
            {
                //Shuffle okay indicators? todo:
                Logger.log("Generated optimal indicators");
                IndicatorOptimizer optimizer = new IndicatorOptimizer(selectedPriceDataArray, outcomeData, outcomeCodeFirstData, outcomeTimeframe, outcomeCodePercent, minPercentThreshold, learningIndicatorSteps);
                indicatorIds = optimizer.getOptimizedIndicators(okayIndicators, indicatorSelector, 8);

                File.WriteAllLines(optimalIndicatorsFileName, indicatorIds);
            }

            Logger.log("Selected indicators: ");
            List <LearningIndicator> lis = new List <LearningIndicator>();

            foreach (string str in indicatorIds)
            {
                Logger.log(str);

                WalkerIndicator ind = IndicatorGenerator.getIndicatorByString(str);
                if (ind.getName() != str)
                {
                    throw new Exception(str + "!=" + ind.getName());
                }

                lis.Add(new LearningIndicator(ind, selectedPriceDataArray, outcomeCodeFirstData, outcomeData, outcomeTimeframe, outcomeCodePercent, minPercentThreshold, learningIndicatorSteps, false));
            }

            SignalMachine sm = new AlternativeSignalMachine(lis.ToArray()); //Todo: make accessable copy?

            Logger.log("SM STATE: ##################" + Environment.NewLine + sm.getStateMessage());

            //Make them up to date
            List <double[]> selectedPriceDataForIndicatorInit = new List <double[]>();

            for (int i = priceData.Count - 1; i > 0; i--)
            {
                if (Convert.ToInt64(priceData[i][(int)PriceDataIndeces.Date]) > timestampNow - timeframeToLookBackForIndicatorInit)
                {
                    selectedPriceDataForIndicatorInit.Insert(0, priceData[i]); //Todo: List direction correct?
                }
                else
                {
                    break;
                }
            }

            foreach (double[] row in selectedPriceDataForIndicatorInit)
            {
                sm.pushPrice(row);
            }

            this.signalMachine = sm;
        }
Ejemplo n.º 11
0
        private void FindOkayIndicatorsForm_Load(object sender, EventArgs e)
        {
            timer1.Start();

            string okayIndicatorsFile = "okayIndicators" + outcomeTimeframe + ".txt";

            if (File.Exists(okayIndicatorsFile))
            {
                List <string> lines = File.ReadLines(okayIndicatorsFile).ToList();
                foreach (string line in lines)
                {
                    if (line != "" && line != null && line != " ")
                    {
                        found.Add(line, true);
                    }
                }
            }

            DataLoader dl = new DataLoader(Config.DataPath + pair);

            double[][] priceData = dl.getArray(1000 * 60 * 60 * 24 * 30l,
                                               timeframeToTest,
                                               minTimestep); //One month, but the second. Every 10 secs

            double success;

            bool[][] outcomeCodeFirstData = OutcomeGenerator.getOutcomeCodeFirst(priceData, outcomeTimeframe, outcomeCodePercent, out success);

            if (success < 0.7)
            {
                throw new Exception("OutcomeCode low success: " + success);
            }

            double[][] outcomeData = OutcomeGenerator.getOutcome(priceData, outcomeTimeframe, out success);

            if (success < 0.7)
            {
                throw new Exception("Outcome low success: " + success);
            }

            IndicatorGenerator generator = new IndicatorGenerator();

            new Thread(delegate() {
                while (true)
                {
                    WalkerIndicator ind = generator.getGeneratedIndicator(Convert.ToInt32((outcomeTimeframe / 1000) / 10), Convert.ToInt32((outcomeTimeframe / 1000) * 100));

                    try
                    {
                        if (found.ContainsKey(ind.getName()) == false)
                        {
                            tried++;
                            new LearningIndicator(ind, priceData, outcomeCodeFirstData, outcomeData, outcomeTimeframe, outcomeCodePercent, minPercentThreshold, learningIndicatorSteps, false);
                            File.AppendAllText(okayIndicatorsFile, ind.getName() + Environment.NewLine);
                            found.Add(ind.getName(), true);
                        }
                    }
                    catch (Exception) { }
                }
            }).Start();
        }
Ejemplo n.º 12
0
 public FakeTradingAPI()
 {
     tradingTime = new TimeOpeningHoursIndicator();
 }