Search in sources :

Example 71 with ClosePriceIndicator

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));
}
Also used : ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 72 with ClosePriceIndicator

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);
}
Also used : ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 73 with ClosePriceIndicator

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);
}
Also used : ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 74 with ClosePriceIndicator

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);
}
Also used : ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 75 with ClosePriceIndicator

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));
}
Also used : SMAIndicator(org.ta4j.core.indicators.SMAIndicator) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) UnderIndicatorRule(org.ta4j.core.trading.rules.UnderIndicatorRule) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator)

Aggregations

ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)81 Test (org.junit.Test)55 MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)26 TimeSeries (org.ta4j.core.TimeSeries)16 Before (org.junit.Before)14 SMAIndicator (org.ta4j.core.indicators.SMAIndicator)7 OverIndicatorRule (org.ta4j.core.trading.rules.OverIndicatorRule)6 ArrayList (java.util.ArrayList)5 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)5 MockBar (org.ta4j.core.mocks.MockBar)5 UnderIndicatorRule (org.ta4j.core.trading.rules.UnderIndicatorRule)5 SimpleDateFormat (java.text.SimpleDateFormat)4 JFreeChart (org.jfree.chart.JFreeChart)4 DateAxis (org.jfree.chart.axis.DateAxis)4 XYPlot (org.jfree.chart.plot.XYPlot)4 EMAIndicator (org.ta4j.core.indicators.EMAIndicator)4 CrossedDownIndicatorRule (org.ta4j.core.trading.rules.CrossedDownIndicatorRule)4 BaseStrategy (org.ta4j.core.BaseStrategy)3 Decimal (org.ta4j.core.Decimal)3 MaxPriceIndicator (org.ta4j.core.indicators.helpers.MaxPriceIndicator)3