use of org.ta4j.core.indicators.helpers.ClosePriceIndicator in project ta4j by ta4j.
the class StandardDeviationIndicatorTest method standardDeviationUsingTimeFrame4UsingClosePrice.
@Test
public void standardDeviationUsingTimeFrame4UsingClosePrice() {
StandardDeviationIndicator sdv = new StandardDeviationIndicator(new ClosePriceIndicator(data), 4);
assertDecimalEquals(sdv.getValue(0), 0);
assertDecimalEquals(sdv.getValue(1), Math.sqrt(0.25));
assertDecimalEquals(sdv.getValue(2), Math.sqrt(2.0 / 3));
assertDecimalEquals(sdv.getValue(3), Math.sqrt(1.25));
assertDecimalEquals(sdv.getValue(4), Math.sqrt(0.5));
assertDecimalEquals(sdv.getValue(5), Math.sqrt(0.25));
assertDecimalEquals(sdv.getValue(6), Math.sqrt(0.5));
assertDecimalEquals(sdv.getValue(7), Math.sqrt(0.5));
assertDecimalEquals(sdv.getValue(8), Math.sqrt(0.5));
assertDecimalEquals(sdv.getValue(9), Math.sqrt(3.5));
assertDecimalEquals(sdv.getValue(10), Math.sqrt(10.5));
}
use of org.ta4j.core.indicators.helpers.ClosePriceIndicator in project ta4j by ta4j.
the class StandardErrorIndicatorTest method shouldBeZeroWhenTimeFrameIs1.
@Test
public void shouldBeZeroWhenTimeFrameIs1() {
StandardErrorIndicator se = new StandardErrorIndicator(new ClosePriceIndicator(data), 1);
assertDecimalEquals(se.getValue(1), 0);
assertDecimalEquals(se.getValue(3), 0);
}
use of org.ta4j.core.indicators.helpers.ClosePriceIndicator in project ta4j by ta4j.
the class StandardErrorIndicatorTest method usingTimeFrame5UsingClosePrice.
@Test
public void usingTimeFrame5UsingClosePrice() {
StandardErrorIndicator se = new StandardErrorIndicator(new ClosePriceIndicator(data), 5);
assertDecimalEquals(se.getValue(0), 0);
assertDecimalEquals(se.getValue(1), 3.5355);
assertDecimalEquals(se.getValue(2), 4.714);
assertDecimalEquals(se.getValue(3), 5.5902);
assertDecimalEquals(se.getValue(4), 6.3246);
assertDecimalEquals(se.getValue(5), 4.5607);
assertDecimalEquals(se.getValue(6), 2.8284);
assertDecimalEquals(se.getValue(7), 2.1909);
assertDecimalEquals(se.getValue(8), 2.1909);
assertDecimalEquals(se.getValue(9), 2.8284);
assertDecimalEquals(se.getValue(10), 4.5607);
assertDecimalEquals(se.getValue(11), 6.3246);
}
use of org.ta4j.core.indicators.helpers.ClosePriceIndicator in project ta4j by ta4j.
the class VarianceIndicatorTest method varianceShouldBeZeroWhenTimeFrameIs1.
@Test
public void varianceShouldBeZeroWhenTimeFrameIs1() {
VarianceIndicator var = new VarianceIndicator(new ClosePriceIndicator(data), 1);
assertDecimalEquals(var.getValue(3), 0);
assertDecimalEquals(var.getValue(8), 0);
}
use of org.ta4j.core.indicators.helpers.ClosePriceIndicator in project ta4j by ta4j.
the class TradingBotOnMovingTimeSeries method buildStrategy.
/**
* @param series a time series
* @return a dummy strategy
*/
private static Strategy buildStrategy(TimeSeries series) {
if (series == null) {
throw new IllegalArgumentException("Series cannot be null");
}
ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
SMAIndicator sma = new SMAIndicator(closePrice, 12);
// Sell when close price goes over SMA
return new BaseStrategy(new OverIndicatorRule(sma, closePrice), new UnderIndicatorRule(sma, closePrice));
}
Aggregations