Ejemplo n.º 1
0
        public OutParameter InitialForecast()
        {
            HistryData histryData;
            float      avg = 0, crntPrice = 0, initialAvg;

            try{
                if ((histryData = rqstController.GetHistoricalData(parameters.Coin, 2000)) != null)
                {
                    if (parameters.Strategy.Equals("SMA"))
                    {
                        avg       = new SMA().GetAverage(histryData.Data.ConvertAll(data => data.close).GetRange(2000 - parameters.Limit - 2, parameters.Limit));
                        crntPrice = this.LiveMarketPrice();
                    }
                    else if (parameters.Strategy.Equals("EMA"))
                    {
                        MovingAverage ma = new EMA();
                        initialAvg = ma.GetAverage(histryData.Data.ConvertAll(data => data.close).GetRange(0, 100));
                        avg        = ma.PredictedPrice(histryData.Data.ConvertAll(data => data.close).GetRange(100, 1900), initialAvg, parameters.Period);
                        crntPrice  = this.LiveMarketPrice();
                    }
                    else if (parameters.Strategy.Equals("EMADC"))
                    {
                        MovingAverage ma = new EMA();
                        initialAvg = ma.GetAverage(histryData.Data.ConvertAll(data => data.close).GetRange(0, 100));
                        avg        = ma.PredictedPrice(histryData.Data.ConvertAll(data => data.close).GetRange(100, 1900), initialAvg, parameters.Period_1);
                        crntPrice  = ma.PredictedPrice(histryData.Data.ConvertAll(data => data.close).GetRange(100, 1900), initialAvg, parameters.Period);
                    }
                    coinUpdate[parameters.Coin] = Builder <OutParameter> .CreateNew().With(x => x.Coin = parameters.Coin)
                                                  .With(x => x.Current  = crntPrice).With(x => x.Predicted = avg)
                                                  .With(x => x.Decision = this.Decision(crntPrice, avg)).Build();

                    return(coinUpdate[parameters.Coin]);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Exiting App...");
                }
            }
            catch (Exception ex) {
                Console.WriteLine("Exception: " + ex);
            }
            return(null);
        }