public int getRequiredHistorySize() {
   if (this.function == Function.EMA) {
     Core core = new Core();
     int lookback = core.emaLookback(day);
     return ((lookback + 1) << 2);
   } else if (function == Function.RSI) {
     Core core = new Core();
     int lookback = core.rsiLookback(day);
     return ((lookback + 1) << 2);
   } else if (this.function == Function.MFI) {
     Core core = new Core();
     int lookback = core.mfiLookback(day);
     return ((lookback + 1) << 2);
   } else if (this.function == Function.MACD) {
     Core core = new Core();
     int lookback = core.macdFixLookback(day);
     return ((lookback + 1) << 2);
   } else if (this.function == Function.MACDSignal) {
     Core core = new Core();
     int lookback = core.macdFixLookback(day);
     return ((lookback + 1) << 2);
   } else if (this.function == Function.MACDHist) {
     Core core = new Core();
     int lookback = core.macdFixLookback(day);
     return ((lookback + 1) << 2);
   } else {
     return day;
   }
 }
Пример #2
0
  public static MACD.Result createMACDFix(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.macdFixLookback(period);
    if (allocationSize <= 0) {
      return null;
    }
    final double[] outMACD = new double[allocationSize];
    final double[] outMACDSignal = new double[allocationSize];
    final double[] outMACDHist = new double[allocationSize];
    final MInteger outBegIdx = new MInteger();
    final MInteger outNbElement = new MInteger();
    double[] _values = ArrayUtils.toPrimitive(values.toArray(new Double[0]));

    core.macdFix(
        0,
        values.size() - 1,
        _values,
        period,
        outBegIdx,
        outNbElement,
        outMACD,
        outMACDSignal,
        outMACDHist);

    return MACD.Result.newInstance(
        outMACD[outNbElement.value - 1],
        outMACDSignal[outNbElement.value - 1],
        outMACDHist[outNbElement.value - 1]);
  }