Beispiel #1
0
  public EventType periodType(Integer calculationStartIdx, Integer calculationEndIdx)
      throws NotEnoughDataException {

    // Avg previous variations
    double[] quotationCloseValues = sma.getSma();

    double lastVariation =
        periodVariation(
            quotationCloseValues, calculationEndIdx - NOTICABLEPERIODBAND, calculationEndIdx);
    Boolean positiveVariation = lastVariation > 0;

    List<Double> variations = new ArrayList<Double>();
    for (int i = calculationStartIdx + NOTICABLEPERIODBAND; i < calculationEndIdx; i++) {
      double periodVariation = periodVariation(quotationCloseValues, i - NOTICABLEPERIODBAND, i);
      if (periodVariation <= 0 && !positiveVariation) {
        variations.add(periodVariation);
      }
      if (periodVariation > 0 & positiveVariation) {
        variations.add(periodVariation);
      }
    }
    int nbSignedVariations = variations.size();
    if (variations.size() < MINNBVAR) throw new NotEnoughDataException(null, "", null);
    double[] variationsArray = new double[nbSignedVariations];
    for (int i = 0; i < nbSignedVariations; i++) {
      variationsArray[i] = variations.get(i);
    }

    double meanPreviousVariation = mean(0, nbSignedVariations, variationsArray);
    double stdDev = stdDev(variationsArray, 0, nbSignedVariations, meanPreviousVariation);

    // Last variation
    double lastDiffToMean = lastVariation - meanPreviousVariation;

    if (lastDiffToMean < -stdDev && !positiveVariation) {
      return EventType.BEARISH;
    }
    if (stdDev < lastDiffToMean && positiveVariation) {
      return EventType.BULLISH;
    }

    return EventType.NONE;
  }
 @Override
 public Integer getOutputBeginIdx() {
   return Math.max(chaikinOscillator.getOutBegIdx().value, sma.getOutBegIdx().value)
       + getDaysSpan();
 }
 @Override
 public Integer getStartShift() {
   // return Math.max(20, getDaysSpan());
   return Math.max(chaikinOscillator.getStartShift(), sma.getStartShift()) + getDaysSpan();
 }