|
From: Carlos <ma...@us...> - 2007-05-17 22:45:37
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/indicator/tracker In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv27199/src/java/net/sf/tail/indicator/tracker Modified Files: WilliamsRIndicator.java Added Files: HighestValueIndicator.java LowestValueIndicator.java Log Message: Refatoracao do Williams R e criado dois indicators (HighestValue e LowestValue), pois eles serao necessarios em varios outros indicadores. Index: WilliamsRIndicator.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/indicator/tracker/WilliamsRIndicator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** WilliamsRIndicator.java 17 May 2007 21:30:54 -0000 1.3 --- WilliamsRIndicator.java 17 May 2007 22:45:34 -0000 1.4 *************** *** 20,54 **** public Double getValue(int index) { ! double highestHighPrice = getHighestHighPrice(index); ! double lowestLowPrice = getLowestLowPrice(index); return ((highestHighPrice - indicator.getValue(index).doubleValue()) / (highestHighPrice - lowestLowPrice)) * -100d; } - - private Double getHighestHighPrice(int index) - { - int start = Math.max(0, index - timeFrame + 1); - Double highest = maxPriceIndicator.getValue(start); - for (int i = start + 1; i <= index; i++) { - if(highest.doubleValue() < maxPriceIndicator.getValue(i).doubleValue()) - highest = maxPriceIndicator.getValue(i); - } - return highest; - } - - /* - * TODO - Pensar em otimização ou maior número de indicadores ? - * - */ - private Double getLowestLowPrice(int index) - { - int start = Math.max(0, index - timeFrame + 1); - Double lowest = minPriceIndicator.getValue(start); - for (int i = start + 1; i <= index; i++) { - if(lowest.doubleValue() > minPriceIndicator.getValue(i).doubleValue()) - lowest = minPriceIndicator.getValue(i); - } - return lowest; - } } --- 20,31 ---- public Double getValue(int index) { ! HighestValueIndicator highestHigh = new HighestValueIndicator(maxPriceIndicator, timeFrame); ! LowestValueIndicator lowestMin = new LowestValueIndicator(minPriceIndicator, timeFrame); ! ! double highestHighPrice = highestHigh.getValue(index); ! double lowestLowPrice = lowestMin.getValue(index); return ((highestHighPrice - indicator.getValue(index).doubleValue()) / (highestHighPrice - lowestLowPrice)) * -100d; } } --- NEW FILE: HighestValueIndicator.java --- package net.sf.tail.indicator.tracker; import net.sf.tail.Indicator; public class HighestValueIndicator implements Indicator<Double> { private final Indicator<? extends Number> indicator; private final int timeFrame; public HighestValueIndicator(Indicator<? extends Number> indicator, int timeFrame) { this.indicator = indicator; this.timeFrame = timeFrame; } public Double getValue(int index) { int start = Math.max(0, index - timeFrame + 1); Double highest = (Double) indicator.getValue(start); for (int i = start + 1; i <= index; i++) { if(highest.doubleValue() < indicator.getValue(i).doubleValue()) highest = (Double) indicator.getValue(i); } return highest; } } --- NEW FILE: LowestValueIndicator.java --- package net.sf.tail.indicator.tracker; import net.sf.tail.Indicator; public class LowestValueIndicator implements Indicator<Double> { private final Indicator<? extends Number> indicator; private final int timeFrame; public LowestValueIndicator(Indicator<? extends Number> indicator, int timeFrame) { this.indicator = indicator; this.timeFrame = timeFrame; } public Double getValue(int index) { int start = Math.max(0, index - timeFrame + 1); Double lowest = (Double) indicator.getValue(start); for (int i = start + 1; i <= index; i++) { if(lowest.doubleValue() > indicator.getValue(i).doubleValue()) lowest = (Double) indicator.getValue(i); } return lowest; } } |