public static Double createEMA(java.util.List<Double> values, int period) {
   if (period <= 0) {
     throw new IllegalArgumentException("period must be greater than 0");
   }
   final int size = values.size();
   final Core core = new Core();
   final int allocationSize = size - core.emaLookback(period);
   if (allocationSize <= 0) {
     return null;
   }
   final double[] output = new double[allocationSize];
   final MInteger outBegIdx = new MInteger();
   final MInteger outNbElement = new MInteger();
   double[] _values = ArrayUtils.toPrimitive(values.toArray(new Double[0]));
   core.ema(0, values.size() - 1, _values, period, outBegIdx, outNbElement, output);
   return output[outNbElement.value - 1];
 }
Exemple #2
0
  public static double[] computeMA(double[] input, int period, int maType) {
    MInteger begin = new MInteger();
    MInteger length = new MInteger();
    double[] out = new double[input.length - period + 1];

    switch (maType) {
      case MA_TYPE_SMA:
        core.sma(0, input.length - 1, input, period, begin, length, out);
        break;
      case MA_TYPE_EMA:
        core.ema(0, input.length - 1, input, period, begin, length, out);
        break;
      case MA_TYPE_WMA:
        core.wma(0, input.length - 1, input, period, begin, length, out);
        break;
      default:
        throw new RuntimeException("unsupported MaType " + maType);
    }

    return out;
  }