Esempio n. 1
0
        public static DataArray <double> BollingerBandTop(StockSeriesData data, int periods, MovingAverageMethod method, double stddev)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data", "Data must not be null.");
            }
            if (periods <= 0)
            {
                throw new ArgumentOutOfRangeException("periods", "Periods must not be negative or zero.");
            }
            if (stddev <= 0.0)
            {
                throw new ArgumentOutOfRangeException("stddev", "Standard deviation must not be negative or zero.");
            }
            DataArray <double> array = null;

            switch (method)
            {
            case MovingAverageMethod.Simple:
                array = SimpleMovingAverage(data, periods);
                break;

            case MovingAverageMethod.Weighted:
                array = WeightedMovingAverage(data, periods);
                break;

            case MovingAverageMethod.Exponential:
                array = ExponentialMovingAverage(data, periods);
                break;
            }
            DataArray <double> array2 = ChartMath.StdDev(data, periods);

            return(ChartMath.Add(array, ChartMath.Multiply(array2, stddev)));
        }
Esempio n. 2
0
 public static DataArray <double> Momentum(DataArray <double> data, int periods)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data", "DataArray<double> must not be null.");
     }
     if (periods <= 0)
     {
         throw new ArgumentOutOfRangeException("periods", "Periods must not be negative or zero.");
     }
     return(ChartMath.Multiply(ChartMath.Divide(data, Reference(data, -periods)), 100.0));
 }
Esempio n. 3
0
        public static DataArray <double> RateOfChange(DataArray <double> data, int periods)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data", "DataArray<double> must not be null.");
            }
            if (periods <= 0)
            {
                throw new ArgumentOutOfRangeException("periods", "Periods must not be negative or zero.");
            }
            DataArray <double> array = Reference(data, -periods);

            return(ChartMath.Multiply(ChartMath.Divide(ChartMath.Subtract(data, array), array), 100.0));
        }
Esempio n. 4
0
 public static DataArray <double> MACD(StockSeriesData data, int shortPeriods, int longPeriods)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data", "DataArray<double> must not be null.");
     }
     if (shortPeriods <= 0)
     {
         throw new ArgumentOutOfRangeException("shortPeriods", "Periods must not be negative or zero.");
     }
     if (longPeriods <= 0)
     {
         throw new ArgumentOutOfRangeException("longPeriods", "Periods must not be negative or zero.");
     }
     return(ChartMath.Subtract(ExponentialMovingAverage(data, shortPeriods), ExponentialMovingAverage(data, longPeriods)));
 }
Esempio n. 5
0
 public static DataArray <double> SimpleMovingAverage(StockSeriesData data, int periods)
 {
     return(ChartMath.Divide(ChartMath.Sum(data, periods), periods));
 }