예제 #1
0
        public double[] Calculate(double[] forecast, double[] price)
        {
            var days = _pastDays.Where(c => c.Value).Select(c => (double)c.Stats).ToArray();

            if ((double)days.Count(c => c > 0) / days.Count() < 0.8)
            {
                return(null);
            }
            var result = HoltsCalculation.Calculate(Math.Min(_futureDays.Where(c => c).Count(), 90), days);
            int m      = 0;

            //double dif = 0;
            for (var i = 0; i < _futureDays.Count() && i < 90; ++i)
            {
                if (_futureDays[i])
                {
                    forecast[i] = result[m];
                    price[i]    = _priceTemp;//+ dif;
                    //dif = forecast[i] - (int)forecast[i];
                    //forecast[i] = (int)forecast[i];
                    m++;
                }
            }
            _price    = price;
            _forecast = forecast;
            return(_price);
        }
예제 #2
0
        private void CalculatePlanedInflation(DateTime start)
        {
            //calculate Inflation for planning period with Holts method

            if (_inflationCoefs.Any())
            {
                var array = _inflationCoefs.Where(c => c.Date < start && c.Date >= start.AddMonths(-12)).OrderBy(c => c.Date).Select(c => c.Coef).ToArray();
                if (array.Any())
                {
                    double[] newCoefs = HoltsCalculation.Calculate(12, array);

                    foreach (var coef in newCoefs)
                    {
                        _inflationCoefs.Add(new InflationCoef {
                            Date = start, Coef = coef
                        });
                        start = start.AddMonths(1);
                    }
                }
            }
        }