|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 16:45:41
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/strategy In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2946/src/java/net/sf/tail/strategy Modified Files: IndicatorCrossedIndicatorStrategy.java ResistanceStrategy.java PipeEnterStrategy.java SupportStrategy.java Log Message: Refatoração de testes Index: SupportStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/SupportStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SupportStrategy.java 24 May 2007 20:10:01 -0000 1.1 --- SupportStrategy.java 31 May 2007 16:45:41 -0000 1.2 *************** *** 15,21 **** public class SupportStrategy implements Strategy { ! private Strategy strategy; ! private Indicator<? extends Number> indicator; private double support; --- 15,21 ---- public class SupportStrategy implements Strategy { ! private final Strategy strategy; ! private final Indicator<? extends Number> indicator; private double support; Index: PipeEnterStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/PipeEnterStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PipeEnterStrategy.java 24 May 2007 21:11:11 -0000 1.1 --- PipeEnterStrategy.java 31 May 2007 16:45:41 -0000 1.2 *************** *** 5,8 **** --- 5,9 ---- import net.sf.tail.OperationType; import net.sf.tail.Strategy; + import net.sf.tail.indicator.helper.CrossIndicator; /** *************** *** 17,25 **** public class PipeEnterStrategy implements Strategy { ! private Indicator<? extends Number> upper; ! private Indicator<? extends Number> lower; ! private Indicator<? extends Number> value; public PipeEnterStrategy(Indicator<? extends Number> upper, Indicator<? extends Number> lower, --- 18,30 ---- public class PipeEnterStrategy implements Strategy { ! private final Indicator<? extends Number> upper; ! private final Indicator<? extends Number> lower; ! private final Indicator<? extends Number> value; ! ! private final Indicator<Boolean> crossUp; ! ! private final Indicator<Boolean> crossDown; public PipeEnterStrategy(Indicator<? extends Number> upper, Indicator<? extends Number> lower, *************** *** 28,37 **** this.lower = lower; this.value = value; } public Operation shouldEnter(int index) { ! if (isCrossed(index, value, upper)) return new Operation(index, OperationType.SELL); ! if (isCrossed(index, lower, value)) return new Operation(index, OperationType.BUY); return null; --- 33,44 ---- this.lower = lower; this.value = value; + crossUp = new CrossIndicator(value,upper); + crossDown = new CrossIndicator(lower,value); } public Operation shouldEnter(int index) { ! if (crossUp.getValue(index)) return new Operation(index, OperationType.SELL); ! if (crossDown.getValue(index)) return new Operation(index, OperationType.BUY); return null; *************** *** 39,69 **** public Operation shouldExit(Operation entry, int index) { ! if (isCrossed(index, lower, value)) return new Operation(index, OperationType.BUY); ! if (isCrossed(index, value, upper)) return new Operation(index, OperationType.SELL); return null; } - private boolean isCrossed(int index, Indicator<? extends Number> up, Indicator<? extends Number> low) { - - if (index == 0 || up.getValue(index).doubleValue() >= (low.getValue(index).doubleValue())) - return false; - index--; - if (up.getValue(index).doubleValue() > low.getValue(index).doubleValue()) - return true; - - else { - - while (index > 0 && up.getValue(index).doubleValue() == low.getValue(index).doubleValue()) - index--; - if (index == 0) - return false; - if (up.getValue(index).doubleValue() > low.getValue(index).doubleValue()) - return true; - return false; - } - } - public Indicator<? extends Number> getLower() { return lower; --- 46,56 ---- public Operation shouldExit(Operation entry, int index) { ! if (crossDown.getValue(index)) return new Operation(index, OperationType.BUY); ! if (crossUp.getValue(index)) return new Operation(index, OperationType.SELL); return null; } public Indicator<? extends Number> getLower() { return lower; Index: ResistanceStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/ResistanceStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ResistanceStrategy.java 24 May 2007 20:10:01 -0000 1.1 --- ResistanceStrategy.java 31 May 2007 16:45:41 -0000 1.2 *************** *** 14,20 **** public class ResistanceStrategy implements Strategy{ ! private Strategy strategy; ! private Indicator<? extends Number> indicator; private double resistance; --- 14,20 ---- public class ResistanceStrategy implements Strategy{ ! private final Strategy strategy; ! private final Indicator<? extends Number> indicator; private double resistance; Index: IndicatorCrossedIndicatorStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/IndicatorCrossedIndicatorStrategy.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IndicatorCrossedIndicatorStrategy.java 24 May 2007 21:11:11 -0000 1.2 --- IndicatorCrossedIndicatorStrategy.java 31 May 2007 16:45:41 -0000 1.3 *************** *** 5,8 **** --- 5,9 ---- import net.sf.tail.OperationType; import net.sf.tail.Strategy; + import net.sf.tail.indicator.helper.CrossIndicator; /** *************** *** 16,30 **** public class IndicatorCrossedIndicatorStrategy implements Strategy { ! private Indicator<? extends Number> upper; - private Indicator<? extends Number> lower; public IndicatorCrossedIndicatorStrategy(Indicator<? extends Number> upper, Indicator<? extends Number> lower) { ! this.upper = upper; ! this.lower = lower; } public Operation shouldEnter(int index) { ! if (isCrossed(index, upper, lower)) return new Operation(index, OperationType.BUY); return null; --- 17,33 ---- public class IndicatorCrossedIndicatorStrategy implements Strategy { ! ! private final Indicator<Boolean> crossUp; ! ! private final Indicator<Boolean> crossDown; public IndicatorCrossedIndicatorStrategy(Indicator<? extends Number> upper, Indicator<? extends Number> lower) { ! crossUp = new CrossIndicator(upper,lower); ! crossDown = new CrossIndicator(lower,upper); } public Operation shouldEnter(int index) { ! if (crossUp.getValue(index)) return new Operation(index, OperationType.BUY); return null; *************** *** 32,58 **** public Operation shouldExit(Operation entry, int index) { ! if (isCrossed(index, lower, upper)) return new Operation(index, OperationType.SELL); return null; } - private boolean isCrossed(int index, Indicator<? extends Number> up, Indicator<? extends Number> low) { - - if (index == 0 || up.getValue(index).doubleValue() >= (low.getValue(index).doubleValue())) - return false; - index--; - if (up.getValue(index).doubleValue() > low.getValue(index).doubleValue()) - return true; - - else { - - while (index > 0 && up.getValue(index).doubleValue() == low.getValue(index).doubleValue()) - index--; - if (index == 0) - return false; - if (up.getValue(index).doubleValue() > low.getValue(index).doubleValue()) - return true; - return false; - } - } } --- 35,42 ---- public Operation shouldExit(Operation entry, int index) { ! if (crossDown.getValue(index)) return new Operation(index, OperationType.SELL); return null; } } |