org.jfree.data.time.MovingAverage Java Examples

The following examples show how to use org.jfree.data.time.MovingAverage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MovingAverageTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for the values calculated from a time series.
 */
public void test1() {
    TimeSeries source = createDailyTimeSeries1();
    TimeSeries maverage = MovingAverage.createMovingAverage(
        source, "Moving Average", 3, 3
    );

    // the moving average series has 7 items, the first three
    // days (11, 12, 13 August are skipped)
    assertEquals(7, maverage.getItemCount());
    double value = maverage.getValue(0).doubleValue();
    assertEquals(14.1, value, EPSILON);
    value = maverage.getValue(1).doubleValue();
    assertEquals(13.4, value, EPSILON);
    value = maverage.getValue(2).doubleValue();
    assertEquals(14.433333333333, value, EPSILON);
    value = maverage.getValue(3).doubleValue();
    assertEquals(14.933333333333, value, EPSILON);
    value = maverage.getValue(4).doubleValue();
    assertEquals(19.8, value, EPSILON);
    value = maverage.getValue(5).doubleValue();
    assertEquals(15.25, value, EPSILON);
    value = maverage.getValue(6).doubleValue();
    assertEquals(12.5, value, EPSILON);
}
 
Example #2
Source File: MovingAverageTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for the values calculated from a time series.
 */
public void test1() {
    TimeSeries source = createDailyTimeSeries1();
    TimeSeries maverage = MovingAverage.createMovingAverage(
        source, "Moving Average", 3, 3
    );
    
    // the moving average series has 7 items, the first three 
    // days (11, 12, 13 August are skipped)
    assertEquals(7, maverage.getItemCount());
    double value = maverage.getValue(0).doubleValue();
    assertEquals(14.1, value, EPSILON);
    value = maverage.getValue(1).doubleValue();
    assertEquals(13.4, value, EPSILON);
    value = maverage.getValue(2).doubleValue();
    assertEquals(14.433333333333, value, EPSILON);
    value = maverage.getValue(3).doubleValue();
    assertEquals(14.933333333333, value, EPSILON);
    value = maverage.getValue(4).doubleValue();
    assertEquals(19.8, value, EPSILON);
    value = maverage.getValue(5).doubleValue();
    assertEquals(15.25, value, EPSILON);
    value = maverage.getValue(6).doubleValue();
    assertEquals(12.5, value, EPSILON);
}