/** * @param toCmp * @param testCondition associated with each decision tree node, int index for features included * in CandleStick 0-time, 1-high bid price, 2-low bid price, 3-close bid price * @return */ public int compareWith(CandleStick toCmp, int testCondition) { if (testCondition == 0) { return this.getTime().compareTo(toCmp.getTime()); } else if (testCondition == 1) { return this.getHigh().compareTo(toCmp.getHigh()); } else if (testCondition == 2) { return this.getLow().compareTo(toCmp.getLow()); } else if (testCondition == 3) { return this.getClose().compareTo(toCmp.getClose()); } else { System.err.println("invalid attribute idx...error"); return 0; } }
public String getFeaturesAndLabel(CandleStick next) { // use StringBuilder other than String concatenation for fast operation StringBuilder sb = new StringBuilder(); sb.append(this.currencyPair + ","); sb.append(this.time + ","); sb.append(this.high + ","); sb.append(this.low + ","); sb.append(this.close + ","); if (next.getClose() > this.close) sb.append(1); else if (next.getClose() < this.close) { sb.append(-1); } else { sb.append(0); } sb.append("\n"); return sb.toString(); }
@Override public int compare(CandleStick o1, CandleStick o2) { // TODO Auto-generated method stub return o1.getClose().compareTo(o2.getClose()); }