Update of /cvsroot/tail/Tail/src/java/net/sf/tail/strategy
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv11076/src/java/net/sf/tail/strategy
Added Files:
DistanceBetweenIndicatorsStrategy.java
Log Message:
Estratégia de diferença entre indicadores e seu teste.
--- NEW FILE: DistanceBetweenIndicatorsStrategy.java ---
package net.sf.tail.strategy;
import net.sf.tail.Indicator;
import net.sf.tail.Operation;
import net.sf.tail.OperationType;
import net.sf.tail.Strategy;
/**
*
* 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 {
private Indicator<? extends Number> upper;
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;
this.distance = distance;
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);
}
return null;
}
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;
}
}
|