You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(148) |
Jun
(48) |
Jul
(107) |
Aug
(292) |
Sep
(301) |
Oct
(530) |
Nov
(142) |
Dec
(37) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
|
Feb
|
Mar
(4) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Márcio V. d. S. <mv...@us...> - 2007-06-08 15:14:21
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/analysis/criteria In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv9460/src/test/net/sf/tail/analysis/criteria Log Message: Directory /cvsroot/tail/Tail/src/test/net/sf/tail/analysis/criteria added to the repository |
|
From: Márcio V. d. S. <mv...@us...> - 2007-06-08 15:14:21
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/analysis In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv9460/src/java/net/sf/tail/analysis Log Message: Directory /cvsroot/tail/Tail/src/java/net/sf/tail/analysis added to the repository |
|
From: Márcio V. d. S. <mv...@us...> - 2007-06-08 15:14:21
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/analysis In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv9460/src/test/net/sf/tail/analysis Log Message: Directory /cvsroot/tail/Tail/src/test/net/sf/tail/analysis added to the repository |
|
From: Thies <tg...@us...> - 2007-06-08 15:11:15
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv8205/src/java/net/sf/tail Modified Files: Strategy.java Log Message: Ajustada a interface Strategy e as estrategias, comentando todos shouldEnter e shouldExit Index: Strategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/Strategy.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Strategy.java 6 Jun 2007 19:24:52 -0000 1.3 --- Strategy.java 8 Jun 2007 15:11:16 -0000 1.4 *************** *** 8,31 **** public interface Strategy { /** ! * Retorna uma operação, caso seja necessária, recomendando uma determinação ação. ! * ! * Caso não haja ação recomendada, retorna null. ! * ! * @param index ! * @return ! */ ! Operation shouldEnter(int index); ! ! /** ! * Retorna uma operação, caso seja necessária, recomendando uma determinação ação. ! * ! * Caso não haja ação recomendada, retorna null. * * @param index * @return */ - Operation shouldExit(Operation entry, int index); - public boolean shouldOperate(Trade trade, int index); --- 8,39 ---- public interface Strategy { + // /** + // * Retorna uma operação, caso seja necessária, recomendando uma determinação ação. + // * + // * Caso não haja ação recomendada, retorna null. + // * + // * @param index + // * @return + // */ + // Operation shouldEnter(int index); + // + // /** + // * Retorna uma operação, caso seja necessária, recomendando uma determinação ação. + // * + // * Caso não haja ação recomendada, retorna null. + // * + // * @param index + // * @return + // */ + // Operation shouldExit(Operation entry, int index); + /** ! * Retorna um boolean true, caso avalie necessario, recomendando uma determinada acao. ! * Caso contrario retorna false, nao recomendando nenhuma acao. * + * @param trade * @param index * @return */ public boolean shouldOperate(Trade trade, int index); |
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/strategy In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2977/src/java/net/sf/tail/strategy Modified Files: DistanceBetweenIndicatorsStrategy.java MinValueStarterStrategy.java SupportStrategy.java IndicatorOverIndicatorStrategy.java PipeEnterStrategy.java ResistanceStrategy.java Log Message: Refatoracao das strategys substituindo shoulEnter e shouldExit por shouldOperate, e tambem os testes. Index: PipeEnterStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/PipeEnterStrategy.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PipeEnterStrategy.java 6 Jun 2007 19:24:52 -0000 1.3 --- PipeEnterStrategy.java 8 Jun 2007 14:59:36 -0000 1.4 *************** *** 24,30 **** private final Indicator<? extends Number> value; ! private final Indicator<Boolean> crossUp; ! private final Indicator<Boolean> crossDown; --- 24,30 ---- private final Indicator<? extends Number> value; ! private final Indicator<Boolean> crossUp; ! private final Indicator<Boolean> crossDown; *************** *** 34,39 **** this.lower = lower; this.value = value; ! crossUp = new CrossIndicator(value,upper); ! crossDown = new CrossIndicator(lower,value); } --- 34,39 ---- this.lower = lower; this.value = value; ! crossUp = new CrossIndicator(value, upper); ! crossDown = new CrossIndicator(lower, value); } *************** *** 53,59 **** return null; } ! public boolean shouldOperate(Trade trade, int index) { ! // TODO Auto-generated method stub return false; } --- 53,72 ---- return null; } ! public boolean shouldOperate(Trade trade, int index) { ! if (trade.isNew()) { ! if (crossUp.getValue(index)) ! return trade.exit(index); ! ! if (crossDown.getValue(index)) ! return trade.enter(index); ! } ! else if (trade.isOpened()) { ! if (crossDown.getValue(index)) ! return trade.enter(index); ! ! if (crossUp.getValue(index)) ! return trade.exit(index); ! } return false; } Index: IndicatorOverIndicatorStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/IndicatorOverIndicatorStrategy.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IndicatorOverIndicatorStrategy.java 6 Jun 2007 19:24:52 -0000 1.2 --- IndicatorOverIndicatorStrategy.java 8 Jun 2007 14:59:36 -0000 1.3 *************** *** 9,16 **** public class IndicatorOverIndicatorStrategy implements Strategy { - private Indicator<Double> first; - private Indicator<Double> second; public IndicatorOverIndicatorStrategy(Indicator<Double> first, Indicator<Double> second) { --- 9,15 ---- public class IndicatorOverIndicatorStrategy implements Strategy { private Indicator<Double> first; + private Indicator<Double> second; public IndicatorOverIndicatorStrategy(Indicator<Double> first, Indicator<Double> second) { *************** *** 20,29 **** public boolean shouldOperate(Trade trade, int index) { ! // TODO Auto-generated method stub return false; } ! public Operation shouldEnter(int index) { ! if(first.getValue(index).compareTo(second.getValue(index)) < 0) { return new Operation(index, OperationType.BUY); } --- 19,38 ---- public boolean shouldOperate(Trade trade, int index) { ! if (trade.isNew()) { ! if (first.getValue(index).compareTo(second.getValue(index)) < 0) { ! return trade.enter(index); ! } ! } ! ! else if (trade.isOpened()) { ! if (first.getValue(index).compareTo(second.getValue(index)) > 0) { ! return trade.exit(index); ! } ! } return false; } ! public Operation shouldEnter(int index) { ! if (first.getValue(index).compareTo(second.getValue(index)) < 0) { return new Operation(index, OperationType.BUY); } *************** *** 32,36 **** public Operation shouldExit(Operation entry, int index) { ! if(first.getValue(index).compareTo(second.getValue(index)) > 0) { return new Operation(index, OperationType.SELL); } --- 41,45 ---- public Operation shouldExit(Operation entry, int index) { ! if (first.getValue(index).compareTo(second.getValue(index)) > 0) { return new Operation(index, OperationType.SELL); } Index: DistanceBetweenIndicatorsStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/DistanceBetweenIndicatorsStrategy.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DistanceBetweenIndicatorsStrategy.java 6 Jun 2007 19:24:52 -0000 1.2 --- DistanceBetweenIndicatorsStrategy.java 8 Jun 2007 14:59:36 -0000 1.3 *************** *** 9,19 **** /** * ! * Estratégia que recebe dois indicadores com uma diferença comum entre eles ! * e toma a decisão de compra do indicador que está representando a ação superior ! * caso a distance entre elas esteja abaixo de difference, e a decisão de venda * caso a distance entre elas esteja acima de difference. * * @author marcio ! * */ public class DistanceBetweenIndicatorsStrategy implements Strategy { --- 9,19 ---- /** * ! * Estratégia que recebe dois indicadores com uma diferença comum entre eles e ! * toma a decisão de compra do indicador que está representando a ação inferior ! * caso a distance entre elas esteja abaixo de difference, e a decisão de venda * caso a distance entre elas esteja acima de difference. * * @author marcio ! * */ public class DistanceBetweenIndicatorsStrategy implements Strategy { *************** *** 22,31 **** private Indicator<? extends Number> lower; ! private double distance; private double difference; ! ! public DistanceBetweenIndicatorsStrategy(Indicator<? extends Number> upper, Indicator<? extends Number> lower, double distance, double difference) { this.upper = upper; this.lower = lower; --- 22,32 ---- private Indicator<? extends Number> lower; ! private double distance; private double difference; ! ! public DistanceBetweenIndicatorsStrategy(Indicator<? extends Number> upper, Indicator<? extends Number> lower, ! double distance, double difference) { this.upper = upper; this.lower = lower; *************** *** 33,40 **** this.difference = difference; } ! public Operation shouldEnter(int index) { ! if((upper.getValue(index).doubleValue() - lower.getValue(index).doubleValue()) >= (difference + 1.0) * distance) ! { return new Operation(index, OperationType.BUY); } --- 34,41 ---- this.difference = difference; } ! public Operation shouldEnter(int index) { ! if ((upper.getValue(index).doubleValue() - lower.getValue(index).doubleValue()) >= (difference + 1.0) ! * distance) { return new Operation(index, OperationType.BUY); } *************** *** 43,57 **** public Operation shouldExit(Operation entry, int index) { ! if((upper.getValue(index).doubleValue() - lower.getValue(index).doubleValue()) <= (1.0 - difference) * distance) ! { return new Operation(index, OperationType.SELL); } return null; } ! public boolean shouldOperate(Trade trade, int index) { ! // TODO Auto-generated method stub return false; } } --- 44,80 ---- public Operation shouldExit(Operation entry, int index) { ! if ((upper.getValue(index).doubleValue() - lower.getValue(index).doubleValue()) <= (1.0 - difference) ! * distance) { return new Operation(index, OperationType.SELL); } return null; } ! public boolean shouldOperate(Trade trade, int index) { ! if (trade.isNew()) { ! if ((upper.getValue(index).doubleValue() - lower.getValue(index).doubleValue()) >= (difference + 1.0) ! * distance) { ! return trade.enter(index); ! } ! } ! else if (trade.isOpened()) { ! if ((upper.getValue(index).doubleValue() - lower.getValue(index).doubleValue()) <= (1.0 - difference) ! * distance) { ! return trade.exit(index); ! } ! } ! return false; } } + + // TODO APAGAR ISTO DEPOIS DA REFATORACAO + //if (trade.isNew()) { + // return trade.enter(index); + // } + //} + //else if (trade.isOpened()) { + // return trade.exit(index); + // } + //} Index: MinValueStarterStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/MinValueStarterStrategy.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MinValueStarterStrategy.java 6 Jun 2007 19:24:52 -0000 1.4 --- MinValueStarterStrategy.java 8 Jun 2007 14:59:36 -0000 1.5 *************** *** 8,13 **** /** * MinValueStarterStrategy baseia a compra em uma {@link Strategy} enviada como ! * parâmetro desde que o valor atual esteja acima do {@link start}, ! * e baseia a venda nessa mesma {@link Strategy} */ public class MinValueStarterStrategy implements Strategy { --- 8,13 ---- /** * MinValueStarterStrategy baseia a compra em uma {@link Strategy} enviada como ! * parâmetro desde que o valor atual esteja acima do {@link start}, e baseia a ! * venda nessa mesma {@link Strategy} */ public class MinValueStarterStrategy implements Strategy { *************** *** 40,46 **** return strategy; } ! public boolean shouldOperate(Trade trade, int index) { ! // TODO Auto-generated method stub return false; } --- 40,53 ---- return strategy; } ! public boolean shouldOperate(Trade trade, int index) { ! if (trade.isNew()) { ! if (indicator.getValue(index).doubleValue() > start) { ! return trade.enter(index); ! } ! } ! else if (trade.isOpened()) { ! return strategy.shouldOperate(trade, index); ! } return false; } Index: ResistanceStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/ResistanceStrategy.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ResistanceStrategy.java 6 Jun 2007 19:24:52 -0000 1.3 --- ResistanceStrategy.java 8 Jun 2007 14:59:36 -0000 1.4 *************** *** 8,17 **** /** ! * A estratégia ResistanceStrategy vende quando o valor do {@link indicator} é maior ou igual ao {@link resistance} e compra de acordo ! * com a {@link strategy}. * @author marcio ! * */ ! public class ResistanceStrategy implements Strategy{ private final Strategy strategy; --- 8,19 ---- /** ! * A estratégia ResistanceStrategy vende quando o valor do {@link indicator} é ! * maior ou igual ao {@link resistance} e compra de acordo com a ! * {@link strategy}. ! * * @author marcio ! * */ ! public class ResistanceStrategy implements Strategy { private final Strategy strategy; *************** *** 26,30 **** this.indicator = indicator; } ! public Operation shouldEnter(int index) { return strategy.shouldEnter(index); --- 28,32 ---- this.indicator = indicator; } ! public Operation shouldEnter(int index) { return strategy.shouldEnter(index); *************** *** 32,42 **** public Operation shouldExit(Operation entry, int index) { ! if(indicator.getValue(index).doubleValue() >= resistance) return new Operation(index, OperationType.SELL); return strategy.shouldExit(entry, index); } ! public boolean shouldOperate(Trade trade, int index) { ! // TODO Auto-generated method stub return false; } --- 34,50 ---- public Operation shouldExit(Operation entry, int index) { ! if (indicator.getValue(index).doubleValue() >= resistance) return new Operation(index, OperationType.SELL); return strategy.shouldExit(entry, index); } ! public boolean shouldOperate(Trade trade, int index) { ! if (trade.isNew()) { ! return strategy.shouldOperate(trade, index); ! } else if (trade.isOpened()) { ! if (indicator.getValue(index).doubleValue() >= resistance) ! return trade.exit(index); ! return strategy.shouldOperate(trade, index); ! } return false; } Index: SupportStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/SupportStrategy.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SupportStrategy.java 6 Jun 2007 19:24:52 -0000 1.3 --- SupportStrategy.java 8 Jun 2007 14:59:36 -0000 1.4 *************** *** 7,16 **** import net.sf.tail.Trade; - /** ! * A estratégia SupportStrategy compra quando o valor do {@link indicator} é menor ou igual ao {@link support} e vende de acordo ! * com a {@link strategy}. * @author marcio ! * */ public class SupportStrategy implements Strategy { --- 7,16 ---- import net.sf.tail.Trade; /** ! * A estratégia SupportStrategy compra quando o valor do {@link indicator} é ! * menor ou igual ao {@link support} e vende de acordo com a {@link strategy}. ! * * @author marcio ! * */ public class SupportStrategy implements Strategy { *************** *** 39,43 **** public boolean shouldOperate(Trade trade, int index) { ! // TODO Auto-generated method stub return false; } --- 39,49 ---- public boolean shouldOperate(Trade trade, int index) { ! if (trade.isNew()) { ! if (indicator.getValue(index).doubleValue() <= support) ! return trade.enter(index); ! return strategy.shouldOperate(trade, index); ! } else if (trade.isOpened()) { ! return strategy.shouldOperate(trade, index); ! } return false; } |
|
From: Danilo S. <dt...@us...> - 2007-06-06 19:24:54
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/strategy In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv1640/src/java/net/sf/tail/strategy Modified Files: ResistanceStrategy.java PipeEnterStrategy.java JustBuyOnceStrategy.java MinValueStarterStrategy.java IndicatorOverIndicatorStrategy.java SupportStrategy.java MinValueStopperStrategy.java DistanceBetweenIndicatorsStrategy.java IndicatorCrossedIndicatorStrategy.java Added Files: AlwaysOperateStrategy.java Log Message: Incio da refatorao para usar Strategy.shouldOperate() Index: PipeEnterStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/PipeEnterStrategy.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PipeEnterStrategy.java 31 May 2007 16:45:41 -0000 1.2 --- PipeEnterStrategy.java 6 Jun 2007 19:24:52 -0000 1.3 *************** *** 5,8 **** --- 5,9 ---- import net.sf.tail.OperationType; import net.sf.tail.Strategy; + import net.sf.tail.Trade; import net.sf.tail.indicator.helper.CrossIndicator; *************** *** 52,55 **** --- 53,61 ---- return null; } + + public boolean shouldOperate(Trade trade, int index) { + // TODO Auto-generated method stub + return false; + } public Indicator<? extends Number> getLower() { --- NEW FILE: AlwaysOperateStrategy.java --- package net.sf.tail.strategy; import net.sf.tail.Operation; import net.sf.tail.Strategy; import net.sf.tail.Trade; public class AlwaysOperateStrategy implements Strategy { public Operation shouldEnter(int index) { // TODO Auto-generated method stub return null; } public Operation shouldExit(Operation entry, int index) { // TODO Auto-generated method stub return null; } public boolean shouldOperate(Trade trade, int index) { if (trade.isNew()) { return trade.enter(index); } else if (trade.isOpened()) { return trade.exit(index); } return false; } } Index: IndicatorOverIndicatorStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/IndicatorOverIndicatorStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IndicatorOverIndicatorStrategy.java 19 May 2007 12:37:57 -0000 1.1 --- IndicatorOverIndicatorStrategy.java 6 Jun 2007 19:24:52 -0000 1.2 *************** *** 5,8 **** --- 5,9 ---- import net.sf.tail.OperationType; import net.sf.tail.Strategy; + import net.sf.tail.Trade; public class IndicatorOverIndicatorStrategy implements Strategy { *************** *** 18,21 **** --- 19,26 ---- } + public boolean shouldOperate(Trade trade, int index) { + // TODO Auto-generated method stub + return false; + } public Operation shouldEnter(int index) { Index: DistanceBetweenIndicatorsStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/DistanceBetweenIndicatorsStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DistanceBetweenIndicatorsStrategy.java 26 May 2007 13:57:03 -0000 1.1 --- DistanceBetweenIndicatorsStrategy.java 6 Jun 2007 19:24:52 -0000 1.2 *************** *** 5,8 **** --- 5,9 ---- import net.sf.tail.OperationType; import net.sf.tail.Strategy; + import net.sf.tail.Trade; /** *************** *** 48,51 **** --- 49,57 ---- return null; } + + public boolean shouldOperate(Trade trade, int index) { + // TODO Auto-generated method stub + return false; + } } Index: MinValueStarterStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/MinValueStarterStrategy.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MinValueStarterStrategy.java 24 May 2007 21:11:11 -0000 1.3 --- MinValueStarterStrategy.java 6 Jun 2007 19:24:52 -0000 1.4 *************** *** 4,7 **** --- 4,8 ---- import net.sf.tail.Operation; import net.sf.tail.Strategy; + import net.sf.tail.Trade; /** *************** *** 39,42 **** --- 40,48 ---- return strategy; } + + public boolean shouldOperate(Trade trade, int index) { + // TODO Auto-generated method stub + return false; + } } Index: JustBuyOnceStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/JustBuyOnceStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JustBuyOnceStrategy.java 19 May 2007 15:45:12 -0000 1.1 --- JustBuyOnceStrategy.java 6 Jun 2007 19:24:52 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- import net.sf.tail.OperationType; import net.sf.tail.Strategy; + import net.sf.tail.Trade; public class JustBuyOnceStrategy implements Strategy { *************** *** 26,28 **** --- 27,36 ---- return null; } + + public boolean shouldOperate(Trade trade, int index) { + if (trade.isNew()) { + return trade.enter(index); + } + return false; + } } Index: ResistanceStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/ResistanceStrategy.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ResistanceStrategy.java 31 May 2007 16:45:41 -0000 1.2 --- ResistanceStrategy.java 6 Jun 2007 19:24:52 -0000 1.3 *************** *** 5,8 **** --- 5,9 ---- import net.sf.tail.OperationType; import net.sf.tail.Strategy; + import net.sf.tail.Trade; /** *************** *** 36,39 **** } ! } --- 37,43 ---- } ! public boolean shouldOperate(Trade trade, int index) { ! // TODO Auto-generated method stub ! return false; ! } } Index: SupportStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/SupportStrategy.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SupportStrategy.java 31 May 2007 16:45:41 -0000 1.2 --- SupportStrategy.java 6 Jun 2007 19:24:52 -0000 1.3 *************** *** 5,8 **** --- 5,9 ---- import net.sf.tail.OperationType; import net.sf.tail.Strategy; + import net.sf.tail.Trade; *************** *** 37,39 **** --- 38,44 ---- } + public boolean shouldOperate(Trade trade, int index) { + // TODO Auto-generated method stub + return false; + } } Index: MinValueStopperStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/MinValueStopperStrategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MinValueStopperStrategy.java 19 May 2007 15:45:12 -0000 1.1 --- MinValueStopperStrategy.java 6 Jun 2007 19:24:52 -0000 1.2 *************** *** 5,8 **** --- 5,9 ---- import net.sf.tail.OperationType; import net.sf.tail.Strategy; + import net.sf.tail.Trade; /** *************** *** 44,47 **** --- 45,62 ---- return strategy.shouldExit(entry, index); } + + public boolean shouldOperate(Trade trade, int index) { + // TODO: Código replicado. Template method?? + if (trade.isNew()) { + value = indicator.getValue(index).doubleValue(); + return strategy.shouldOperate(trade, index); + } else if (trade.isOpened()) { + if (value - (value * (loss / 100)) > indicator.getValue(index).doubleValue()) { + return trade.exit(index); + } + return strategy.shouldOperate(trade, index); + } + return false; + } public double getLoss() { Index: IndicatorCrossedIndicatorStrategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/strategy/IndicatorCrossedIndicatorStrategy.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** IndicatorCrossedIndicatorStrategy.java 31 May 2007 16:45:41 -0000 1.3 --- IndicatorCrossedIndicatorStrategy.java 6 Jun 2007 19:24:52 -0000 1.4 *************** *** 5,8 **** --- 5,9 ---- import net.sf.tail.OperationType; import net.sf.tail.Strategy; + import net.sf.tail.Trade; import net.sf.tail.indicator.helper.CrossIndicator; *************** *** 40,42 **** --- 41,55 ---- } + public boolean shouldOperate(Trade trade, int index) { + if (trade.isNew()) { + if (crossUp.getValue(index)) { + return trade.enter(index); + } + } else if (trade.isOpened()) { + if (crossDown.getValue(index)) { + return trade.exit(index); + } + } + return false; + } } |
|
From: Danilo S. <dt...@us...> - 2007-06-06 19:24:54
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/runner In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv1640/src/java/net/sf/tail/runner Modified Files: HistoryRunner.java Log Message: Incio da refatorao para usar Strategy.shouldOperate() Index: HistoryRunner.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/runner/HistoryRunner.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** HistoryRunner.java 24 May 2007 17:48:04 -0000 1.4 --- HistoryRunner.java 6 Jun 2007 19:24:52 -0000 1.5 *************** *** 4,8 **** import java.util.List; - import net.sf.tail.Operation; import net.sf.tail.OperationType; import net.sf.tail.Strategy; --- 4,7 ---- *************** *** 12,44 **** private int seriesSize; ! public HistoryRunner(int seriesSize) { this.seriesSize = seriesSize; } public List<Trade> run(Strategy strategy) { List<Trade> trades = new ArrayList<Trade>(); for (int i = 0; i < seriesSize; i++) { ! Operation entry = strategy.shouldEnter(i); ! if (entry != null) { ! for (i++; i < seriesSize; i++) { ! Operation exit = strategy.shouldExit(entry, i); ! if (exit != null) { ! Trade t = new Trade(entry, exit); ! trades.add(t); ! break; ! } ! else if(i + 1 == seriesSize){ ! if(entry.getType().equals(OperationType.BUY)) ! exit = new Operation(i, OperationType.SELL); ! else ! exit = new Operation(i, OperationType.BUY); ! Trade t = new Trade(entry, exit); ! trades.add(t); ! break; ! } ! } } } return trades; } --- 11,51 ---- private int seriesSize; + private OperationType operationType; ! public HistoryRunner(int seriesSize, OperationType type) { this.seriesSize = seriesSize; + this.operationType = type; } public List<Trade> run(Strategy strategy) { List<Trade> trades = new ArrayList<Trade>(); + Trade lastTrade = new Trade(operationType); for (int i = 0; i < seriesSize; i++) { ! // Operation entry = strategy.shouldEnter(i); ! // if (entry != null) { ! // for (i++; i < seriesSize; i++) { ! // Operation exit = strategy.shouldExit(entry, i); ! // if (exit != null) { ! // Trade t = new Trade(entry, exit); ! // trades.add(t); ! // break; ! // } ! // else if(i + 1 == seriesSize){ ! // exit = new Operation(i, OperationType.SELL); ! // Trade t = new Trade(entry, exit); ! // trades.add(t); ! // break; ! // } ! // } ! // } ! if (strategy.shouldOperate(lastTrade, i) && lastTrade.isClosed()) { ! trades.add(lastTrade); ! lastTrade = new Trade(operationType); } } + if (lastTrade.isOpened()) { + lastTrade.exit(seriesSize-1); + trades.add(lastTrade); + } return trades; } |
|
From: Danilo S. <dt...@us...> - 2007-06-06 19:24:54
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/strategy In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv1640/src/test/net/sf/tail/strategy Modified Files: ResistanceStrategyTest.java JustBuyOnceStrategyTest.java IndicatorCrossedIndicatorStrategyTest.java MinValueStarterStrategyTest.java IndicatorOverIndicatorStrategyTest.java MinValueStopperStrategyTest.java SupportStrategyTest.java Added Files: AlwaysOperateStrategyTest.java FakeStrategy.java Removed Files: FakeStratetgy.java Log Message: Incio da refatorao para usar Strategy.shouldOperate() Index: SupportStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/SupportStrategyTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SupportStrategyTest.java 24 May 2007 20:10:01 -0000 1.1 --- SupportStrategyTest.java 6 Jun 2007 19:24:52 -0000 1.2 *************** *** 27,31 **** Operation[] enter = new Operation[] { null, null, null, null, null, null }; ! Strategy neverBuy = new FakeStratetgy( enter , enter); Strategy support = new SupportStrategy(indicator,neverBuy, 95); --- 27,31 ---- Operation[] enter = new Operation[] { null, null, null, null, null, null }; ! Strategy neverBuy = new FakeStrategy( enter , enter); Strategy support = new SupportStrategy(indicator,neverBuy, 95); --- NEW FILE: FakeStrategy.java --- package net.sf.tail.strategy; import net.sf.tail.Operation; import net.sf.tail.Strategy; import net.sf.tail.Trade; public class FakeStrategy implements Strategy { private Operation[] enter; private Operation[] exit; public FakeStrategy(Operation[] enter, Operation[] exit) { this.enter = enter; this.exit = exit; } public Operation shouldEnter(int index) { return enter[index]; } public Operation shouldExit(Operation entry, int index) { return exit[index]; } public boolean shouldOperate(Trade trade, int index) { if (enter[index] != null) { return trade.enter(index); } else if (exit[index] != null) { return trade.exit(index); } return false; } } Index: IndicatorOverIndicatorStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/IndicatorOverIndicatorStrategyTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** IndicatorOverIndicatorStrategyTest.java 24 May 2007 17:47:15 -0000 1.5 --- IndicatorOverIndicatorStrategyTest.java 6 Jun 2007 19:24:52 -0000 1.6 *************** *** 35,39 **** Operation buy = new Operation(2,OperationType.BUY); assertEquals(buy, s.shouldEnter(2)); ! assertEquals(null, s.shouldExit(buy, 3)); Operation sell = new Operation(4,OperationType.SELL); --- 35,39 ---- Operation buy = new Operation(2,OperationType.BUY); assertEquals(buy, s.shouldEnter(2)); ! assertEquals(null, s.shouldExit(buy, 3)); // TODO: ?? Não deveria mandar comprar mais? Operation sell = new Operation(4,OperationType.SELL); Index: MinValueStopperStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/MinValueStopperStrategyTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MinValueStopperStrategyTest.java 24 May 2007 20:08:07 -0000 1.2 --- MinValueStopperStrategyTest.java 6 Jun 2007 19:24:52 -0000 1.3 *************** *** 1,10 **** package net.sf.tail.strategy; ! import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; - import junit.framework.JUnit4TestAdapter; import net.sf.tail.Operation; import net.sf.tail.OperationType; import net.sf.tail.Strategy; import net.sf.tail.sample.SampleIndicator; --- 1,10 ---- package net.sf.tail.strategy; ! import static org.junit.Assert.*; import static org.junit.Assert.assertNull; import net.sf.tail.Operation; import net.sf.tail.OperationType; import net.sf.tail.Strategy; + import net.sf.tail.Trade; import net.sf.tail.sample.SampleIndicator; *************** *** 28,43 **** Operation buy = new Operation(0,OperationType.BUY); ! assertEquals(buy, stopper.shouldEnter(0)); ! assertNull(stopper.shouldExit(buy, 2)); ! assertNull(stopper.shouldExit(buy, 3)); ! Operation sell = new Operation(4,OperationType.SELL); ! assertEquals(sell, stopper.shouldExit(buy, 4)); } ! public static junit.framework.Test suite() { ! return new JUnit4TestAdapter(IndicatorOverIndicatorStrategyTest.class); ! } } --- 28,51 ---- Operation buy = new Operation(0,OperationType.BUY); + Operation sell = new Operation(4,OperationType.SELL); ! // assertEquals(buy, stopper.shouldEnter(0)); ! // assertNull(stopper.shouldExit(buy, 2)); ! // assertNull(stopper.shouldExit(buy, 3)); ! // ! // Operation sell = new Operation(4,OperationType.SELL); ! // assertEquals(sell, stopper.shouldExit(buy, 4)); ! Trade trade = new Trade(); ! assertTrue(stopper.shouldOperate(trade, 0)); ! assertEquals(buy, trade.getEntry()); ! assertFalse(stopper.shouldOperate(trade, 1)); ! assertFalse(stopper.shouldOperate(trade, 2)); ! assertFalse(stopper.shouldOperate(trade, 3)); ! assertTrue(stopper.shouldOperate(trade, 4)); ! assertEquals(sell, trade.getExit()); } ! } --- NEW FILE: AlwaysOperateStrategyTest.java --- package net.sf.tail.strategy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import net.sf.tail.Operation; import net.sf.tail.OperationType; import net.sf.tail.Trade; import org.junit.Before; import org.junit.Test; public class AlwaysOperateStrategyTest { private AlwaysOperateStrategy strategy; private Trade trade, uncoveredTrade; @Before public void setUp() { this.strategy = new AlwaysOperateStrategy(); this.trade = new Trade(); this.uncoveredTrade = new Trade(OperationType.SELL); } @Test public void shouldEnterBuyingIfTradeIsNew() { assertTrue(strategy.shouldOperate(trade, 0)); assertEquals(new Operation(0, OperationType.BUY), trade.getEntry()); } @Test public void shouldExitSellingIfTradeIsOpened() { trade.enter(0); assertTrue(strategy.shouldOperate(trade, 1)); assertEquals(new Operation(1, OperationType.SELL), trade.getExit()); } @Test public void shouldNotOperateIfTradeIsClosed() { trade.enter(0); trade.exit(1); assertFalse(strategy.shouldOperate(trade, 2)); } @Test public void shouldEnterSellingIfUncoveredTradeIsNew() { assertTrue(strategy.shouldOperate(uncoveredTrade, 0)); assertEquals(new Operation(0, OperationType.SELL), uncoveredTrade.getEntry()); } @Test public void shouldExitBuyingIfUncoveredTradeIsOpened() { uncoveredTrade.enter(0); assertTrue(strategy.shouldOperate(uncoveredTrade, 1)); assertEquals(new Operation(1, OperationType.BUY), uncoveredTrade.getExit()); } } Index: ResistanceStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/ResistanceStrategyTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ResistanceStrategyTest.java 24 May 2007 20:10:01 -0000 1.1 --- ResistanceStrategyTest.java 6 Jun 2007 19:24:51 -0000 1.2 *************** *** 27,31 **** Operation[] enter = new Operation[] { null, null, null, null, null, null }; ! Strategy neverSell = new FakeStratetgy( enter , enter); Strategy resistance = new ResistanceStrategy(indicator,neverSell, 96); --- 27,31 ---- Operation[] enter = new Operation[] { null, null, null, null, null, null }; ! Strategy neverSell = new FakeStrategy( enter , enter); Strategy resistance = new ResistanceStrategy(indicator,neverSell, 96); --- FakeStratetgy.java DELETED --- Index: IndicatorCrossedIndicatorStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/IndicatorCrossedIndicatorStrategyTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** IndicatorCrossedIndicatorStrategyTest.java 31 May 2007 16:45:41 -0000 1.3 --- IndicatorCrossedIndicatorStrategyTest.java 6 Jun 2007 19:24:51 -0000 1.4 *************** *** 2,7 **** --- 2,9 ---- import static org.junit.Assert.assertEquals; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; + import static org.junit.Assert.assertTrue; import junit.framework.JUnit4TestAdapter; import net.sf.tail.Indicator; *************** *** 9,12 **** --- 11,15 ---- import net.sf.tail.OperationType; import net.sf.tail.Strategy; + import net.sf.tail.Trade; import net.sf.tail.sample.SampleIndicator; *************** *** 21,38 **** Strategy s = new IndicatorCrossedIndicatorStrategy(first, second); ! assertNull(s.shouldEnter(0)); ! assertNull(s.shouldEnter(1)); ! Operation enter = new Operation(2,OperationType.BUY); ! assertEquals(enter,s.shouldEnter(2)); ! assertNull(s.shouldEnter(3)); ! assertNull(s.shouldEnter(4)); ! assertNull(s.shouldExit(enter, 3)); Operation exit = new Operation(4,OperationType.SELL); ! assertEquals(exit,s.shouldExit(enter, 4)); ! assertNull(s.shouldEnter(5)); ! } --- 24,42 ---- Strategy s = new IndicatorCrossedIndicatorStrategy(first, second); ! Trade trade = new Trade(); ! assertFalse(s.shouldOperate(trade, 0)); ! assertFalse(s.shouldOperate(trade, 1)); ! assertTrue(s.shouldOperate(trade, 2)); ! Operation enter = new Operation(2, OperationType.BUY); ! assertEquals(enter, trade.getEntry()); + assertFalse(s.shouldOperate(trade, 3)); + + assertTrue(s.shouldOperate(trade, 4)); Operation exit = new Operation(4,OperationType.SELL); + assertEquals(exit, trade.getExit()); ! assertFalse(s.shouldOperate(trade, 5)); } Index: JustBuyOnceStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/JustBuyOnceStrategyTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** JustBuyOnceStrategyTest.java 24 May 2007 20:08:07 -0000 1.2 --- JustBuyOnceStrategyTest.java 6 Jun 2007 19:24:51 -0000 1.3 *************** *** 2,9 **** - import junit.framework.JUnit4TestAdapter; import net.sf.tail.Operation; import net.sf.tail.OperationType; import net.sf.tail.Strategy; import static org.junit.Assert.*; --- 2,9 ---- import net.sf.tail.Operation; import net.sf.tail.OperationType; import net.sf.tail.Strategy; + import net.sf.tail.Trade; import static org.junit.Assert.*; *************** *** 13,42 **** public class JustBuyOnceStrategyTest { @Before public void setUp() throws Exception { } ! @Test ! public void testIfOnlyBuy(){ ! Strategy strategy = new JustBuyOnceStrategy(); Operation buy = new Operation(0,OperationType.BUY); ! assertEquals(buy, strategy.shouldEnter(0)); ! assertNull(strategy.shouldEnter(1)); ! assertNull(strategy.shouldExit(buy, 6)); } ! @Test ! public void testSameIndexShouldResultSameAwnser(){ ! Strategy strategy = new JustBuyOnceStrategy(); Operation buy = new Operation(0,OperationType.BUY); ! assertEquals(buy, strategy.shouldEnter(0)); ! assertEquals(buy, strategy.shouldEnter(0)); } ! public static junit.framework.Test suite() { ! return new JUnit4TestAdapter(JustBuyOnceStrategyTest.class); ! } } --- 13,53 ---- public class JustBuyOnceStrategyTest { + private Strategy strategy; + private Trade trade; + @Before public void setUp() throws Exception { + this.strategy = new JustBuyOnceStrategy(); + this.trade = new Trade(); } ! @Test public void ! shouldBuyTradeOnce() { Operation buy = new Operation(0,OperationType.BUY); ! // assertEquals(buy, strategy.shouldEnter(0)); ! // assertNull(strategy.shouldEnter(1)); ! // assertNull(strategy.shouldExit(buy, 6)); ! assertTrue(strategy.shouldOperate(trade, 0)); ! assertEquals(buy, trade.getEntry()); ! assertFalse(strategy.shouldOperate(trade, 1)); ! assertFalse(strategy.shouldOperate(trade, 6)); } ! @Test public void ! sameIndexShouldResultSameAnswer() { Operation buy = new Operation(0,OperationType.BUY); ! // assertEquals(buy, strategy.shouldEnter(0)); ! // assertEquals(buy, strategy.shouldEnter(0)); ! // TODO: Discutir... ! assertTrue(strategy.shouldOperate(trade, 0)); ! assertEquals(buy, trade.getEntry()); ! Trade trade2 = new Trade(); ! assertTrue(strategy.shouldOperate(trade2, 0)); ! assertEquals(buy, trade2.getEntry()); } ! } Index: MinValueStarterStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/MinValueStarterStrategyTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MinValueStarterStrategyTest.java 24 May 2007 20:09:25 -0000 1.2 --- MinValueStarterStrategyTest.java 6 Jun 2007 19:24:51 -0000 1.3 *************** *** 28,32 **** Operation[] exit = new Operation[] { null, null, null, null, null }; ! Strategy alwaysBuy = new FakeStratetgy( enter , exit); Strategy starter = new MinValueStarterStrategy(indicator,alwaysBuy, 93); --- 28,32 ---- Operation[] exit = new Operation[] { null, null, null, null, null }; ! Strategy alwaysBuy = new FakeStrategy( enter , exit); Strategy starter = new MinValueStarterStrategy(indicator,alwaysBuy, 93); |
|
From: Danilo S. <dt...@us...> - 2007-06-06 19:24:54
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/runner In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv1640/src/test/net/sf/tail/runner Modified Files: HistoryRunnerTest.java Log Message: Incio da refatorao para usar Strategy.shouldOperate() Index: HistoryRunnerTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/runner/HistoryRunnerTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** HistoryRunnerTest.java 19 May 2007 19:59:31 -0000 1.5 --- HistoryRunnerTest.java 6 Jun 2007 19:24:53 -0000 1.6 *************** *** 9,13 **** import net.sf.tail.Strategy; import net.sf.tail.Trade; ! import net.sf.tail.strategy.FakeStratetgy; import org.junit.Test; --- 9,13 ---- import net.sf.tail.Strategy; import net.sf.tail.Trade; ! import net.sf.tail.strategy.FakeStrategy; import org.junit.Test; *************** *** 15,27 **** public class HistoryRunnerTest { ! @Test ! public void testRunMethod() { Operation[] enter = { null, null, new Operation(2, OperationType.BUY), ! new Operation(3, OperationType.BUY), null, null, new Operation(6, OperationType.BUY), null }; Operation[] exit = { null, null, null, null, new Operation(4, OperationType.SELL), null, null, new Operation(7, OperationType.SELL), new Operation(8, OperationType.SELL) }; ! Strategy strategy = new FakeStratetgy(enter, exit); ! HistoryRunner historyRunner = new HistoryRunner(8); List<Trade> trades = historyRunner.run(strategy); assertEquals(2, trades.size()); --- 15,27 ---- public class HistoryRunnerTest { ! @Test public void ! testRunMethod() { Operation[] enter = { null, null, new Operation(2, OperationType.BUY), ! new Operation(3, OperationType.BUY), null, null, new Operation(6, OperationType.BUY), null, null }; Operation[] exit = { null, null, null, null, new Operation(4, OperationType.SELL), null, null, new Operation(7, OperationType.SELL), new Operation(8, OperationType.SELL) }; ! Strategy strategy = new FakeStrategy(enter, exit); ! HistoryRunner historyRunner = new HistoryRunner(8, OperationType.BUY); List<Trade> trades = historyRunner.run(strategy); assertEquals(2, trades.size()); *************** *** 35,46 **** } ! @Test ! public void testRunWithOpenEntryBuyLeft() { Operation[] enter = new Operation[] { null, new Operation(1, OperationType.BUY), null, null }; Operation[] exit = {null, null, null,null}; ! Strategy strategy = new FakeStratetgy(enter, exit); ! HistoryRunner historyRunner = new HistoryRunner(4); List<Trade> trades = historyRunner.run(strategy); assertEquals(1, trades.size()); --- 35,46 ---- } ! @Test public void ! testRunWithOpenEntryBuyLeft() { Operation[] enter = new Operation[] { null, new Operation(1, OperationType.BUY), null, null }; Operation[] exit = {null, null, null,null}; ! Strategy strategy = new FakeStrategy(enter, exit); ! HistoryRunner historyRunner = new HistoryRunner(4, OperationType.BUY); List<Trade> trades = historyRunner.run(strategy); assertEquals(1, trades.size()); *************** *** 51,62 **** ! @Test ! public void testRunWithOpenEntrySellLeft() { Operation[] enter = new Operation[] { null, new Operation(1, OperationType.SELL), null, null }; Operation[] exit = {null, null, null,null}; ! Strategy strategy = new FakeStratetgy(enter, exit); ! HistoryRunner historyRunner = new HistoryRunner(4); List<Trade> trades = historyRunner.run(strategy); assertEquals(1, trades.size()); --- 51,62 ---- ! @Test public void ! testRunWithOpenEntrySellLeft() { Operation[] enter = new Operation[] { null, new Operation(1, OperationType.SELL), null, null }; Operation[] exit = {null, null, null,null}; ! Strategy strategy = new FakeStrategy(enter, exit); ! HistoryRunner historyRunner = new HistoryRunner(4, OperationType.SELL); List<Trade> trades = historyRunner.run(strategy); assertEquals(1, trades.size()); |
|
From: Thies <tg...@us...> - 2007-06-06 17:30:57
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/analyzer In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv17768/src/java/net/sf/tail/analyzer Modified Files: MaximumDrawDown.java Log Message: Refatoração Index: MaximumDrawDown.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/analyzer/MaximumDrawDown.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MaximumDrawDown.java 31 May 2007 16:45:36 -0000 1.2 --- MaximumDrawDown.java 6 Jun 2007 17:30:57 -0000 1.3 *************** *** 20,25 **** double max = Double.NEGATIVE_INFINITY; ! for (int i = 0; i < seriesSize; i++) { ! sum = sum + indicator.getValue(index).doubleValue(); if (sum > max) { max = sum; --- 20,26 ---- double max = Double.NEGATIVE_INFINITY; ! for (int i = 0; i <= index; i++) { ! sum = sum + indicator.getValue(i).doubleValue(); ! if (sum > max) { max = sum; *************** *** 29,37 **** } ! public double calcMaximunDrawDown(int index) { double max = Double.NEGATIVE_INFINITY; double drawDown = 0; ! for (int i = 0; i <= index; i++) { drawDown = calcDrawDown(i); if (drawDown > max) { --- 30,38 ---- } ! public double calcMaximunDrawDown() { double max = Double.NEGATIVE_INFINITY; double drawDown = 0; ! for (int i = 0; i < seriesSize; i++) { drawDown = calcDrawDown(i); if (drawDown > max) { |
|
From: Thies <tg...@us...> - 2007-06-06 17:18:03
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/graphics In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv12268/src/java/net/sf/tail/graphics Added Files: TimeSeriesChartDemo1.java Log Message: teste BEM básico da parte gráfica... --- NEW FILE: TimeSeriesChartDemo1.java --- /* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Java is a trademark or registered trademark of Sun Microsystems, Inc. * in the United States and other countries.] * * ------------------------- * TimeSeriesChartDemo1.java * ------------------------- * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): ; * * $Id: TimeSeriesChartDemo1.java,v 1.1 2007/06/06 17:18:02 tgthies Exp $ * * Changes * ------- * 09-Mar-2005 : Version 1, copied from the demo collection that ships with * the JFreeChart Developer Guide (DG); * */ package net.sf.tail.graphics; import java.awt.Color; import java.text.SimpleDateFormat; import javax.swing.JPanel; import net.sf.tail.Indicator; import net.sf.tail.indicator.tracker.SMAIndicator; import net.sf.tail.sample.SampleIndicator; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; import org.jfree.data.time.Month; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; import org.jfree.data.xy.XYDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RectangleInsets; import org.jfree.ui.RefineryUtilities; /** * An example of a time series chart. For the most part, default settings are * used, except that the renderer is modified to show filled shapes (as well as * lines) at each data point. */ public class TimeSeriesChartDemo1 extends ApplicationFrame { /** * */ private static final long serialVersionUID = 1L; private final static String legenda = "Valor"; private final static String legenda2 = "SMA"; private final static SampleIndicator sample = new SampleIndicator(new double[]{10.4, 10.7, 9.1, 8.7, 6.3, 9.3, 10.8, 11.1, 12.5, 14.0}); private final static Indicator<Double> sma = new SMAIndicator(sample, 5); private final static TimeSeries s1 = new TimeSeries(legenda, Month.class); private final static TimeSeries s2 = new TimeSeries(legenda2, Month.class); /** * A demonstration application showing how to create a simple time series * chart. This example uses monthly data. * * @param title the frame title. */ public TimeSeriesChartDemo1(String title) { super(title); ChartPanel chartPanel = (ChartPanel) createDemoPanel(); chartPanel.setPreferredSize(new java.awt.Dimension(800, 600)); chartPanel.setMouseZoomable(true, false); setContentPane(chartPanel); } /** * Creates a chart. * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart( "Valor teste e seu SMA", // title "Data", // x-axis label "Valor", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.BLACK); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm")); return chart; } /** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset. */ private static XYDataset createDataset() { // SampleTimeSeries ts = new SampleTimeSeries(); // // ClosePriceIndicator sample = new ClosePriceIndicator(ts); for (int i = 0; i<10; i++) { s1.add(new Month((i%12)+1, 2007+(i/12)), sample.getValue(i).doubleValue()); s2.add(new Month((i%12)+1, 2007+(i/12)), sma.getValue(i).doubleValue()); } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); //dataset.setDomainIsPointsInTime(true); return dataset; } /** * Creates a panel for the demo (used by SuperDemo.java). * * @return A panel. */ public static JPanel createDemoPanel() { JFreeChart chart = createChart(createDataset()); return new ChartPanel(chart); } /** * Starting point for the demonstration application. * * @param args ignored. */ public static void main(String[] args) { TimeSeriesChartDemo1 demo = new TimeSeriesChartDemo1( "Time Series Chart Demo 1" ); demo.pack(); RefineryUtilities.centerFrameOnScreen(demo); demo.setVisible(true); } } |
|
From: Thies <tg...@us...> - 2007-06-06 17:17:56
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/graphics In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv12257/src/java/net/sf/tail/graphics Log Message: Directory /cvsroot/tail/Tail/src/java/net/sf/tail/graphics added to the repository |
|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 17:03:23
|
Update of /cvsroot/tail/Tail In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv10815 Modified Files: .classpath Log Message: Refatoração de testes Index: .classpath =================================================================== RCS file: /cvsroot/tail/Tail/.classpath,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** .classpath 31 May 2007 16:45:40 -0000 1.5 --- .classpath 31 May 2007 17:03:23 -0000 1.6 *************** *** 6,10 **** <classpathentry exported="true" kind="lib" path="lib/javacsv.jar"/> <classpathentry kind="lib" path="lib/junit-4.1.jar"/> - <classpathentry kind="lib" path="lib/emma.jar"/> <classpathentry kind="output" path="bin"/> </classpath> --- 6,9 ---- |
|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 17:03:22
|
Update of /cvsroot/tail/Tail/lib In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv10815/lib Removed Files: emma.jar Log Message: Refatoração de testes --- emma.jar DELETED --- |
|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 16:46:10
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/analyzer In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2946/src/java/net/sf/tail/analyzer Modified Files: MaximumDrawDown.java Log Message: Refatoração de testes Index: MaximumDrawDown.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/analyzer/MaximumDrawDown.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MaximumDrawDown.java 26 May 2007 15:20:53 -0000 1.1 --- MaximumDrawDown.java 31 May 2007 16:45:36 -0000 1.2 *************** *** 2,28 **** import net.sf.tail.Indicator; ! //TODO: MaximumDrawDown é mesmo uma classe? Ela fica neste pacote? Recebe um indicator como parâmetro no construtor? public class MaximumDrawDown { ! private Indicator<? extends Number> indicator; private int seriesSize; ! public MaximumDrawDown(Indicator <? extends Number> indicator, int seriesSize) { this.indicator = indicator; this.seriesSize = seriesSize; } ! ! private double calcDrawDown(int index) ! { double sum = 0; double max = Double.NEGATIVE_INFINITY; ! for (int i = 0; i < seriesSize; i++) { - sum = 0; - - for (int j = 0; j <= i; j++) { sum = sum + indicator.getValue(index).doubleValue(); - } - if (sum > max) { max = sum; --- 2,25 ---- import net.sf.tail.Indicator; ! ! //TODO: MaximumDrawDown é mesmo uma classe? Ela fica neste pacote? Recebe um indicator como parâmetro no ! //construtor? public class MaximumDrawDown { ! private Indicator<? extends Number> indicator; + private int seriesSize; ! public MaximumDrawDown(Indicator<? extends Number> indicator, int seriesSize) { this.indicator = indicator; this.seriesSize = seriesSize; } ! ! private double calcDrawDown(int index) { double sum = 0; double max = Double.NEGATIVE_INFINITY; ! for (int i = 0; i < seriesSize; i++) { sum = sum + indicator.getValue(index).doubleValue(); if (sum > max) { max = sum; *************** *** 31,44 **** return max - indicator.getValue(index).doubleValue(); } ! ! public double calcMaximunDrawDown(int index) ! { double max = Double.NEGATIVE_INFINITY; double drawDown = 0; ! for (int i = 0; i <= index; i++) { drawDown = calcDrawDown(i); ! if (drawDown > max) ! { max = drawDown; } --- 28,39 ---- return max - indicator.getValue(index).doubleValue(); } ! ! public double calcMaximunDrawDown(int index) { double max = Double.NEGATIVE_INFINITY; double drawDown = 0; ! for (int i = 0; i <= index; i++) { drawDown = calcDrawDown(i); ! if (drawDown > max) { max = drawDown; } |
|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 16:45:44
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/bollingerbands In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2946/src/test/net/sf/tail/indicator/bollingerbands Modified Files: BollingerBandsLowerIndicatorTest.java BollingerBandsUpperIndicatorTest.java BollingerBandsMiddleIndicatorTest.java Log Message: Refatoração de testes Index: BollingerBandsMiddleIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/bollingerbands/BollingerBandsMiddleIndicatorTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BollingerBandsMiddleIndicatorTest.java 19 May 2007 13:23:19 -0000 1.3 --- BollingerBandsMiddleIndicatorTest.java 31 May 2007 16:45:41 -0000 1.4 *************** *** 28,45 **** assertEquals(sma.getValue(i), bbmSMA.getValue(i)); } } @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 3); BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); ! bbmSMA.getValue(data.getSize()); } - // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede - // Linux) - // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(BollingerBandsMiddleIndicatorTest.class); --- 28,51 ---- assertEquals(sma.getValue(i), bbmSMA.getValue(i)); } + } + + @Test + public void testBollingerBandsLowerShouldWorkJumpingIndexes() { + SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 3); + BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); + assertEquals(sma.getValue(6), bbmSMA.getValue(6)); + assertEquals(sma.getValue(0), bbmSMA.getValue(0)); + } @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 3); BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); ! bbmSMA.getValue(3000); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(BollingerBandsMiddleIndicatorTest.class); Index: BollingerBandsLowerIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/bollingerbands/BollingerBandsLowerIndicatorTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BollingerBandsLowerIndicatorTest.java 19 May 2007 13:23:21 -0000 1.3 --- BollingerBandsLowerIndicatorTest.java 31 May 2007 16:45:41 -0000 1.4 *************** *** 4,10 **** import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.indicator.tracker.SMAIndicator; - import net.sf.tail.indicator.tracker.StandardDeviationIndicator; import net.sf.tail.indicator.tracker.bollingerbands.BollingerBandsLowerIndicator; import net.sf.tail.indicator.tracker.bollingerbands.BollingerBandsMiddleIndicator; --- 4,10 ---- import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; + import net.sf.tail.indicator.helper.StandardDeviationIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.indicator.tracker.SMAIndicator; import net.sf.tail.indicator.tracker.bollingerbands.BollingerBandsLowerIndicator; import net.sf.tail.indicator.tracker.bollingerbands.BollingerBandsMiddleIndicator; *************** *** 18,45 **** private TimeSeries data; @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2 }); } @Test public void testBollingerBandsLowerUsingSMAAndStandardDeviation() throws Exception { ! int timeFrame = 3; ! ClosePriceIndicator closePrice = new ClosePriceIndicator(data); ! SMAIndicator sma = new SMAIndicator(closePrice, timeFrame); BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); BollingerBandsLowerIndicator bblSMA = new BollingerBandsLowerIndicator(bbmSMA, standardDeviation); ! for (int i = 0; i < data.getSize(); i++) { ! assertEquals(sma.getValue(i) - 2 * standardDeviation.getValue(i), bblSMA.getValue(i)); ! } } @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { ! int timeFrame = 3; ! ClosePriceIndicator closePrice = new ClosePriceIndicator(data); ! SMAIndicator sma = new SMAIndicator(closePrice, timeFrame); BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); --- 18,65 ---- private TimeSeries data; + private int timeFrame; + + private ClosePriceIndicator closePrice; + + private SMAIndicator sma; + @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2 }); + timeFrame = 3; + closePrice = new ClosePriceIndicator(data); + sma = new SMAIndicator(closePrice, timeFrame); } @Test public void testBollingerBandsLowerUsingSMAAndStandardDeviation() throws Exception { ! BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); BollingerBandsLowerIndicator bblSMA = new BollingerBandsLowerIndicator(bbmSMA, standardDeviation); ! assertEquals(1d, bblSMA.getValue(0)); ! assertEquals(0.08, bblSMA.getValue(1), 0.01); ! assertEquals(-0.82, bblSMA.getValue(2), 0.01); ! assertEquals(0.17, bblSMA.getValue(3), 0.01); ! assertEquals(1.70, bblSMA.getValue(4), 0.01); ! assertEquals(2.03, bblSMA.getValue(5), 0.01); ! assertEquals(1.17, bblSMA.getValue(6), 0.01); ! } ! ! @Test ! public void testBollingerBandsLowerShouldWorkJumpingIndexes() { ! ! BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); ! StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); ! BollingerBandsLowerIndicator bblSMA = new BollingerBandsLowerIndicator(bbmSMA, standardDeviation); ! ! assertEquals(1.17, bblSMA.getValue(6), 0.01); ! assertEquals(0.08, bblSMA.getValue(1), 0.01); } @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { ! BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); Index: BollingerBandsUpperIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/bollingerbands/BollingerBandsUpperIndicatorTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BollingerBandsUpperIndicatorTest.java 19 May 2007 13:23:18 -0000 1.3 --- BollingerBandsUpperIndicatorTest.java 31 May 2007 16:45:41 -0000 1.4 *************** *** 4,10 **** import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.indicator.tracker.SMAIndicator; - import net.sf.tail.indicator.tracker.StandardDeviationIndicator; import net.sf.tail.indicator.tracker.bollingerbands.BollingerBandsMiddleIndicator; import net.sf.tail.indicator.tracker.bollingerbands.BollingerBandsUpperIndicator; --- 4,10 ---- import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; + import net.sf.tail.indicator.helper.StandardDeviationIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.indicator.tracker.SMAIndicator; import net.sf.tail.indicator.tracker.bollingerbands.BollingerBandsMiddleIndicator; import net.sf.tail.indicator.tracker.bollingerbands.BollingerBandsUpperIndicator; *************** *** 18,45 **** private TimeSeries data; @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2 }); } @Test public void testBollingerBandsUpperUsingSMAAndStandardDeviation() throws Exception { ! int timeFrame = 3; ! ClosePriceIndicator closePrice = new ClosePriceIndicator(data); ! SMAIndicator sma = new SMAIndicator(closePrice, timeFrame); BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); BollingerBandsUpperIndicator bbuSMA = new BollingerBandsUpperIndicator(bbmSMA, standardDeviation); ! for (int i = 0; i < data.getSize(); i++) { ! assertEquals(sma.getValue(i) + 2 * standardDeviation.getValue(i), bbuSMA.getValue(i)); ! } } @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { ! int timeFrame = 3; ! ClosePriceIndicator closePrice = new ClosePriceIndicator(data); ! SMAIndicator sma = new SMAIndicator(closePrice, timeFrame); BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); --- 18,69 ---- private TimeSeries data; + private int timeFrame; + + private ClosePriceIndicator closePrice; + + private SMAIndicator sma; + @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2 }); + timeFrame = 3; + closePrice = new ClosePriceIndicator(data); + sma = new SMAIndicator(closePrice, timeFrame); } @Test public void testBollingerBandsUpperUsingSMAAndStandardDeviation() throws Exception { ! BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); BollingerBandsUpperIndicator bbuSMA = new BollingerBandsUpperIndicator(bbmSMA, standardDeviation); ! assertEquals(1.0, bbuSMA.getValue(0),0.01); ! assertEquals(2.91, bbuSMA.getValue(1),0.01); ! assertEquals(4.82, bbuSMA.getValue(2),0.01); ! assertEquals(5.82, bbuSMA.getValue(3),0.01); ! assertEquals(4.96, bbuSMA.getValue(4),0.01); ! assertEquals(5.29, bbuSMA.getValue(5),0.01); ! assertEquals(6.82, bbuSMA.getValue(6),0.01); ! assertEquals(5.96, bbuSMA.getValue(7),0.01); ! assertEquals(6.82, bbuSMA.getValue(8),0.01); ! assertEquals(4.96, bbuSMA.getValue(9),0.01); ! ! } ! ! @Test ! public void testBollingerBandsUpperShouldWorkJumpingIndexes() { ! ! BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); ! StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); ! BollingerBandsUpperIndicator bbuSMA = new BollingerBandsUpperIndicator(bbmSMA, standardDeviation); ! ! assertEquals(4.96, bbuSMA.getValue(9),0.01); ! assertEquals(4.96, bbuSMA.getValue(4),0.01); } @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { ! BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma); StandardDeviationIndicator standardDeviation = new StandardDeviationIndicator(closePrice, timeFrame); |
|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 16:45:44
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/indicator/oscilator In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2946/src/java/net/sf/tail/indicator/oscilator Modified Files: StochasticOscilatorK.java StochasticOscilatorD.java Log Message: Refatoração de testes Index: StochasticOscilatorD.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/indicator/oscilator/StochasticOscilatorD.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StochasticOscilatorD.java 19 May 2007 15:59:51 -0000 1.2 --- StochasticOscilatorD.java 31 May 2007 16:45:41 -0000 1.3 *************** *** 19,23 **** indicator = new SMAIndicator(k, 3); } ! //TODO é necessário este construtor? Este indicador precisa calcular com base no StochasticOscilator k public StochasticOscilatorD(Indicator<? extends Number> indicator) { --- 19,23 ---- indicator = new SMAIndicator(k, 3); } ! public StochasticOscilatorD(Indicator<? extends Number> indicator) { Index: StochasticOscilatorK.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/indicator/oscilator/StochasticOscilatorK.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StochasticOscilatorK.java 19 May 2007 15:59:51 -0000 1.2 --- StochasticOscilatorK.java 31 May 2007 16:45:41 -0000 1.3 *************** *** 3,11 **** import net.sf.tail.Indicator; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.indicator.simple.MaxPriceIndicator; import net.sf.tail.indicator.simple.MinPriceIndicator; - import net.sf.tail.indicator.tracker.HighestValueIndicator; - import net.sf.tail.indicator.tracker.LowestValueIndicator; /** --- 3,11 ---- import net.sf.tail.Indicator; import net.sf.tail.TimeSeries; + import net.sf.tail.indicator.helper.HighestValueIndicator; + import net.sf.tail.indicator.helper.LowestValueIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.indicator.simple.MaxPriceIndicator; import net.sf.tail.indicator.simple.MinPriceIndicator; /** |
|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 16:45:44
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail/indicator/tracker/bollingerbands In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2946/src/java/net/sf/tail/indicator/tracker/bollingerbands Modified Files: BollingerBandsUpperIndicator.java BollingerBandsLowerIndicator.java Log Message: Refatoração de testes Index: BollingerBandsLowerIndicator.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/indicator/tracker/bollingerbands/BollingerBandsLowerIndicator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BollingerBandsLowerIndicator.java 24 May 2007 21:11:11 -0000 1.3 --- BollingerBandsLowerIndicator.java 31 May 2007 16:45:41 -0000 1.4 *************** *** 2,6 **** import net.sf.tail.Indicator; ! import net.sf.tail.indicator.tracker.StandardDeviationIndicator; /** --- 2,6 ---- import net.sf.tail.Indicator; ! import net.sf.tail.indicator.helper.StandardDeviationIndicator; /** Index: BollingerBandsUpperIndicator.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/indicator/tracker/bollingerbands/BollingerBandsUpperIndicator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BollingerBandsUpperIndicator.java 24 May 2007 21:11:11 -0000 1.3 --- BollingerBandsUpperIndicator.java 31 May 2007 16:45:41 -0000 1.4 *************** *** 2,6 **** import net.sf.tail.Indicator; ! import net.sf.tail.indicator.tracker.StandardDeviationIndicator; /** --- 2,6 ---- import net.sf.tail.Indicator; ! import net.sf.tail.indicator.helper.StandardDeviationIndicator; /** |
|
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; } } |
|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 16:45:41
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/strategy In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2946/src/test/net/sf/tail/strategy Modified Files: PipeEnterStrategyTest.java IndicatorCrossedIndicatorStrategyTest.java Log Message: Refatoração de testes Index: IndicatorCrossedIndicatorStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/IndicatorCrossedIndicatorStrategyTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IndicatorCrossedIndicatorStrategyTest.java 24 May 2007 21:11:11 -0000 1.2 --- IndicatorCrossedIndicatorStrategyTest.java 31 May 2007 16:45:41 -0000 1.3 *************** *** 11,44 **** import net.sf.tail.sample.SampleIndicator; - import org.junit.Before; import org.junit.Test; public class IndicatorCrossedIndicatorStrategyTest { - private Indicator<Double> first; - - private Indicator<Double> second; - - @Before - public void setUp() throws Exception { - - first = new SampleIndicator(new double[] { 4, 7, 9, 6, 3, 2 }); - second = new SampleIndicator(new double[] { 3, 6, 10, 8, 2, 1 }); - - } @Test ! public void testCrossedIndicator() { Strategy s = new IndicatorCrossedIndicatorStrategy(first, second); assertNull(s.shouldEnter(0)); assertNull(s.shouldEnter(1)); ! Operation enter = s.shouldEnter(2); ! assertNotNull(enter); ! assertEquals(enter.getType(), OperationType.BUY); assertNull(s.shouldEnter(3)); assertNull(s.shouldEnter(4)); assertNull(s.shouldExit(enter, 3)); ! Operation exit = s.shouldExit(enter, 4); ! assertNotNull(exit); ! assertEquals(exit.getType(), OperationType.SELL); assertNull(s.shouldEnter(5)); --- 11,36 ---- import net.sf.tail.sample.SampleIndicator; import org.junit.Test; public class IndicatorCrossedIndicatorStrategyTest { @Test ! public void testCrossedIndicatorShouldBuyIndex2SellIndex4() { ! Indicator<Double> first = new SampleIndicator(new double[] { 4, 7, 9, 6, 3, 2 }); ! Indicator<Double> second = new SampleIndicator(new double[] { 3, 6, 10, 8, 2, 1 }); ! Strategy s = new IndicatorCrossedIndicatorStrategy(first, second); assertNull(s.shouldEnter(0)); assertNull(s.shouldEnter(1)); ! Operation enter = new Operation(2,OperationType.BUY); ! ! assertEquals(enter,s.shouldEnter(2)); assertNull(s.shouldEnter(3)); assertNull(s.shouldEnter(4)); assertNull(s.shouldExit(enter, 3)); ! ! Operation exit = new Operation(4,OperationType.SELL); ! ! assertEquals(exit,s.shouldExit(enter, 4)); assertNull(s.shouldEnter(5)); *************** *** 46,54 **** @Test ! public void testEqualIndicatorsShouldEnter() { ! Indicator<Double> firstEqual = new SampleIndicator(new double[] { 2, 3, 4, 5, 6, 7 }); ! Indicator<Double> secondEqual = new SampleIndicator(new double[] { 2, 3, 4, 5, 6, 7 }); ! Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); for (int i = 0; i < 6; i++) { --- 38,45 ---- @Test ! public void testCrossedIndicatorShouldNotEnterWhenIndicatorsAreEquals() { ! Indicator<Double> first = new SampleIndicator(new double[] { 2, 3, 4, 5, 6, 7 }); ! Strategy s = new IndicatorCrossedIndicatorStrategy(first, first); for (int i = 0; i < 6; i++) { *************** *** 58,62 **** @Test ! public void testEqualIndicatorsShouldExit() { Indicator<Double> firstEqual = new SampleIndicator(new double[] { 2, 1, 4, 5, 6, 7 }); Indicator<Double> secondEqual = new SampleIndicator(new double[] { 1, 3, 4, 5, 6, 7 }); --- 49,68 ---- @Test ! public void testCrossedIndicatorShouldNotExitWhenIndicatorsBecameEquals() { ! Indicator<Double> first = new SampleIndicator(new double[] { 4, 7, 9, 6, 3, 2 }); ! Indicator<Double> second = new SampleIndicator(new double[] { 3, 6, 10, 6, 3, 2 }); ! ! Strategy s = new IndicatorCrossedIndicatorStrategy(first, second); ! ! Operation enter = new Operation(2,OperationType.BUY); ! assertEquals(enter,s.shouldEnter(2)); ! ! for (int i = 3; i < 6; i++) { ! assertNull(s.shouldExit(enter,i)); ! } ! } ! ! @Test ! public void testEqualIndicatorsShouldNotExitWhenIndicatorsBecameEquals() { Indicator<Double> firstEqual = new SampleIndicator(new double[] { 2, 1, 4, 5, 6, 7 }); Indicator<Double> secondEqual = new SampleIndicator(new double[] { 1, 3, 4, 5, 6, 7 }); *************** *** 74,111 **** @Test ! public void testEqualIndicatorsShouldEnterEqualsShouldExit() { Indicator<Double> firstEqual = new SampleIndicator(new double[] { 2, 1, 4, 5, 6, 7, 10 }); Indicator<Double> secondEqual = new SampleIndicator(new double[] { 1, 3, 4, 5, 6, 7, 9 }); Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); ! Operation enter = s.shouldEnter(1); ! assertNotNull(enter); ! assertEquals(enter.getType(), OperationType.BUY); for (int i = 2; i < 6; i++) { assertNull(s.shouldExit(enter, i)); } ! Operation exit = s.shouldExit(enter, 6); ! assertNotNull(exit); ! assertEquals(exit.getType(), OperationType.SELL); } @Test ! public void testEqualIndicatorsShouldNotBuy() { Indicator<Double> firstEqual = new SampleIndicator(new double[] { 2, 3, 4, 5, 6, 7, 10 }); Indicator<Double> secondEqual = new SampleIndicator(new double[] { 1, 3, 4, 5, 6, 7, 9 }); Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); ! for (int i = 0; i < 7; i++) { assertNull(s.shouldEnter(i)); } - - firstEqual = new SampleIndicator(new double[] { 2, 3, 4, 5, 6, 8 }); - secondEqual = new SampleIndicator(new double[] { 2, 3, 4, 5, 6, 7 }); - - for (int i = 0; i < 6; i++) { - assertNull(s.shouldEnter(i)); - } } --- 80,109 ---- @Test ! public void testShouldNotSellWhileIndicatorAreEquals() { Indicator<Double> firstEqual = new SampleIndicator(new double[] { 2, 1, 4, 5, 6, 7, 10 }); Indicator<Double> secondEqual = new SampleIndicator(new double[] { 1, 3, 4, 5, 6, 7, 9 }); Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); ! Operation enter = new Operation(1,OperationType.BUY); ! assertEquals(enter,s.shouldEnter(1)); for (int i = 2; i < 6; i++) { assertNull(s.shouldExit(enter, i)); } ! ! Operation exit = new Operation(6,OperationType.SELL); ! assertEquals(exit, s.shouldExit(enter, 6)); } @Test ! public void testDontCrossShouldReturnNullOperations() { Indicator<Double> firstEqual = new SampleIndicator(new double[] { 2, 3, 4, 5, 6, 7, 10 }); Indicator<Double> secondEqual = new SampleIndicator(new double[] { 1, 3, 4, 5, 6, 7, 9 }); Strategy s = new IndicatorCrossedIndicatorStrategy(firstEqual, secondEqual); ! for (int i = 0; i < 7; i++) { assertNull(s.shouldEnter(i)); } } Index: PipeEnterStrategyTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/strategy/PipeEnterStrategyTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PipeEnterStrategyTest.java 24 May 2007 21:11:11 -0000 1.1 --- PipeEnterStrategyTest.java 31 May 2007 16:45:41 -0000 1.2 *************** *** 19,23 **** upper = new SampleIndicator(new double[] { 30, 32, 33, 32, 35, 33, 32, 33, 31, 30, 31, 32, 32, 34, 35 }); lower = new SampleIndicator(new double[] { 10, 12, 13, 12, 15, 13, 12, 13, 11, 10, 11, 12, 12, 14, 15 }); - } --- 19,22 ---- |
|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 16:45:41
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/simple In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2946/src/test/net/sf/tail/indicator/simple Modified Files: ConstantIndicatorTest.java AmountIndicatorTest.java ClosePriceIndicatorTest.java VolumeIndicatorTest.java MaxPriceIndicatorTest.java TradeIndicatorTest.java PreviousPriceIndicatorTest.java OpenPriceIndicatorTest.java VariationPriceIndicatorTest.java MinPriceIndicatorTest.java Log Message: Refatoração de testes Index: VolumeIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/simple/VolumeIndicatorTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** VolumeIndicatorTest.java 19 May 2007 13:23:18 -0000 1.4 --- VolumeIndicatorTest.java 31 May 2007 16:45:40 -0000 1.5 *************** *** 29,39 **** @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { volumeIndicator.getValue(10); } ! ! // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede ! // Linux) ! // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(VolumeIndicatorTest.class); --- 29,36 ---- @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { volumeIndicator.getValue(10); } ! public static junit.framework.Test suite() { return new JUnit4TestAdapter(VolumeIndicatorTest.class); Index: AmountIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/simple/AmountIndicatorTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AmountIndicatorTest.java 19 May 2007 13:23:18 -0000 1.4 --- AmountIndicatorTest.java 31 May 2007 16:45:40 -0000 1.5 *************** *** 30,40 **** @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { amountIndicator.getValue(10); } ! ! // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede ! // Linux) ! // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(AmountIndicatorTest.class); --- 30,37 ---- @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { amountIndicator.getValue(10); } ! public static junit.framework.Test suite() { return new JUnit4TestAdapter(AmountIndicatorTest.class); Index: MaxPriceIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/simple/MaxPriceIndicatorTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MaxPriceIndicatorTest.java 19 May 2007 13:23:18 -0000 1.7 --- MaxPriceIndicatorTest.java 31 May 2007 16:45:40 -0000 1.8 *************** *** 30,40 **** @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { maxPriceIndicator.getValue(10); } ! ! // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede ! // Linux) ! // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(MaxPriceIndicatorTest.class); --- 30,37 ---- @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { maxPriceIndicator.getValue(10); } ! public static junit.framework.Test suite() { return new JUnit4TestAdapter(MaxPriceIndicatorTest.class); Index: TradeIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/simple/TradeIndicatorTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TradeIndicatorTest.java 19 May 2007 13:23:17 -0000 1.7 --- TradeIndicatorTest.java 31 May 2007 16:45:40 -0000 1.8 *************** *** 30,40 **** @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { tradeIndicator.getValue(10); } ! ! // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede ! // Linux) ! // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(TradeIndicatorTest.class); --- 30,37 ---- @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { tradeIndicator.getValue(10); } ! public static junit.framework.Test suite() { return new JUnit4TestAdapter(TradeIndicatorTest.class); Index: ConstantIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/simple/ConstantIndicatorTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ConstantIndicatorTest.java 19 May 2007 13:13:29 -0000 1.3 --- ConstantIndicatorTest.java 31 May 2007 16:45:40 -0000 1.4 *************** *** 17,21 **** @Test ! public void TestConstant() { assertEquals(30.33, constantIndicator.getValue(10)); assertEquals(30.33, constantIndicator.getValue(1)); --- 17,21 ---- @Test ! public void testConstantIndicator() { assertEquals(30.33, constantIndicator.getValue(10)); assertEquals(30.33, constantIndicator.getValue(1)); *************** *** 23,30 **** assertEquals(30.33, constantIndicator.getValue(30)); } ! ! // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede ! // Linux) ! // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(ConstantIndicatorTest.class); --- 23,27 ---- assertEquals(30.33, constantIndicator.getValue(30)); } ! public static junit.framework.Test suite() { return new JUnit4TestAdapter(ConstantIndicatorTest.class); Index: OpenPriceIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/simple/OpenPriceIndicatorTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** OpenPriceIndicatorTest.java 19 May 2007 13:23:18 -0000 1.7 --- OpenPriceIndicatorTest.java 31 May 2007 16:45:40 -0000 1.8 *************** *** 29,39 **** @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { openPriceIndicator.getValue(10); } ! ! // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede ! // Linux) ! // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(OpenPriceIndicatorTest.class); --- 29,36 ---- @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { openPriceIndicator.getValue(10); } ! public static junit.framework.Test suite() { return new JUnit4TestAdapter(OpenPriceIndicatorTest.class); Index: VariationPriceIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/simple/VariationPriceIndicatorTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** VariationPriceIndicatorTest.java 19 May 2007 13:23:18 -0000 1.5 --- VariationPriceIndicatorTest.java 31 May 2007 16:45:40 -0000 1.6 *************** *** 31,41 **** @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { variationIndicator.getValue(10); } ! ! // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede ! // Linux) ! // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(VariationPriceIndicatorTest.class); --- 31,38 ---- @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { variationIndicator.getValue(10); } ! public static junit.framework.Test suite() { return new JUnit4TestAdapter(VariationPriceIndicatorTest.class); Index: MinPriceIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/simple/MinPriceIndicatorTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** MinPriceIndicatorTest.java 19 May 2007 13:23:18 -0000 1.7 --- MinPriceIndicatorTest.java 31 May 2007 16:45:40 -0000 1.8 *************** *** 29,39 **** @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { minPriceIndicator.getValue(10); } ! ! // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede ! // Linux) ! // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(MinPriceIndicatorTest.class); --- 29,36 ---- @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { minPriceIndicator.getValue(10); } ! public static junit.framework.Test suite() { return new JUnit4TestAdapter(MinPriceIndicatorTest.class); Index: ClosePriceIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/simple/ClosePriceIndicatorTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ClosePriceIndicatorTest.java 19 May 2007 13:23:18 -0000 1.7 --- ClosePriceIndicatorTest.java 31 May 2007 16:45:40 -0000 1.8 *************** *** 31,41 **** @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { closePrice.getValue(10); } ! ! // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede ! // Linux) ! // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(ClosePriceIndicatorTest.class); --- 31,38 ---- @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { closePrice.getValue(10); } ! public static junit.framework.Test suite() { return new JUnit4TestAdapter(ClosePriceIndicatorTest.class); Index: PreviousPriceIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/simple/PreviousPriceIndicatorTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PreviousPriceIndicatorTest.java 19 May 2007 13:23:18 -0000 1.7 --- PreviousPriceIndicatorTest.java 31 May 2007 16:45:40 -0000 1.8 *************** *** 30,40 **** @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { previousPriceIndicator.getValue(10); } ! ! // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede ! // Linux) ! // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(PreviousPriceIndicatorTest.class); --- 30,37 ---- @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { previousPriceIndicator.getValue(10); } ! public static junit.framework.Test suite() { return new JUnit4TestAdapter(PreviousPriceIndicatorTest.class); |
|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 16:45:40
|
Update of /cvsroot/tail/Tail/src/java/net/sf/tail In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2946/src/java/net/sf/tail Modified Files: Indicator.java Trade.java Tick.java Strategy.java Operation.java DefaultTimeSeries.java OperationType.java TimeSeries.java Log Message: Refatoração de testes Index: DefaultTimeSeries.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/DefaultTimeSeries.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DefaultTimeSeries.java 14 May 2007 16:30:18 -0000 1.1 --- DefaultTimeSeries.java 31 May 2007 16:45:40 -0000 1.2 *************** *** 3,6 **** --- 3,12 ---- import java.util.List; + /** + * Implementação default da interface {@link TimeSeries}. + * + * @author Marcio + * + */ public class DefaultTimeSeries implements TimeSeries { private List<Tick> ticks; Index: OperationType.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/OperationType.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OperationType.java 19 May 2007 14:18:14 -0000 1.2 --- OperationType.java 31 May 2007 16:45:40 -0000 1.3 *************** *** 1,4 **** --- 1,7 ---- package net.sf.tail; + /** + * Enum com os tipos de operações. + */ public enum OperationType { BUY, SELL; Index: Indicator.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/Indicator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Indicator.java 17 May 2007 23:06:56 -0000 1.3 --- Indicator.java 31 May 2007 16:45:40 -0000 1.4 *************** *** 1,4 **** --- 1,14 ---- package net.sf.tail; + /** + * Indicator é toda a classe que recebe um {@link TimeSeries} ou + * + * @link {@link Indicator} como parâmetro e retorna um valor interpretado T. + * + * + * @author Marcio + * + * @param <T> + */ public interface Indicator<T> { public T getValue(int index); Index: Tick.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/Tick.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Tick.java 17 May 2007 23:06:56 -0000 1.8 --- Tick.java 31 May 2007 16:45:40 -0000 1.9 *************** *** 3,6 **** --- 3,12 ---- import java.sql.Timestamp; + /** + * Contém todos os possÃveis atributos registrados de uma detrminada ação em um único perÃodo de tempo. + * + * @author Marcio + * + */ public class Tick { Index: Operation.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/Operation.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Operation.java 24 May 2007 21:20:28 -0000 1.5 --- Operation.java 31 May 2007 16:45:40 -0000 1.6 *************** *** 1,9 **** package net.sf.tail; public class Operation { private OperationType type; - private int index; public Operation(int index, OperationType type) { --- 1,20 ---- package net.sf.tail; + /** + * Operation é toda decisão tomada da classe {@link Strategy}. + * + * Contém um enum {@link OperationType} representando o tipo de operação e um + * + * int index em que a operação foi efetuada. + * + * + * @author original Kadu + * + */ public class Operation { private OperationType type; + private int index; public Operation(int index, OperationType type) { *************** *** 19,23 **** return index; } ! @Override public int hashCode() { --- 30,34 ---- return index; } ! @Override public int hashCode() { *************** *** 29,38 **** if (obj instanceof Operation) { Operation o = (Operation) obj; ! return type.equals(o.getType()) && ! (index == o.getIndex()); } return false; } ! @Override public String toString() { --- 40,48 ---- if (obj instanceof Operation) { Operation o = (Operation) obj; ! return type.equals(o.getType()) && (index == o.getIndex()); } return false; } ! @Override public String toString() { *************** *** 40,43 **** } - } --- 50,52 ---- Index: Trade.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/Trade.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Trade.java 24 May 2007 21:20:28 -0000 1.4 --- Trade.java 31 May 2007 16:45:40 -0000 1.5 *************** *** 1,4 **** --- 1,10 ---- package net.sf.tail; + /** + * Conjunto fechado de {@link Operation} disjuntas de uma única ação. + * + * @author Marcio + * + */ public class Trade { Index: TimeSeries.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/TimeSeries.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TimeSeries.java 17 May 2007 23:06:56 -0000 1.3 --- TimeSeries.java 31 May 2007 16:45:40 -0000 1.4 *************** *** 1,4 **** --- 1,10 ---- package net.sf.tail; + /** + * Time Series é um conjunto de {@link Tick} ordenados por um determinado perÃodo temporal. + * + * @author Marcio + * + */ public interface TimeSeries { Index: Strategy.java =================================================================== RCS file: /cvsroot/tail/Tail/src/java/net/sf/tail/Strategy.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Strategy.java 19 May 2007 12:37:56 -0000 1.1 --- Strategy.java 31 May 2007 16:45:40 -0000 1.2 *************** *** 1,7 **** --- 1,29 ---- package net.sf.tail; + /** + * Strategy é toda a classe que pode receber como parâmetro um {@link Indicator} ou uma outra Strategy, + * e retornar uma {@link Operation} dado um index. + * + */ public interface Strategy { + /** + * Retorna uma operação, caso seja necessária, recomendando uma determinação ação. + * + * Caso não haja ação recomendada, retorna null. + * + * @param index + * @return + */ Operation shouldEnter(int index); + + /** + * Retorna uma operação, caso seja necessária, recomendando uma determinação ação. + * + * Caso não haja ação recomendada, retorna null. + * + * @param index + * @return + */ Operation shouldExit(Operation entry, int index); |
|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 16:45:40
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/cache In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2946/src/test/net/sf/tail/indicator/cache Modified Files: CachedIndicatorTest.java Log Message: Refatoração de testes Index: CachedIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/cache/CachedIndicatorTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** CachedIndicatorTest.java 19 May 2007 13:23:22 -0000 1.3 --- CachedIndicatorTest.java 31 May 2007 16:45:41 -0000 1.4 *************** *** 53,57 **** @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { SMAIndicator quoteSMA = new SMAIndicator(new ClosePriceIndicator(data), 3); CachedIndicator cache = new CachedIndicator(quoteSMA); --- 53,57 ---- @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { SMAIndicator quoteSMA = new SMAIndicator(new ClosePriceIndicator(data), 3); CachedIndicator cache = new CachedIndicator(quoteSMA); *************** *** 59,65 **** } - // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede - // Linux) - // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(CachedIndicatorTest.class); --- 59,62 ---- |
|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 16:45:40
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/helper In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2946/src/test/net/sf/tail/indicator/helper Added Files: StandardDeviationIndicatorTest.java AverageLossIndicatorTest.java AverageGainIndicatorTest.java HighestValueIndicatorTest.java LowestValueIndicatorTest.java Log Message: Refatoração de testes --- NEW FILE: StandardDeviationIndicatorTest.java --- package net.sf.tail.indicator.helper; import static org.junit.Assert.assertEquals; import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.helper.StandardDeviationIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.sample.SampleTimeSeries; import org.junit.Before; import org.junit.Test; public class StandardDeviationIndicatorTest { private TimeSeries data; @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 4, 3, 0, 9 }); } @Test public void testStandardDeviationUsingTimeFrame4UsingClosePrice() throws Exception { StandardDeviationIndicator sdv = new StandardDeviationIndicator(new ClosePriceIndicator(data), 4); assertEquals(0d, sdv.getValue(0), 0.1); assertEquals(Math.sqrt(0.5), sdv.getValue(1), 0.1); assertEquals(Math.sqrt(2.0), sdv.getValue(2), 0.1); assertEquals(Math.sqrt(5.0), sdv.getValue(3), 0.1); assertEquals(Math.sqrt(2.0), sdv.getValue(4), 0.1); assertEquals(1, sdv.getValue(5), 0.1); assertEquals(Math.sqrt(2.0), sdv.getValue(6), 0.1); assertEquals(Math.sqrt(2.0), sdv.getValue(7), 0.1); assertEquals(Math.sqrt(2.0), sdv.getValue(8), 0.1); assertEquals(Math.sqrt(14.0), sdv.getValue(9), 0.1); assertEquals(Math.sqrt(42.0), sdv.getValue(10), 0.1); } @Test public void testFirstValueShouldBeZero() throws Exception { StandardDeviationIndicator sdv = new StandardDeviationIndicator(new ClosePriceIndicator(data), 4); assertEquals(0, sdv.getValue(0), 0.1); } @Test public void testStandardDeviationValueIndicatorValueWhenTimeFraseIs1ShouldBeZero() { StandardDeviationIndicator sdv = new StandardDeviationIndicator(new ClosePriceIndicator(data), 1); assertEquals(0d, sdv.getValue(3), 0.1); assertEquals(0d, sdv.getValue(8), 0.1); } @Test public void testStandardDeviationUsingTimeFrame2UsingClosePrice() throws Exception { StandardDeviationIndicator sdv = new StandardDeviationIndicator(new ClosePriceIndicator(data), 2); assertEquals(0d, sdv.getValue(0), 0.1); assertEquals(Math.sqrt(0.5), sdv.getValue(1), 0.1); assertEquals(Math.sqrt(0.5), sdv.getValue(2), 0.1); assertEquals(Math.sqrt(0.5), sdv.getValue(3), 0.1); assertEquals(Math.sqrt(4.5), sdv.getValue(9), 0.1); assertEquals(Math.sqrt(40.5), sdv.getValue(10), 0.1); } @Test(expected = IndexOutOfBoundsException.class) public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { StandardDeviationIndicator quoteSDV = new StandardDeviationIndicator(new ClosePriceIndicator(data), 3); quoteSDV.getValue(13); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(StandardDeviationIndicatorTest.class); } } --- NEW FILE: AverageLossIndicatorTest.java --- package net.sf.tail.indicator.helper; import static org.junit.Assert.assertEquals; import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.RSIIndicatorTest; import net.sf.tail.indicator.helper.AverageLossIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.sample.SampleTimeSeries; import org.junit.Before; import org.junit.Test; public class AverageLossIndicatorTest { private TimeSeries data; @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2 }); } @Test public void testAverageLossUsingTimeFrame5UsingClosePrice() throws Exception { AverageLossIndicator averageLoss = new AverageLossIndicator(new ClosePriceIndicator(data), 5); assertEquals(1d / 5d, averageLoss.getValue(5), 0.01); assertEquals(1d / 5d, averageLoss.getValue(6), 0.01); assertEquals(2d / 5d, averageLoss.getValue(7), 0.01); assertEquals(3d / 5d, averageLoss.getValue(8), 0.01); assertEquals(2d / 5d, averageLoss.getValue(9), 0.01); assertEquals(2d / 5d, averageLoss.getValue(10), 0.01); assertEquals(3d / 5d, averageLoss.getValue(11), 0.01); assertEquals(3d / 5d, averageLoss.getValue(12), 0.01); } @Test public void testAverageLossShouldWorkJumpingIndexes() { AverageLossIndicator averageLoss = new AverageLossIndicator(new ClosePriceIndicator(data), 5); assertEquals(2d / 5d, averageLoss.getValue(10), 0.01); assertEquals(3d / 5d, averageLoss.getValue(12), 0.01); } @Test public void testAverageLossMustReturnZeroWhenTheDataDoesntGain() { AverageLossIndicator averageLoss = new AverageLossIndicator(new ClosePriceIndicator(data), 4); assertEquals(0, averageLoss.getValue(3), 0.01); } @Test public void testAverageLossWhenTimeFrameIsGreaterThanIndex() { AverageLossIndicator averageLoss = new AverageLossIndicator(new ClosePriceIndicator(data), 1000); assertEquals(5d/data.getSize(), averageLoss.getValue(12), 0.01); } @Test public void testAverageGainWhenIndexIsZeroMustBeZero() { AverageLossIndicator averageLoss = new AverageLossIndicator(new ClosePriceIndicator(data), 10); assertEquals(0, averageLoss.getValue(0), 0.01); } @Test(expected = IndexOutOfBoundsException.class) public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { AverageLossIndicator averageLoss = new AverageLossIndicator(new ClosePriceIndicator(data), 5); assertEquals(3d, averageLoss.getValue(300)); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(RSIIndicatorTest.class); } } --- NEW FILE: AverageGainIndicatorTest.java --- package net.sf.tail.indicator.helper; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.RSIIndicatorTest; import net.sf.tail.indicator.helper.AverageGainIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.sample.SampleTimeSeries; import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; import junit.framework.JUnit4TestAdapter; public class AverageGainIndicatorTest { private TimeSeries data; @Before public void prepare() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2 }); } @Test public void testAverageGainUsingTimeFrame5UsingClosePrice() throws Exception { AverageGainIndicator averageGain = new AverageGainIndicator(new ClosePriceIndicator(data), 5); assertEquals(4d / 5d, averageGain.getValue(5), 0.01); assertEquals(4d / 5d, averageGain.getValue(6), 0.01); assertEquals(3d / 5d, averageGain.getValue(7), 0.01); assertEquals(2d / 5d, averageGain.getValue(8), 0.01); assertEquals(2d / 5d, averageGain.getValue(9), 0.01); assertEquals(2d / 5d, averageGain.getValue(10), 0.01); assertEquals(1d / 5d, averageGain.getValue(11), 0.01); assertEquals(1d / 5d, averageGain.getValue(12), 0.01); } @Test public void testAverageGainShouldWorkJumpingIndexes() { AverageGainIndicator averageGain = new AverageGainIndicator(new ClosePriceIndicator(data), 5); assertEquals(2d / 5d, averageGain.getValue(10), 0.01); assertEquals(1d / 5d, averageGain.getValue(12), 0.01); } @Test public void testAverageGainMustReturnZeroWhenTheDataDoesntGain() { AverageGainIndicator averageGain = new AverageGainIndicator(new ClosePriceIndicator(data), 3); assertEquals(0, averageGain.getValue(9), 0.01); } @Test public void testAverageGainWhenTimeFrameIsGreaterThanIndicatorDataShouldBeCalculatedWithDataSize() { AverageGainIndicator averageGain = new AverageGainIndicator(new ClosePriceIndicator(data), 1000); assertEquals(6d/data.getSize(), averageGain.getValue(12), 0.01); } @Test public void testAverageGainWhenIndexIsZeroMustBeZero() { AverageGainIndicator averageGain = new AverageGainIndicator(new ClosePriceIndicator(data), 10); assertEquals(0, averageGain.getValue(0), 0.01); } @Test(expected = IndexOutOfBoundsException.class) public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { AverageGainIndicator averageGain = new AverageGainIndicator(new ClosePriceIndicator(data), 5); assertEquals(3d, averageGain.getValue(300)); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(RSIIndicatorTest.class); } } --- NEW FILE: HighestValueIndicatorTest.java --- package net.sf.tail.indicator.helper; import static org.junit.Assert.assertEquals; import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.RSIIndicatorTest; import net.sf.tail.indicator.helper.HighestValueIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.sample.SampleTimeSeries; import org.junit.Before; import org.junit.Test; public class HighestValueIndicatorTest { private TimeSeries data; @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 6, 4, 3, 3, 4, 3, 2 }); } @Test public void testHighestValueUsingTimeFrame5UsingClosePrice() throws Exception { HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(4d, highestValue.getValue(4), 0.01); assertEquals(4d, highestValue.getValue(5), 0.01); assertEquals(5d, highestValue.getValue(6), 0.01); assertEquals(6d, highestValue.getValue(7), 0.01); assertEquals(6d, highestValue.getValue(8), 0.01); assertEquals(6d, highestValue.getValue(9), 0.01); assertEquals(6d, highestValue.getValue(10), 0.01); assertEquals(6d, highestValue.getValue(11), 0.01); assertEquals(4d, highestValue.getValue(12), 0.01); } @Test public void testFirstHighestValueIndicatorValueShouldBeEqualsToFirstDataValue() { HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(1d, highestValue.getValue(0), 0.01); } @Test public void testHighestValueIndicatorWhenTimeFrameIsGreaterThanIndex() { HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 500); assertEquals(6d, highestValue.getValue(12), 0.01); } @Test public void testHighestValueShouldWorkJumpingIndexes() { HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(5d, highestValue.getValue(6), 0.01); assertEquals(4, highestValue.getValue(12), 0.01); } @Test(expected = IndexOutOfBoundsException.class) public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(3d, highestValue.getValue(300)); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(RSIIndicatorTest.class); } } --- NEW FILE: LowestValueIndicatorTest.java --- package net.sf.tail.indicator.helper; import static org.junit.Assert.assertEquals; import junit.framework.JUnit4TestAdapter; import net.sf.tail.TimeSeries; import net.sf.tail.indicator.RSIIndicatorTest; import net.sf.tail.indicator.helper.LowestValueIndicator; import net.sf.tail.indicator.simple.ClosePriceIndicator; import net.sf.tail.sample.SampleTimeSeries; import org.junit.Before; import org.junit.Test; public class LowestValueIndicatorTest { private TimeSeries data; @Before public void setUp() throws Exception { data = new SampleTimeSeries(new double[] { 1, 2, 3, 4, 3, 4, 5, 6, 4, 3, 2, 4, 3, 1 }); } @Test public void testLowestValueIndicatorUsingTimeFrame5UsingClosePrice() throws Exception { LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(1d, lowestValue.getValue(4), 0.01); assertEquals(2d, lowestValue.getValue(5), 0.01); assertEquals(3d, lowestValue.getValue(6), 0.01); assertEquals(3d, lowestValue.getValue(7), 0.01); assertEquals(3d, lowestValue.getValue(8), 0.01); assertEquals(3d, lowestValue.getValue(9), 0.01); assertEquals(2d, lowestValue.getValue(10), 0.01); assertEquals(2d, lowestValue.getValue(11), 0.01); assertEquals(2d, lowestValue.getValue(12), 0.01); } @Test public void testLowestValueShouldWorkJumpingIndexes() { LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(2d, lowestValue.getValue(10), 0.01); assertEquals(3d, lowestValue.getValue(6), 0.01); } @Test public void testLowestValueIndicatorValueShouldBeEqualsToFirstDataValue() { LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(1d, lowestValue.getValue(0), 0.01); } @Test public void testLowestValueIndicatorWhenTimeFrameIsGreaterThanIndex() { LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(data), 500); assertEquals(1d, lowestValue.getValue(12), 0.01); } @Test(expected = IndexOutOfBoundsException.class) public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(data), 5); assertEquals(3d, lowestValue.getValue(300)); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(RSIIndicatorTest.class); } } |
|
From: Márcio V. d. S. <mv...@us...> - 2007-05-31 16:45:40
|
Update of /cvsroot/tail/Tail/src/test/net/sf/tail/indicator In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2946/src/test/net/sf/tail/indicator Modified Files: RSIIndicatorTest.java WilliamsRIndicatorTest.java EMAIndicatorTest.java SMAIndicatorTest.java Removed Files: AverageLossIndicatorTest.java HighestValueIndicatorTest.java LowestValueIndicatorTest.java AverageGainIndicatorTest.java StandardDeviationIndicatorTest.java Log Message: Refatoração de testes --- AverageLossIndicatorTest.java DELETED --- --- AverageGainIndicatorTest.java DELETED --- Index: WilliamsRIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/WilliamsRIndicatorTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** WilliamsRIndicatorTest.java 19 May 2007 13:13:30 -0000 1.5 --- WilliamsRIndicatorTest.java 31 May 2007 16:45:40 -0000 1.6 *************** *** 44,48 **** @Test ! public void testWR5() throws Exception { WilliamsRIndicator wr = new WilliamsRIndicator(new ClosePriceIndicator(data), 5, new MaxPriceIndicator(data), new MinPriceIndicator(data)); --- 44,48 ---- @Test ! public void testWilliamsRUsingTimeFrame5UsingClosePrice() throws Exception { WilliamsRIndicator wr = new WilliamsRIndicator(new ClosePriceIndicator(data), 5, new MaxPriceIndicator(data), new MinPriceIndicator(data)); *************** *** 59,63 **** @Test ! public void testWR10() { WilliamsRIndicator wr = new WilliamsRIndicator(new ClosePriceIndicator(data), 10, new MaxPriceIndicator(data), new MinPriceIndicator(data)); --- 59,71 ---- @Test ! public void testWilliamsRShouldWorkJumpingIndexes() { ! WilliamsRIndicator wr = new WilliamsRIndicator(new ClosePriceIndicator(data), 5, new MaxPriceIndicator(data), ! new MinPriceIndicator(data)); ! assertEquals(-13.95, wr.getValue(10), 0.01); ! assertEquals(-47.22, wr.getValue(4), 0.01); ! } ! ! @Test ! public void testWilliamsRUsingTimeFrame10UsingClosePrice() { WilliamsRIndicator wr = new WilliamsRIndicator(new ClosePriceIndicator(data), 10, new MaxPriceIndicator(data), new MinPriceIndicator(data)); *************** *** 82,86 **** @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { WilliamsRIndicator wr = new WilliamsRIndicator(new ClosePriceIndicator(data), 100, new MaxPriceIndicator(data), new MinPriceIndicator(data)); --- 90,94 ---- @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { WilliamsRIndicator wr = new WilliamsRIndicator(new ClosePriceIndicator(data), 100, new MaxPriceIndicator(data), new MinPriceIndicator(data)); *************** *** 88,94 **** } - // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede - // Linux) - // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(WilliamsRIndicatorTest.class); --- 96,99 ---- --- LowestValueIndicatorTest.java DELETED --- Index: RSIIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/RSIIndicatorTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RSIIndicatorTest.java 19 May 2007 13:23:21 -0000 1.6 --- RSIIndicatorTest.java 31 May 2007 16:45:40 -0000 1.7 *************** *** 23,27 **** @Test ! public void testRSI14() { RSIIndicator rsi = new RSIIndicator(new ClosePriceIndicator(data), 14); --- 23,27 ---- @Test ! public void testRSIUsingTimeFrame14UsingClosePrice() { RSIIndicator rsi = new RSIIndicator(new ClosePriceIndicator(data), 14); *************** *** 39,56 **** @Test ! public void test19daysJumping() { RSIIndicator rsi = new RSIIndicator(new ClosePriceIndicator(data), 14); assertEquals(73.33, rsi.getValue(19), 0.01); } @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { RSIIndicator rsi = new RSIIndicator(new ClosePriceIndicator(data), 14); assertEquals(3d, rsi.getValue(300)); } - // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede - // Linux) - // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(RSIIndicatorTest.class); --- 39,62 ---- @Test ! public void testRSIFirstValueShouldBeZero() { ! RSIIndicator rsi = new RSIIndicator(new ClosePriceIndicator(data), 14); ! ! assertEquals(0d, rsi.getValue(0), 0.01); ! } ! ! ! @Test ! public void testRSIShouldWorkJumpingIndexes() { RSIIndicator rsi = new RSIIndicator(new ClosePriceIndicator(data), 14); assertEquals(73.33, rsi.getValue(19), 0.01); + assertEquals(62.75, rsi.getValue(15), 0.01); } @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { RSIIndicator rsi = new RSIIndicator(new ClosePriceIndicator(data), 14); assertEquals(3d, rsi.getValue(300)); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(RSIIndicatorTest.class); --- StandardDeviationIndicatorTest.java DELETED --- Index: SMAIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/SMAIndicatorTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SMAIndicatorTest.java 19 May 2007 13:23:21 -0000 1.7 --- SMAIndicatorTest.java 31 May 2007 16:45:40 -0000 1.8 *************** *** 21,25 **** @Test ! public void testSMA3() throws Exception { SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 3); --- 21,25 ---- @Test ! public void testSMAUsingTimeFrame3UsingClosePrice() throws Exception { SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 3); *************** *** 41,45 **** @Test ! public void test3daysJumping() { SMAIndicator quoteSMA = new SMAIndicator(new ClosePriceIndicator(data), 3); assertEquals(3d, quoteSMA.getValue(12)); --- 41,53 ---- @Test ! public void testSMAWhenTimeFrameIs1ResultShouldBeIndicatorValue() { ! SMAIndicator quoteSMA = new SMAIndicator(new ClosePriceIndicator(data), 1); ! for (int i = 0; i < data.getSize(); i++) { ! assertEquals(data.getTick(i).getClosePrice(), quoteSMA.getValue(i)); ! } ! } ! ! @Test ! public void testSMAShouldWorkJumpingIndexes() { SMAIndicator quoteSMA = new SMAIndicator(new ClosePriceIndicator(data), 3); assertEquals(3d, quoteSMA.getValue(12)); *************** *** 47,58 **** @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { SMAIndicator quoteSMA = new SMAIndicator(new ClosePriceIndicator(data), 3); assertEquals(3d, quoteSMA.getValue(13)); } - // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede - // Linux) - // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(SMAIndicatorTest.class); --- 55,63 ---- @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { SMAIndicator quoteSMA = new SMAIndicator(new ClosePriceIndicator(data), 3); assertEquals(3d, quoteSMA.getValue(13)); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(SMAIndicatorTest.class); Index: EMAIndicatorTest.java =================================================================== RCS file: /cvsroot/tail/Tail/src/test/net/sf/tail/indicator/EMAIndicatorTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** EMAIndicatorTest.java 19 May 2007 13:23:21 -0000 1.8 --- EMAIndicatorTest.java 31 May 2007 16:45:40 -0000 1.9 *************** *** 26,34 **** @Test ! public void test10days() { EMAIndicator ema = new EMAIndicator(new ClosePriceIndicator(data), 10); SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 10); - // the start of an EMA must be equals to a SMA for (int i = 0; i < 9; i++) { sma.getValue(i); --- 26,49 ---- @Test ! public void testEMAUsingTimeFrame10UsingClosePrice() { ! EMAIndicator ema = new EMAIndicator(new ClosePriceIndicator(data), 10); ! ! assertEquals(63.65, ema.getValue(9), 0.01); ! assertEquals(63.23, ema.getValue(10), 0.01); ! assertEquals(62.91, ema.getValue(11), 0.01); ! } ! ! @Test ! public void testEMAFirstValueShouldBeEqualsToFirstDataValue() { ! EMAIndicator ema = new EMAIndicator(new ClosePriceIndicator(data), 10); ! ! assertEquals(64.75, ema.getValue(0), 0.01); ! } ! ! @Test ! public void testValuesLessThanTimeFrameMustBeEqualsToSMAValues() { EMAIndicator ema = new EMAIndicator(new ClosePriceIndicator(data), 10); SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 10); for (int i = 0; i < 9; i++) { sma.getValue(i); *************** *** 36,46 **** assertEquals(sma.getValue(i), ema.getValue(i)); } - assertEquals(63.65, ema.getValue(9), 0.01); - assertEquals(63.23, ema.getValue(10), 0.01); - assertEquals(62.91, ema.getValue(11), 0.01); } ! @Test ! public void test10daysJumping() { EMAIndicator ema = new EMAIndicator(new ClosePriceIndicator(data), 10); assertEquals(63.23, ema.getValue(10), 0.01); --- 51,58 ---- assertEquals(sma.getValue(i), ema.getValue(i)); } } ! @Test ! public void testEMAShouldWorkJumpingIndexes() { EMAIndicator ema = new EMAIndicator(new ClosePriceIndicator(data), 10); assertEquals(63.23, ema.getValue(10), 0.01); *************** *** 48,59 **** @Test(expected = IndexOutOfBoundsException.class) ! public void testWrongIndex() { EMAIndicator ema = new EMAIndicator(new ClosePriceIndicator(data), 10); assertEquals(3d, ema.getValue(14)); } - // Método adicionado por causa da compatibilidade do Eclipse 3.1.2(Rede - // Linux) - // e o JUnit4 public static junit.framework.Test suite() { return new JUnit4TestAdapter(EMAIndicatorTest.class); --- 60,68 ---- @Test(expected = IndexOutOfBoundsException.class) ! public void testIndexGreatterThanTheIndicatorLenghtShouldThrowException() { EMAIndicator ema = new EMAIndicator(new ClosePriceIndicator(data), 10); assertEquals(3d, ema.getValue(14)); } public static junit.framework.Test suite() { return new JUnit4TestAdapter(EMAIndicatorTest.class); --- HighestValueIndicatorTest.java DELETED --- |