public Image visualizeIndicatorValues(int widht, int height, double[][] prices) { double validRatio; double[] values = IndicatorRunner.getIndicatorValues(prices, indicator.Clone(), out validRatio); return(ArrayVisualizer.visualizeArray(values, widht, height, 15)); }
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; }