使用Talib的布林带

时间:2014-02-10 10:38:17

标签: java eclipse finance

我正在尝试使用talib实现一个简单的BBands应用程序。

我对Talib和技术指标没有任何考虑。

有人可以看看是否这是一个使用Talib的布林带的良好实施,并给我建议如何改进。如果有人对Talib和Bollinger Bands有所了解,那么请给我一个帮助。这是代码。

import com.tictactec.ta.lib.Core;
import com.tictactec.ta.lib.MInteger;
import com.tictactec.ta.lib.RetCode;
import com.tictactec.ta.lib.*;
import com.tictactec.ta.lib.meta.helpers.*;

public class ExampleTALib 
{

  /**
   * The total number of periods to generate data for.
   */
  public static final int TOTAL_PERIODS = 100;

  /**
    * The number of periods to average together.
    */
  public static final int PERIODS_AVERAGE = 20;

    public static void main(String[] args) 
    {
      double[] closePrice = new double[TOTAL_PERIODS];
      double[] out = new double[TOTAL_PERIODS];
      MInteger begin = new MInteger();
      MInteger length = new MInteger();

      double[] outRealUpperBand = new double[TOTAL_PERIODS];
      double[] outRealMiddleBand = new double[TOTAL_PERIODS];
      double[] outRealLowerBand = new double[TOTAL_PERIODS];




      for (int i = 0; i < closePrice.length; i++) {
        closePrice[i] = (double) i;
      }

      Core c = new Core();
//      RetCode retCode = c.sma(0, closePrice.length - 1, closePrice, PERIODS_AVERAGE, begin, length, out);
//      RetCode re = c.sma(startIdx, endIdx, inReal, optInTimePeriod, outBegIdx, outNBElement, outReal)
      RetCode retCode = c.bbands(0, closePrice.length - 1, closePrice, PERIODS_AVERAGE,
              1.0, 3.0, MAType.Ema, begin, length, outRealUpperBand, outRealMiddleBand, outRealLowerBand);
//      RetCode re = c.bbands(startIdx, endIdx, inReal, optInTimePeriod, optInNbDevUp, optInNbDevDn, optInMAType, outBegIdx, outNBElement, outRealUpperBand, outRealMiddleBand, outRealLowerBand)


      if (retCode == RetCode.Success) {
        System.out.println("Output Begin:" + begin.value);
        System.out.println("Output Begin:" + length.value);

        for (int i = begin.value; i < closePrice.length; i++) {
            StringBuilder line = new StringBuilder();
            line.append("Period #");
            line.append(i+1);
            line.append(" close= ");
            line.append(closePrice[i]);
            line.append(" mov avg=");
            line.append(out[i-begin.value]);
            System.out.println(line.toString());
            }
    }
    else {
      System.out.println("Error");
    }
  }
}

0 个答案:

没有答案