SMA is the only indicator available so far but you can create your owns pretty easily by implementing IndicatorBase:
public class ExampleIndicator implements IndicatorBase{
@Override
public void add(String symbol, double value) {
// TODO Auto-generated method stub
}
@Override
public double getValue(String symbol) {
// TODO Auto-generated method stub
return 0;
}
}
/**
* SMA Simple Moving Average <br>
* <br>
* <b>History:</b><br>
* - [18/dic/2012] Created. (sfl)<br>
*
* @author sfl
*/
public class SMA implements IndicatorBase{
private int periods = 0;
@SuppressWarnings("rawtypes")
private HashMap<String,RollingWindow> SMA = new HashMap<String, RollingWindow>();
/**
* Constructor
* @param periods
*/
public SMA(int periods){
this.periods = periods;
}
@SuppressWarnings("unchecked")
@Override
public double getValue(String symbol) {
RollingWindow<Double> val = new RollingWindow<Double>(periods);
if (SMA.get(symbol)!=null)
val = SMA.get(symbol);
else
return 0;
double sum = 0;
int size = val.size();
for(int i=0;i<size;i++){
sum += val.get(i);
}
return (sum/size);
}
@SuppressWarnings("unchecked")
@Override
public void add(String symbol,double value) {
if ((value>0)&&(symbol!=null)){
RollingWindow<Double> val = new RollingWindow<Double>(periods);
if (SMA.get(symbol)!=null)
val = SMA.get(symbol);
val.add(value);
SMA.put(symbol, val);
}
}
// test
public static void main(String[] args) {
SMA sma = new SMA(20);
String s = "GS";
for(int i=0;i<1000;i++){
sma.add(s, i);
if (i==100)
System.out.println("Value at 100: "+sma.getValue(s));
if (i==200)
System.out.println("Value at 200: "+sma.getValue(s));
if (i==400)
System.out.println("Value at 400: "+sma.getValue(s));
if (i==650)
System.out.println("Value at 650: "+sma.getValue(s));
if (i==999)
System.out.println("Value at 999: "+sma.getValue(s));
}
}
}
If you are going to implement others indicators please consider to submit them to us. We can include them in an external jar for istance: tbg-quant-indicators.jar or you can publish your work and we can link it.
About using TA-LIB well, ta indicators works with array[] so you need to do some work to get them work. You can write a wrap class around each indicator implementing IndicatorBase like above or you can just use them directly in a strategy. I personally prefer the firsty approach.