Ejemplo n.º 1
0
  @Override
  protected double[][] getInputData(Quotations quotations) {
    double[] closeValues = quotations.getCloseValues();
    double inLow[] = quotations.getLowValues();
    double inHigh[] = quotations.getHighValues();

    double[][] ret =
        new double[3][Math.max(Math.max(closeValues.length, inHigh.length), inLow.length)];
    ret[0] = closeValues;
    ret[1] = inLow;
    ret[2] = inHigh;
    return ret;
  }
  @Override
  protected FormulatRes eventFormulaCalculation(QuotationUnit qU, Integer quotationIdx)
      throws InvalidAlgorithmParameterException {

    FormulatRes res = new FormulatRes(getEventDefinition());
    res.setCurrentDate(qU.getDate());

    int chaikinIdx = getIndicatorIndexFromQuotationIndex(this.chaikinOscillator, quotationIdx);
    double[] chaikinLookBackP =
        Arrays.copyOfRange(
            this.chaikinOscillator.getChaikinOsc(), chaikinIdx - getDaysSpan(), chaikinIdx);
    double[] quotationLookBackP =
        Arrays.copyOfRange(
            quotationsCopy.getCloseValues(), quotationIdx - getDaysSpan(), quotationIdx);

    int smaIndex = getIndicatorIndexFromQuotationIndex(this.sma, quotationIdx);
    double[] quotationLookBackPThresh =
        Arrays.copyOfRange(this.sma.getSma(), smaIndex - getDaysSpan(), smaIndex);

    double[] chaikinThreshCurve = new double[chaikinLookBackP.length];

    {
      Boolean isPriceDown = lowerLow(quotationLookBackP, quotationLookBackPThresh);
      Boolean isChaikinUp = higherLow(chaikinLookBackP, chaikinThreshCurve);
      res.setBullishCrossOver(isPriceDown && isChaikinUp);

      if (res.getBullishCrossOver()) return res;
    }
    {
      Boolean isPriceUp = higherHigh(quotationLookBackP, quotationLookBackPThresh);
      Boolean isChaikinDown = lowerHigh(chaikinLookBackP, chaikinThreshCurve);
      res.setBearishCrossBellow(isPriceUp && isChaikinDown);

      return res;
    }
  }