public override Advice GetActionForBuckets(List <TradeBucket> tradeBuckets) { Advice advice = new Advice(); advice.AlgorithmName = Name; advice.Confidence = 0; advice.Group = Group; advice.Time = tradeBuckets[tradeBuckets.Count - 1].Time; List <TradeBucket> buckets = tradeBuckets; WilliamsR rsi = new WilliamsR(); TIOutput output = rsi.GetCurrentValue(buckets); advice.Price = buckets[buckets.Count - 1].Close; advice.Confidence = (decimal)output.Value; if (output.Value < 20) { advice.Action = TradeAction.Sell; } else if (output.Value > 80) { advice.Action = TradeAction.Buy; } else { advice.Action = TradeAction.Hold; } return(advice); }
private void williamsRParameterNext_Click(object sender, EventArgs e) { williamsRResultTitle.Text = Code + " için Williams' %R sonucu"; WilliamsRPeriod = (int)williamsRPeriod.Value; williamsRCloseChart.Series.Clear(); williamsRIndicatorChart.Series.Clear(); var closeSeries = new Series { Name = "Kapanış", Color = System.Drawing.Color.Black, ChartType = SeriesChartType.Line }; var wsrSeries = new Series { Name = "Williams' R", Color = System.Drawing.Color.Blue, ChartType = SeriesChartType.Line }; williamsRCloseChart.Series.Add(closeSeries); williamsRIndicatorChart.Series.Add(wsrSeries); var closeData = IndicatorService.GetData(Code, TargetDate, new string[] { "Tarih", "Kapanis" }, NumberOfData); DateTime date; double[] wsr; if (MapReduceAllowed) { wsr = WilliamsR.WsrMR(Code, TargetDate, WilliamsRPeriod, NumberOfData); } else { wsr = WilliamsR.Wsr(Code, TargetDate, WilliamsRPeriod, NumberOfData); } for (int i = 0; i < wsr.Length; i++) { var close = closeData.ElementAt(i); date = close.GetElement("Tarih").Value.AsBsonDateTime.ToLocalTime(); closeSeries.Points.AddXY(date, close.GetElement("Kapanis").Value.ToDouble()); wsrSeries.Points.AddXY(date, wsr[i]); } williamsRCloseChart.ChartAreas[0].AxisY.Minimum = Math.Floor(closeData.Select(p => p.GetElement("Kapanis").Value.ToDouble()).Min()); williamsRCloseChart.ChartAreas[0].AxisY.Maximum = Math.Ceiling(closeData.Select(p => p.GetElement("Kapanis").Value.ToDouble()).Max()); williamsRIndicatorChart.ChartAreas[0].AxisY.Minimum = -100; williamsRIndicatorChart.ChartAreas[0].AxisY.Maximum = 0; williamsRCloseChart.Invalidate(); williamsRIndicatorChart.Invalidate(); williamsRResultPanel.BringToFront(); }
private static void ExportFeaturesAndLabel(string code) { string filePath = (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX) ? Environment.GetEnvironmentVariable("HOME") : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"); filePath += "\\indicatorOutput.txt"; DateTime targetDate = IndicatorService.LastDate(code); int numberOfData = 4000; var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1); double[] sma = MovingAverage.Simple(code, targetDate, 14, numberOfData); double[] wma = MovingAverage.Weighted(code, targetDate, 14, numberOfData); double[] ema = MovingAverage.Exponential(code, targetDate, 14, numberOfData); MovingAverageConvergenceDivergence macd = new MovingAverageConvergenceDivergence(code, targetDate, 12, 26, 9, numberOfData); double[] rsi = RelativeStrengthIndex.Rsi(code, targetDate, 14, numberOfData); double[] williams = WilliamsR.Wsr(code, targetDate, 14, numberOfData); Stochastics stochastics = new Stochastics(code, targetDate, 14, 3, 3, numberOfData); double[] closesOut = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data); double[] smaOut = IndicatorDataPreprocessor.GetSMAOut(sma); double[] wmaOut = IndicatorDataPreprocessor.GetWMAOut(wma); double[] emaOut = IndicatorDataPreprocessor.GetEMAOut(ema); double[] macdOut = IndicatorDataPreprocessor.GetMACDOut(macd); double[] rsiOut = IndicatorDataPreprocessor.GetRSIOut(rsi); double[] williamsROut = IndicatorDataPreprocessor.GetWilliamsROut(williams); double[] stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(stochastics); int minRowCount; minRowCount = smaOut.Length; minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length; minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length; minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length; minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length; minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length; minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length; minRowCount = minRowCount < closesOut.Length ? minRowCount : closesOut.Length; FeatureVector vector = new FeatureVector(); vector.AddColumn("SMA", smaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("WMA", wmaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("EMA", emaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("MACD", macdOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("RSI", rsiOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("WilliamsR", williamsROut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("Stochastics", stochasticsOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("label", closesOut.Select(p => (object)string.Format("{0:0.0}", p).ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); new CSVExporter(vector).Export(filePath); Console.WriteLine("Operations completed."); }
/// <summary> /// Called on every new bar of data. /// </summary> /// <param name="currentBar">The current bar of the simulation</param> protected override void OnBarUpdate(int currentBar) { base.OnBarUpdate(currentBar); WilliamsR ind = (WilliamsR)Dependents[0]; if (DataSeries.IsAboutToCrossBelow(ind.Value, -20, currentBar) == true) { WasFound[currentBar] = true; } }
/// <summary> /// Called on every new bar of data. /// </summary> /// <param name="currentBar">The current bar of the simulation</param> protected override void OnBarUpdate(int currentBar) { base.OnBarUpdate(currentBar); WilliamsR ind = (WilliamsR)Dependents[0]; if (DataSeries.CrossAbove(ind.Value, -80, currentBar, 0) != -1) { WasFound[currentBar] = true; } }
public ReversalGenesis(int n) : base(n) { T3 = new AdaptiveSmoothing(n); T32 = new AdaptiveSmoothing(5 * n); CCI = new CCI(n); WILLR = new WilliamsR(n); Gann = new GannHiLo(n); KST = new KST(); CH = new Chaikin(); BB = new BollingerBands(n); UO = new UltimateOscillator(n, 2 * n, 3 * n); }
public Genesis(int n) : base(n) { T3 = new AdaptiveSmoothing(n); T32 = new AdaptiveSmoothing(5 * n); CCI = new CCI(n); WILLR = new WilliamsR(n); Gann = new GannHiLo(n); KST = new KST(); CH = new Chaikin(); BB = new BollingerBands(); QChannel = new QSPolyChannel(); FI = new ForceIndex(30); PFE = new PFE(150); RWI = new RWI(30); AC = new AC(10); }
/// <summary> /// If the runnable has already been created, returns that object. If not then /// returns an new runnable object based on the name and the instrument. /// </summary> /// <param name="nameAndParameters">Name of the runnable</param> /// <returns>The runnable object</returns> public Runnable GetRunnable(string nameAndParameters) { Runnable requestedItem = null; // The name can have parameters to pass to the runnable construtor // and are separated by commas. // Ex: Rsi,11,3 would create the Rsi and pass the numbers to it in a // list. Its up to the indicator to do what it will with each number. string[] splitParams = nameAndParameters.Split(','); string runnableName = splitParams[0]; string[] runnableParams = splitParams.Skip(1).Take(splitParams.Length - 1).ToArray(); // See if the runnable is created already and return that object if it is. int key = nameAndParameters.GetHashCode(); if (_createdItems.ContainsKey(key)) { requestedItem = _createdItems[key]; } else { switch (runnableName) { // Indicators. case "Bollinger": requestedItem = new Bollinger(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BressertDss": requestedItem = new BressertDss(_tickerData, this, runnableParams); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BressertTimingBands": requestedItem = new BressertTimingBands(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BearBeltHold": requestedItem = new BearBeltHold(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BearEngulfing": requestedItem = new BearEngulfing(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BearHarami": requestedItem = new BearHarami(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BearHaramiCross": requestedItem = new BearHaramiCross(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BullBeltHold": requestedItem = new BullBeltHold(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BullEngulfing": requestedItem = new BullEngulfing(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BullHarami": requestedItem = new BullHarami(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BullHaramiCross": requestedItem = new BullHaramiCross(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Cci14": requestedItem = new Cci(_tickerData, this, 14); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "DarkCloudCover": requestedItem = new DarkCloudCover(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Doji": requestedItem = new Doji(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "BearDoji": requestedItem = new BearDoji(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "DownsideTasukiGap": requestedItem = new DownsideTasukiGap(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "EaseOfMovement": requestedItem = new EaseOfMovement(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "EveningStar": requestedItem = new EveningStar(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "FallingThreeMethods": requestedItem = new FallingThreeMethods(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Hammer": requestedItem = new Hammer(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "HangingMan": requestedItem = new HangingMan(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "InvertedHammer": requestedItem = new InvertedHammer(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "KeltnerChannel": requestedItem = new KeltnerChannel(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Macd": requestedItem = new Macd(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Momentum14": requestedItem = new Momentum(_tickerData, this, 14); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "MorningStar": requestedItem = new MorningStar(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "PiercingLine": requestedItem = new PiercingLine(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "PriceOscillator": requestedItem = new PriceOscillator(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "RisingThreeMethods": requestedItem = new RisingThreeMethods(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Rsi": requestedItem = new Rsi(_tickerData, this, runnableParams); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Rsi3m3": requestedItem = new Rsi3m3(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "ShootingStar": requestedItem = new ShootingStar(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Sma": requestedItem = new Sma(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "StickSandwitch": requestedItem = new StickSandwitch(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "StochasticsFast": requestedItem = new StochasticsFast(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Stochastics": requestedItem = new Stochastics(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "StochRsi": requestedItem = new StochRsi(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Trend": requestedItem = new Trend(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "ThreeBlackCrows": requestedItem = new ThreeBlackCrows(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "ThreeWhiteSoldiers": requestedItem = new ThreeWhiteSoldiers(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Trix": requestedItem = new Trix(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "UpsideGapTwoCrows": requestedItem = new UpsideGapTwoCrows(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "UpsideTasukiGap": requestedItem = new UpsideTasukiGap(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "WilliamsR": requestedItem = new WilliamsR(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "Dmi": requestedItem = new Dmi(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "DtOscillator": requestedItem = new DtOscillator(_tickerData, this, runnableParams); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "FibonacciZones": requestedItem = new FibonacciZones(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "ElliotWaves": requestedItem = new ElliotWaves(_tickerData, this); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; case "ZigZag": requestedItem = new ZigZag(_tickerData, this, runnableParams); Simulator.DataOutput.SaveIndicator((Indicator)requestedItem); break; ///////////////////////////// Strategies //////////////////////////// case "BestOfRootStrategies": requestedItem = new BestOfRootStrategies(_tickerData, this); break; case "ComboStrategy": requestedItem = new ComboStrategy(_tickerData, this); break; case "BressertApproach": requestedItem = new BressertApproach(_tickerData, this); break; case "BressertComboStrategy": requestedItem = new BressertComboStrategy(_tickerData, this); break; case "FibonacciRsi3m3": requestedItem = new FibonacciRsi3m3(_tickerData, this); break; case "FibonacciDtOscillator": requestedItem = new FibonacciDtOscillator(_tickerData, this); break; case "ElliotWavesStrategy": requestedItem = new ElliotWavesStrategy(_tickerData, this); break; // // Bull // case "BullBollingerExtended": requestedItem = new BullBollingerExtended(_tickerData, this); break; case "BullBeltHoldFound": requestedItem = new BullBeltHoldFound(_tickerData, this); break; case "BullEngulfingFound": requestedItem = new BullEngulfingFound(_tickerData, this); break; case "BullHaramiFound": requestedItem = new BullHaramiFound(_tickerData, this); break; case "BullHaramiCrossFound": requestedItem = new BullHaramiCrossFound(_tickerData, this); break; case "BullCciCrossover": requestedItem = new BullCciCrossover(_tickerData, this); break; case "BullEaseOfMovement": requestedItem = new BullEaseOfMovement(_tickerData, this); break; case "BullDojiFound": requestedItem = new BullDojiFound(_tickerData, this); break; case "HammerFound": requestedItem = new HammerFound(_tickerData, this); break; case "BullKeltnerExtended": requestedItem = new BullKeltnerExtended(_tickerData, this); break; case "BullMacdCrossover": requestedItem = new BullMacdCrossover(_tickerData, this); break; case "BullMacdMomentum": requestedItem = new BullMacdMomentum(_tickerData, this); break; case "BullMomentumCrossover": requestedItem = new BullMomentumCrossover(_tickerData, this); break; case "MorningStarFound": requestedItem = new MorningStarFound(_tickerData, this); break; case "PiercingLineFound": requestedItem = new PiercingLineFound(_tickerData, this); break; case "RisingThreeMethodsFound": requestedItem = new RisingThreeMethodsFound(_tickerData, this); break; case "BullRsiCrossover": requestedItem = new BullRsiCrossover(_tickerData, this); break; case "BullSmaCrossover": requestedItem = new BullSmaCrossover(_tickerData, this); break; case "StickSandwitchFound": requestedItem = new StickSandwitchFound(_tickerData, this); break; case "BullStochasticsFastCrossover": requestedItem = new BullStochasticsFastCrossover(_tickerData, this); break; case "BullStochasticsCrossover": requestedItem = new BullStochasticsCrossover(_tickerData, this); break; case "BullStochRsiCrossover": requestedItem = new BullStochRsiCrossover(_tickerData, this); break; case "ThreeWhiteSoldiersFound": requestedItem = new ThreeWhiteSoldiersFound(_tickerData, this); break; case "BullTrendStart": requestedItem = new BullTrendStart(_tickerData, this); break; case "BullTrixSignalCrossover": requestedItem = new BullTrixSignalCrossover(_tickerData, this); break; case "BullTrixZeroCrossover": requestedItem = new BullTrixZeroCrossover(_tickerData, this); break; case "UpsideTasukiGapFound": requestedItem = new UpsideTasukiGapFound(_tickerData, this); break; case "BullWilliamsRCrossover": requestedItem = new BullWilliamsRCrossover(_tickerData, this); break; case "BullPriceOscillator": requestedItem = new BullPriceOscillator(_tickerData, this); break; case "BullDmi": requestedItem = new BullDmi(_tickerData, this); break; case "BullBressertDss": requestedItem = new BullBressertDss(_tickerData, this, runnableParams); break; case "BullRsi3m3": requestedItem = new BullRsi3m3(_tickerData, this); break; case "BullDtOscillator": requestedItem = new BullDtOscillator(_tickerData, this); break; //////////// Predicted bull strategies /////////// case "BullCciCrossoverPredicted": requestedItem = new BullCciCrossoverPredicted(_tickerData, this); break; case "BullDmiPredicted": requestedItem = new BullDmiPredicted(_tickerData, this); break; case "BullEaseOfMovementPredicted": requestedItem = new BullEaseOfMovementPredicted(_tickerData, this); break; case "BullKeltnerExtendedPredicted": requestedItem = new BullKeltnerExtendedPredicted(_tickerData, this); break; case "BullMacdCrossoverPredicted": requestedItem = new BullMacdCrossoverPredicted(_tickerData, this); break; case "BullMomentumCrossoverPredicted": requestedItem = new BullMomentumCrossoverPredicted(_tickerData, this); break; case "BullPriceOscillatorPredicted": requestedItem = new BullPriceOscillatorPredicted(_tickerData, this); break; case "BullRsiCrossoverPredicted": requestedItem = new BullRsiCrossoverPredicted(_tickerData, this); break; case "BullSmaCrossoverPredicted": requestedItem = new BullSmaCrossoverPredicted(_tickerData, this); break; case "BullStochasticsCrossoverPredicted": requestedItem = new BullStochasticsCrossoverPredicted(_tickerData, this); break; case "BullStochasticsFastCrossoverPredicted": requestedItem = new BullStochasticsFastCrossoverPredicted(_tickerData, this); break; case "BullStochRsiCrossoverPredicted": requestedItem = new BullStochRsiCrossoverPredicted(_tickerData, this); break; case "BullTrixSignalCrossoverPredicted": requestedItem = new BullTrixSignalCrossoverPredicted(_tickerData, this); break; case "BullTrixZeroCrossoverPredicted": requestedItem = new BullTrixZeroCrossoverPredicted(_tickerData, this); break; case "BullWilliamsRCrossoverPredicted": requestedItem = new BullWilliamsRCrossoverPredicted(_tickerData, this); break; // // Bear // case "BearBollingerExtended": requestedItem = new BearBollingerExtended(_tickerData, this); break; case "BearCciCrossover": requestedItem = new BearCciCrossover(_tickerData, this); break; case "BearEaseOfMovement": requestedItem = new BearEaseOfMovement(_tickerData, this); break; case "BearDojiFound": requestedItem = new BearDojiFound(_tickerData, this); break; case "BearKeltnerExtended": requestedItem = new BearKeltnerExtended(_tickerData, this); break; case "BearMacdMomentum": requestedItem = new BearMacdMomentum(_tickerData, this); break; case "BearMacdCrossover": requestedItem = new BearMacdCrossover(_tickerData, this); break; case "BearMomentumCrossover": requestedItem = new BearMomentumCrossover(_tickerData, this); break; case "BearRsiCrossover": requestedItem = new BearRsiCrossover(_tickerData, this); break; case "BearSmaCrossover": requestedItem = new BearSmaCrossover(_tickerData, this); break; case "BearStochasticsCrossover": requestedItem = new BearStochasticsCrossover(_tickerData, this); break; case "BearStochasticsFastCrossover": requestedItem = new BearStochasticsFastCrossover(_tickerData, this); break; case "BearStochRsiCrossover": requestedItem = new BearStochRsiCrossover(_tickerData, this); break; case "BearTrendStart": requestedItem = new BearTrendStart(_tickerData, this); break; case "BearTrixSignalCrossover": requestedItem = new BearTrixSignalCrossover(_tickerData, this); break; case "BearTrixZeroCrossover": requestedItem = new BearTrixZeroCrossover(_tickerData, this); break; case "BearWilliamsRCrossover": requestedItem = new BearWilliamsRCrossover(_tickerData, this); break; case "BearBeltHoldFound": requestedItem = new BearBeltHoldFound(_tickerData, this); break; case "BearEngulfingFound": requestedItem = new BearEngulfingFound(_tickerData, this); break; case "BearHaramiFound": requestedItem = new BearHaramiFound(_tickerData, this); break; case "BearHaramiCrossFound": requestedItem = new BearHaramiCrossFound(_tickerData, this); break; case "DarkCloudCoverFound": requestedItem = new DarkCloudCoverFound(_tickerData, this); break; case "DownsideTasukiGapFound": requestedItem = new DownsideTasukiGapFound(_tickerData, this); break; case "EveningStarFound": requestedItem = new EveningStarFound(_tickerData, this); break; case "FallingThreeMethodsFound": requestedItem = new FallingThreeMethodsFound(_tickerData, this); break; case "HangingManFound": requestedItem = new HangingManFound(_tickerData, this); break; case "InvertedHammerFound": requestedItem = new InvertedHammerFound(_tickerData, this); break; case "ShootingStarFound": requestedItem = new ShootingStarFound(_tickerData, this); break; case "ThreeBlackCrowsFound": requestedItem = new ThreeBlackCrowsFound(_tickerData, this); break; case "UpsideGapTwoCrowsFound": requestedItem = new UpsideGapTwoCrowsFound(_tickerData, this); break; case "BearPriceOscillator": requestedItem = new BearPriceOscillator(_tickerData, this); break; case "BearDmi": requestedItem = new BearDmi(_tickerData, this); break; case "BearBressertDss": requestedItem = new BearBressertDss(_tickerData, this, runnableParams); break; case "BearRsi3m3": requestedItem = new BearRsi3m3(_tickerData, this); break; case "BearDtOscillator": requestedItem = new BearDtOscillator(_tickerData, this); break; //////////// Predicted bear strategies /////////// case "BearCciCrossoverPredicted": requestedItem = new BearCciCrossoverPredicted(_tickerData, this); break; case "BearDmiPredicted": requestedItem = new BearDmiPredicted(_tickerData, this); break; case "BearEaseOfMovementPredicted": requestedItem = new BearEaseOfMovementPredicted(_tickerData, this); break; case "BearKeltnerExtendedPredicted": requestedItem = new BearKeltnerExtendedPredicted(_tickerData, this); break; case "BearMacdCrossoverPredicted": requestedItem = new BearMacdCrossoverPredicted(_tickerData, this); break; case "BearMomentumCrossoverPredicted": requestedItem = new BearMomentumCrossoverPredicted(_tickerData, this); break; case "BearPriceOscillatorPredicted": requestedItem = new BearPriceOscillatorPredicted(_tickerData, this); break; case "BearRsiCrossoverPredicted": requestedItem = new BearRsiCrossoverPredicted(_tickerData, this); break; case "BearSmaCrossoverPredicted": requestedItem = new BearSmaCrossoverPredicted(_tickerData, this); break; case "BearStochasticsCrossoverPredicted": requestedItem = new BearStochasticsCrossoverPredicted(_tickerData, this); break; case "BearStochasticsFastCrossoverPredicted": requestedItem = new BearStochasticsFastCrossoverPredicted(_tickerData, this); break; case "BearStochRsiCrossoverPredicted": requestedItem = new BearStochRsiCrossoverPredicted(_tickerData, this); break; case "BearTrixSignalCrossoverPredicted": requestedItem = new BearTrixSignalCrossoverPredicted(_tickerData, this); break; case "BearTrixZeroCrossoverPredicted": requestedItem = new BearTrixZeroCrossoverPredicted(_tickerData, this); break; case "BearWilliamsRCrossoverPredicted": requestedItem = new BearWilliamsRCrossoverPredicted(_tickerData, this); break; default: throw new Exception(nameAndParameters + " doesn't exist"); } _createdItems[key] = requestedItem; } return(requestedItem); }
private void PreprocessIndicators() { var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1); double[] sma = null; double[] wma = null; double[] ema = null; MovingAverageConvergenceDivergence macd = null; double[] rsi = null; double[] williamsR = null; Stochastics stochastics = null; if (isSMA) { sma = MovingAverage.Simple(code, targetDate, 14, numberOfData); } if (isWMA) { wma = MovingAverage.Weighted(code, targetDate, 14, numberOfData); } if (isEMA) { ema = MovingAverage.Exponential(code, targetDate, 14, numberOfData); } if (isMACD) { macd = new MovingAverageConvergenceDivergence(code, targetDate, 12, 26, 9, numberOfData); } if (isRSI) { rsi = RelativeStrengthIndex.Rsi(code, targetDate, 14, numberOfData); } if (isWilliamsR) { williamsR = WilliamsR.Wsr(code, targetDate, 14, numberOfData); } if (isStochastics) { stochastics = new Stochastics(code, targetDate, 14, 3, 3, numberOfData); } double[] closesOut = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data); double[] smaOut = null; double[] wmaOut = null; double[] emaOut = null; double[] macdOut = null; double[] rsiOut = null; double[] williamsROut = null; double[] stochasticsOut = null; if (isSMA) { smaOut = IndicatorDataPreprocessor.GetSMAOut(sma); } if (isWMA) { wmaOut = IndicatorDataPreprocessor.GetWMAOut(wma); } if (isEMA) { emaOut = IndicatorDataPreprocessor.GetEMAOut(ema); } if (isMACD) { macdOut = IndicatorDataPreprocessor.GetMACDOut(macd); } if (isRSI) { rsiOut = IndicatorDataPreprocessor.GetRSIOut(rsi, false); } if (isWilliamsR) { williamsROut = IndicatorDataPreprocessor.GetWilliamsROut(williamsR, false); } if (isStochastics) { stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(stochastics, false); } minRowCount = closesOut.Length; if (isSMA) { minRowCount = minRowCount < smaOut.Length ? minRowCount : smaOut.Length; } if (isWMA) { minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length; } if (isEMA) { minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length; } if (isMACD) { minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length; } if (isRSI) { minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length; } if (isWilliamsR) { minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length; } if (isStochastics) { minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length; } FeatureVector featureVector = new FeatureVector(); if (isSMA) { featureVector.AddColumn("SMA", smaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isWMA) { featureVector.AddColumn("WMA", wmaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isEMA) { featureVector.AddColumn("EMA", emaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isMACD) { featureVector.AddColumn("MACD", macdOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isRSI) { featureVector.AddColumn("RSI", rsiOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isWilliamsR) { featureVector.AddColumn("WilliamsR", williamsROut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isStochastics) { featureVector.AddColumn("Stochastics", stochasticsOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } featureVector.AddColumn("label", closesOut.Select(p => (object)string.Format("{0:0.0}", p).ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); int count = featureVector.Values[0].Length; training = new FeatureVector(); test = new FeatureVector(); for (int i = 0; i < featureVector.ColumnName.Count; i++) { training.AddColumn(featureVector.ColumnName[i], featureVector.Values[i].Take((int)(count * trainingPercentage / 100.0)).ToArray()); test.AddColumn(featureVector.ColumnName[i], featureVector.Values[i].Skip((int)(count * trainingPercentage / 100.0)).Take(count).ToArray()); // Take(count) means take the rest of all elements, number of the rest of the elements is smaller than count. } }
protected override void Execute() { SMA sma10 = SMA.Series(Close, 10); EMA ema30 = EMA.Series(Close, 30, EMACalculation.Modern); WilliamsR wlm = WilliamsR.Series(Bars, 3); BBandLower LB = BBandLower.Series(Close, 29, 2.5); BBandUpper UB = BBandUpper.Series(Close, 29, 2.5); SolidBrush shadowBrush = new SolidBrush(Color.FromArgb(10, Color.FromArgb(102, 0, 0, 255))); PlotSeriesFillBand(PricePane, LB, UB, Color.FromArgb(255, 176, 196, 222), shadowBrush, LineStyle.Solid, 2); DateTime nextReportDate = new DateTime(2010, 1, 1); FundamentalItem fi = GetFundamentalItem(Bars.Count - 1, Bars.Symbol, "earnings per share"); bool crossOver = false; bool pullback = false; bool crossUnder = false; bool pullup = false; for (int bar = 30; bar < Bars.Count; bar++) { SetContext("SPY", true); bool signal = sma10[bar] > ema30[bar]; bool goLong = false; bool goShort = false; if (signal && wlm[bar] < 20) { goLong = true; } if (!signal && wlm[bar] > 80) { crossOver = false; goShort = true; } RestoreContext(); //goLong = true; if (!IsLastPositionActive) { if (goLong) { if (CrossOver(bar, sma10, ema30)) { crossOver = true; pullback = false; crossUnder = false; pullup = false; continue; } if (crossOver && Close[bar] < sma10[bar] && pullback == false) { pullback = true; } if (pullback && Close[bar] > sma10[bar]) { // DrawCircle( PricePane, 10, bar, High[bar], Color.Green, Color.DarkGreen, WealthLab.LineStyle.Solid, 2, true ); // crossOver = false; pullback = false; BuyAtMarket(bar + 1, "SMA 10 is above EMA 30 and pull back is done "); } } else if (goShort) { if (CrossUnder(bar, sma10, ema30)) { crossUnder = true; pullup = false; crossOver = false; pullback = false; continue; } if (crossUnder && Close[bar] > sma10[bar] && pullup == false) { pullup = true; } if (pullup && Close[bar] < sma10[bar]) { // DrawCircle( PricePane, 10, bar, High[bar], Color.Green, Color.DarkGreen, WealthLab.LineStyle.Solid, 2, true ); // crossOver = false; pullup = false; ShortAtMarket(bar + 1, "SMA 10 is below EMA 30 and pull back is done "); } // DrawCircle( PricePane, 10, bar, High[bar], Color.Blue, Color.Black, WealthLab.LineStyle.Solid, 2, true ); } } else { if (LastActivePosition.PositionType == PositionType.Long) { double b = LB[bar]; if ( LastActivePosition.EntryPrice > Close[bar] && Close[bar] < b && bar >= LastActivePosition.EntryBar ) { SellAtMarket(bar + 1, LastActivePosition, "stop lose"); crossOver = false; pullback = false; continue; } if (Bars.IntradayBarNumber(bar) == 0 && EarningsDate.InWindow(this, bar, "earnings per share", 365, 0)) { //DrawLabel(PricePane, "Next Earnings: " + Date[bar].ToString()); PrintDebug(Date[bar].ToString()); } if (Date[bar].Day > (LastActivePosition.EntryDate.Day + 4) && Bars.IsLastBarOfDay(bar)) { SellAtMarket(bar + 1, LastActivePosition, "Close on 5th day"); crossOver = false; pullback = false; continue; } else if (CrossUnder(bar, sma10, ema30)) { SellAtMarket(bar + 1, LastActivePosition, "Take profit"); crossOver = false; pullback = false; continue; } } else if (LastActivePosition.PositionType == PositionType.Short) { double b = UB[bar]; if ( LastActivePosition.EntryPrice < Close[bar] && Close[bar] > b && bar >= LastActivePosition.EntryBar ) { CoverAtMarket(bar + 1, LastActivePosition, "Short stop lose"); crossUnder = false; pullup = false; continue; } if (Date[bar].Day > (LastActivePosition.EntryDate.Day + 4) && Bars.IsLastBarOfDay(bar)) { CoverAtMarket(bar + 1, LastActivePosition, "Close on 5th day"); crossUnder = false; pullup = false; continue; } else if (CrossOver(bar, sma10, ema30)) { CoverAtMarket(bar + 1, LastActivePosition, "Take profit"); crossUnder = false; pullup = false; continue; } } } } //Pushed indicator ChartPane statements ChartPane paneWilliamsR1 = CreatePane(40, true, true); //Pushed indicator PlotSeries statements PlotSeries(PricePane, sma10, Color.DarkGreen, LineStyle.Solid, 2); PlotSeries(PricePane, ema30, Color.Blue, LineStyle.Solid, 2); PlotSeries(paneWilliamsR1, wlm, Color.OliveDrab, LineStyle.Solid, 2); }
private void buttonForDataSplitNext_Click(object sender, EventArgs e) { trainingSetPercentage = (double)numericUpDownForTrainingSetPercent.Value / 100.0; numFolds = (int)numericUpDownForNumFolds.Value; double[] smaOut = null; double[] wmaOut = null; double[] emaOut = null; double[] macdOut = null; double[] stochasticsOut = null; double[] williamsROut = null; double[] rsiOut = null; double[] closesOut = null; var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1); if (isSMAChecked) { smaOut = IndicatorDataPreprocessor.GetSMAOut(MovingAverage.Simple(code, targetDate, smaPeriod, numberOfData)); } if (isWMAChecked) { wmaOut = IndicatorDataPreprocessor.GetWMAOut(MovingAverage.Weighted(code, targetDate, wmaPeriod, numberOfData)); } if (isEMAChecked) { emaOut = IndicatorDataPreprocessor.GetEMAOut(MovingAverage.Exponential(code, targetDate, emaPeriod, numberOfData)); } if (isMACDChecked) { macdOut = IndicatorDataPreprocessor.GetMACDOut(new MovingAverageConvergenceDivergence(code, targetDate, firstPeriod, secondPeriod, triggerPeriod, numberOfData)); } if (isStochasticsChecked) { stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(new Stochastics(code, targetDate, fastKPeriod, fastDPeriod, slowDPeriod, numberOfData)); } if (isWilliamsRChecked) { williamsROut = IndicatorDataPreprocessor.GetWilliamsROut(WilliamsR.Wsr(code, targetDate, williamsRPeriod, numberOfData)); } if (isRSIChecked) { rsiOut = IndicatorDataPreprocessor.GetRSIOut(RelativeStrengthIndex.Rsi(code, targetDate, rsiPeriod, numberOfData)); } closesOut = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data); int minRowCount = 1000000; if (smaOut != null) { minRowCount = smaOut.Length; } if (wmaOut != null) { minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length; } if (emaOut != null) { minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length; } if (macdOut != null) { minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length; } if (rsiOut != null) { minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length; } if (williamsROut != null) { minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length; } if (stochasticsOut != null) { minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length; } if (closesOut != null) { minRowCount = minRowCount < closesOut.Length ? minRowCount : closesOut.Length; } var fv = new FeatureVector(); if (isSMAChecked) { fv.AddColumn("SMA", smaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isWMAChecked) { fv.AddColumn("WMA", wmaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isEMAChecked) { fv.AddColumn("EMA", emaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isMACDChecked) { fv.AddColumn("MACD", macdOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isRSIChecked) { fv.AddColumn("RSI", rsiOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isWilliamsRChecked) { fv.AddColumn("WilliamsR", williamsROut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } if (isStochasticsChecked) { fv.AddColumn("Stochastics", stochasticsOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); } fv.AddColumn("label", closesOut.Select(p => (object)string.Format("{0:0.0}", p).ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); var training = new FeatureVector(); var test = new FeatureVector(); int count = fv.Values[0].Length; for (int i = 0; i < fv.ColumnName.Count; i++) { training.AddColumn(fv.ColumnName[i], fv.Values[i].Take((int)(count * trainingSetPercentage)).ToArray()); } for (int i = 0; i < fv.ColumnName.Count; i++) { test.AddColumn(fv.ColumnName[i], fv.Values[i].Skip((int)(count * trainingSetPercentage)).Take(count).ToArray()); // Take(count) means take the rest of all elements, number of the rest of the elements is smaller than count. } if (numFolds > 0) { BinaryClassificationEvaluator bce1 = new BinaryClassificationEvaluator(); LinearRegression linearRegression = new LinearRegression(); CrossValidator cvLinReg = new CrossValidator(linearRegression, bce1, numFolds); CrossValidatorModel cvLinRegModel = (CrossValidatorModel)cvLinReg.Fit(training); FeatureVector linRegPredictions = cvLinRegModel.transform(test); bce1.evaluate(linRegPredictions); linRegAcc = bce1.Accuracy; BinaryClassificationEvaluator bce2 = new BinaryClassificationEvaluator(); LogisticRegression logisticRegression = new LogisticRegression(); CrossValidator cvLogReg = new CrossValidator(logisticRegression, bce2, numFolds); CrossValidatorModel cvLogRegModel = (CrossValidatorModel)cvLogReg.Fit(training); FeatureVector logRegPredictions = cvLogRegModel.transform(test); bce2.evaluate(logRegPredictions); logRegAcc = bce2.Accuracy; BinaryClassificationEvaluator bce3 = new BinaryClassificationEvaluator(); NaiveBayes naiveBayes = new NaiveBayes(); CrossValidator cvNaiBay = new CrossValidator(naiveBayes, bce3, numFolds); CrossValidatorModel cvNaiBayModel = (CrossValidatorModel)cvNaiBay.Fit(training); FeatureVector naiBayPredictions = cvNaiBayModel.transform(test); bce3.evaluate(naiBayPredictions); naiBayAcc = bce3.Accuracy; } else { BinaryClassificationEvaluator bce1 = new BinaryClassificationEvaluator(); LinearRegression linearRegression = new LinearRegression(); LinearRegressionModel linearRegressionModel = (LinearRegressionModel)linearRegression.Fit(training); FeatureVector linRegPredictions = linearRegressionModel.transform(test); bce1.evaluate(linRegPredictions); linRegAcc = bce1.Accuracy; BinaryClassificationEvaluator bce2 = new BinaryClassificationEvaluator(); LogisticRegression logicticRegression = new LogisticRegression(); LogisticRegressionModel logisticRegressionModel = (LogisticRegressionModel)logicticRegression.Fit(training); FeatureVector logRegPredictions = logisticRegressionModel.transform(test); bce2.evaluate(logRegPredictions); logRegAcc = bce2.Accuracy; BinaryClassificationEvaluator bce3 = new BinaryClassificationEvaluator(); NaiveBayes naiveBayes = new NaiveBayes(); NaiveBayesModel naiveBayesModel = (NaiveBayesModel)naiveBayes.Fit(training); FeatureVector naiBayPredictions = naiveBayesModel.transform(test); bce3.evaluate(naiBayPredictions); naiBayAcc = bce3.Accuracy; } labelForLinRegAcc.Text = linRegAcc.ToString(); labelForLogRegAcc.Text = logRegAcc.ToString(); labelForNaiBayAcc.Text = naiBayAcc.ToString(); panelForResults.BringToFront(); }
/// <summary> /// Initialize test /// </summary> public TestIndicatorWilliamsR() { DataStream stream = new OHLCBarStream(new ForexSecurity("EURUSD"), BarInterval.FiveMin); _sut = new WilliamsR(Period, stream, stream.DefaultInterval); }
public WilliamsRSeries(C1FlexChart chart, string plotAreaName) : base() { Chart = chart; Chart.BeginUpdate(); AxisY.TitleStyle = new ChartStyle(); AxisY.TitleStyle.FontWeight = Windows.UI.Text.FontWeights.Bold; AxisY.Position = C1.Chart.Position.Right; AxisY.PlotAreaName = plotAreaName; AxisY.Title = "W%R"; AxisY.Labels = false; AxisY.MajorTickMarks = AxisY.MinorTickMarks = C1.Chart.TickMark.None; WilliamsR series = new WilliamsR(); series.ChartType = C1.Chart.Finance.FinancialChartType.Line; series.Style = new ChartStyle(); series.Style.Stroke = new SolidColorBrush(Color.FromArgb(255, 51, 103, 214)); series.Style.Fill = new SolidColorBrush(Color.FromArgb(128, 66, 133, 244)); series.Style.StrokeThickness = 1; series.BindingX = "Date"; series.Binding = "High,Low,Close"; series.AxisY = AxisY; Chart.Series.Add(series); ThresholdSeries overBought = new ThresholdSeries(); overBought.ChartType = C1.Chart.Finance.FinancialChartType.Line; overBought.Style = new ChartStyle(); overBought.Style.Stroke = new SolidColorBrush(ViewModel.IndicatorPalettes.StockGreen); overBought.Style.StrokeThickness = 1; overBought.AxisY = AxisY; Chart.Series.Add(overBought); ThresholdSeries overSold = new ThresholdSeries(); overSold.ChartType = C1.Chart.Finance.FinancialChartType.Line; overSold.Style = new ChartStyle(); overSold.Style.Stroke = new SolidColorBrush(ViewModel.IndicatorPalettes.StockRed); overSold.Style.StrokeThickness = 1; overSold.AxisY = AxisY; Chart.Series.Add(overSold); Utilities.Helper.BindingSettingsParams(chart, series, typeof(WilliamsR), "Williams% R", new Data.PropertyParam[] { new Data.PropertyParam("Period", typeof(int)), new Data.PropertyParam("Style.Stroke", typeof(Brush)), }, () => { this.OnSettingParamsChanged(); } ); Utilities.Helper.BindingSettingsParams(chart, overBought, typeof(ThresholdSeries), "Williams% R", new Data.PropertyParam[] { new Data.PropertyParam("ZonesVisibility", typeof(bool)), new Data.PropertyParam("Threshold", typeof(int), "OverBought"), }, () => { this.OnSettingParamsChanged(); } ); Utilities.Helper.BindingSettingsParams(chart, overSold, typeof(ThresholdSeries), "Williams% R", new Data.PropertyParam[] { new Data.PropertyParam("ZonesVisibility", typeof(bool)), new Data.PropertyParam("Threshold", typeof(int), "OverSold"), }, () => { this.OnSettingParamsChanged(); } ); overBought.OnThesholdChanged += (o, e) => { this.OnSettingParamsChanged(); }; overSold.OnThesholdChanged += (o, e) => { this.OnSettingParamsChanged(); }; //binding series color to axis title. Binding binding = new Binding(); binding.Path = new Windows.UI.Xaml.PropertyPath("Stroke"); binding.Source = series.Style; BindingOperations.SetBinding(AxisY.TitleStyle, ChartStyle.StrokeProperty, binding); Chart.EndUpdate(); this.Series = new FinancialSeries[] { series, overBought, overSold }; }
private static void RunConsoleApplication() { string filePath = (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX) ? Environment.GetEnvironmentVariable("HOME") : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"); filePath += "\\indicatorOutput.txt"; string code = "AKBNK"; DateTime targetDate = new DateTime(2018, 11, 1).ToLocalTime(); int numberOfData = 1000; var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1); double[] sma = MovingAverage.Simple(code, targetDate, 14, numberOfData); double[] wma = MovingAverage.Weighted(code, targetDate, 14, numberOfData); double[] ema = MovingAverage.Exponential(code, targetDate, 14, numberOfData); MovingAverageConvergenceDivergence macd = new MovingAverageConvergenceDivergence(code, targetDate, 12, 26, 9, numberOfData); double[] rsi = RelativeStrengthIndex.Rsi(code, targetDate, 14, numberOfData); double[] williams = WilliamsR.Wsr(code, targetDate, 14, numberOfData); Stochastics stochastics = new Stochastics(code, targetDate, 14, 3, 3, numberOfData); double[] closesOut = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data); double[] smaOut = IndicatorDataPreprocessor.GetSMAOut(sma); double[] wmaOut = IndicatorDataPreprocessor.GetWMAOut(wma); double[] emaOut = IndicatorDataPreprocessor.GetEMAOut(ema); double[] macdOut = IndicatorDataPreprocessor.GetMACDOut(macd); double[] rsiOut = IndicatorDataPreprocessor.GetRSIOut(rsi); double[] williamsROut = IndicatorDataPreprocessor.GetWilliamsROut(williams); double[] stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(stochastics); int minRowCount; minRowCount = smaOut.Length; minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length; minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length; minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length; minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length; minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length; minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length; minRowCount = minRowCount < closesOut.Length ? minRowCount : closesOut.Length; FeatureVector vector = new FeatureVector(); vector.AddColumn("SMA", smaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("WMA", wmaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("EMA", emaOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("MACD", macdOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("RSI", rsiOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("WilliamsR", williamsROut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("Stochastics", stochasticsOut.Select(p => (object)p.ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); vector.AddColumn("label", closesOut.Select(p => (object)string.Format("{0:0.0}", p).ToString(CultureInfo.InvariantCulture)).Take(minRowCount).ToArray()); new LabeledPointExporter(vector).Export(filePath); int count = vector.Values[0].Length; FeatureVector training = new FeatureVector(); for (int i = 0; i < vector.ColumnName.Count; i++) { training.AddColumn(vector.ColumnName[i], vector.Values[i].Take(count / 2).ToArray()); } FeatureVector test = new FeatureVector(); for (int i = 0; i < vector.ColumnName.Count; i++) { test.AddColumn(vector.ColumnName[i], vector.Values[i].Skip(count / 2).Take(count / 2).ToArray()); } //TestNaiveBayes(training, test); //TestNaiveBayesUsingCrossValidation(training, test); //TestLinearRegression(training, test); //TestLinearRegressionUsingCrossValidation(training, test); //TestLogisticRegression(training, test); //TestLogisticRegressionUsingCrossValidation(training, test); }
private static void RunFeatureSelector(int mlAlgorithm, bool isCrossValidationEnabled, double trainingSetPercentage) { string code = "AKBNK"; DateTime targetDate = new DateTime(2018, 11, 1).ToLocalTime(); int numberOfData = 4000; var data = IndicatorService.GetData(code, targetDate, new string[] { "Tarih", "Kapanis" }, numberOfData + 1); double[] sma = MovingAverage.Simple(code, targetDate, 14, numberOfData); double[] wma = MovingAverage.Weighted(code, targetDate, 14, numberOfData); double[] ema = MovingAverage.Exponential(code, targetDate, 14, numberOfData); MovingAverageConvergenceDivergence macd = new MovingAverageConvergenceDivergence(code, targetDate, 12, 26, 9, numberOfData); double[] rsi = RelativeStrengthIndex.Rsi(code, targetDate, 14, numberOfData); double[] williams = WilliamsR.Wsr(code, targetDate, 14, numberOfData); Stochastics stochastics = new Stochastics(code, targetDate, 14, 3, 3, numberOfData); double[] closesOut = IndicatorDataPreprocessor.GetClosesOut(numberOfData, data); double[] smaOut = IndicatorDataPreprocessor.GetSMAOut(sma); double[] wmaOut = IndicatorDataPreprocessor.GetWMAOut(wma); double[] emaOut = IndicatorDataPreprocessor.GetEMAOut(ema); double[] macdOut = IndicatorDataPreprocessor.GetMACDOut(macd); double[] rsiOut = IndicatorDataPreprocessor.GetRSIOut(rsi, false); double[] williamsROut = IndicatorDataPreprocessor.GetWilliamsROut(williams, false); double[] stochasticsOut = IndicatorDataPreprocessor.GetStochasticsOut(stochastics, false); int minRowCount; minRowCount = smaOut.Length; minRowCount = minRowCount < wmaOut.Length ? minRowCount : wmaOut.Length; minRowCount = minRowCount < emaOut.Length ? minRowCount : emaOut.Length; minRowCount = minRowCount < macdOut.Length ? minRowCount : macdOut.Length; minRowCount = minRowCount < rsiOut.Length ? minRowCount : rsiOut.Length; minRowCount = minRowCount < williamsROut.Length ? minRowCount : williamsROut.Length; minRowCount = minRowCount < stochasticsOut.Length ? minRowCount : stochasticsOut.Length; minRowCount = minRowCount < closesOut.Length ? minRowCount : closesOut.Length; int numberOfIndicators = IndicatorService.indicators.Length; int numberOfCombinations = (int)Math.Pow(2, numberOfIndicators) - 1; for (int i = 1; i <= numberOfCombinations; i++) { int tmp = i; List <int> indicators = new List <int>(); for (int j = 0; j < numberOfIndicators; j++) { if ((tmp & 1) == 1) { indicators.Add(IndicatorService.indicators[j]); } tmp >>= 1; } double accuracy = CalculateAccuracy(indicators, mlAlgorithm, isCrossValidationEnabled, minRowCount, trainingSetPercentage, smaOut, wmaOut, emaOut, macdOut, rsiOut, williamsROut, stochasticsOut, closesOut); if (indicators.Contains(IndicatorService.SMA)) { Console.Write("SMA "); } if (indicators.Contains(IndicatorService.WMA)) { Console.Write("WMA "); } if (indicators.Contains(IndicatorService.EMA)) { Console.Write("EMA "); } if (indicators.Contains(IndicatorService.MACD)) { Console.Write("MACD "); } if (indicators.Contains(IndicatorService.RSI)) { Console.Write("RSI "); } if (indicators.Contains(IndicatorService.WilliamsR)) { Console.Write("WilliamsR "); } if (indicators.Contains(IndicatorService.Stochastics)) { Console.Write("Stochastics "); } Console.WriteLine("=>\t" + accuracy); } }