Search in sources :

Example 1 with SimpleMovingAverage

use of name.abuchen.portfolio.ui.views.SimpleMovingAverage in project portfolio by buchen.

the class SimpleMovingAverageTest method testSecurityHasOnlyOnePrice.

@Test
public void testSecurityHasOnlyOnePrice() {
    ChartLineSeriesAxes SMALines = new SimpleMovingAverage(200, this.securityOnePrice, null).getSMA();
    assertThat(SMALines.getDates(), is(IsNull.nullValue()));
}
Also used : ChartLineSeriesAxes(name.abuchen.portfolio.ui.views.ChartLineSeriesAxes) SimpleMovingAverage(name.abuchen.portfolio.ui.views.SimpleMovingAverage) Test(org.junit.Test)

Example 2 with SimpleMovingAverage

use of name.abuchen.portfolio.ui.views.SimpleMovingAverage in project portfolio by buchen.

the class SimpleMovingAverageTest method testCorrectSMAEntries.

@Test
public void testCorrectSMAEntries() {
    ChartLineSeriesAxes SMALines = new SimpleMovingAverage(10, this.securityTenPrices, null).getSMA();
    assertThat(SMALines, is(IsNull.notNullValue()));
    assertThat(SMALines.getValues().length, is(1));
    assertThat(SMALines.getValues()[0], is((1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / Values.Quote.divider() / 10));
}
Also used : ChartLineSeriesAxes(name.abuchen.portfolio.ui.views.ChartLineSeriesAxes) SimpleMovingAverage(name.abuchen.portfolio.ui.views.SimpleMovingAverage) Test(org.junit.Test)

Example 3 with SimpleMovingAverage

use of name.abuchen.portfolio.ui.views.SimpleMovingAverage in project portfolio by buchen.

the class SimpleMovingAverageTest method testSecurityIsNull.

@Test
public void testSecurityIsNull() {
    ChartLineSeriesAxes SMALines = new SimpleMovingAverage(200, null, null).getSMA();
    assertThat(SMALines.getDates(), is(IsNull.nullValue()));
}
Also used : ChartLineSeriesAxes(name.abuchen.portfolio.ui.views.ChartLineSeriesAxes) SimpleMovingAverage(name.abuchen.portfolio.ui.views.SimpleMovingAverage) Test(org.junit.Test)

Example 4 with SimpleMovingAverage

use of name.abuchen.portfolio.ui.views.SimpleMovingAverage in project portfolio by buchen.

the class SimpleMovingAverageTest method testSufficientPriceDataPass.

@Test
public void testSufficientPriceDataPass() {
    Security security = new Security();
    LocalDate date = LocalDate.parse("2016-01-01");
    for (int ii = 0; ii < 300; ii++) {
        security.addPrice(new SecurityPrice(date, Values.Quote.factorize(10)));
        date = date.plusDays(1);
    }
    ChartLineSeriesAxes SMALines = new SimpleMovingAverage(10, security, null).getSMA();
    assertThat(SMALines, is(IsNull.notNullValue()));
    assertThat(SMALines.getValues().length, is(security.getPrices().size() - 10 + 1));
}
Also used : ChartLineSeriesAxes(name.abuchen.portfolio.ui.views.ChartLineSeriesAxes) SimpleMovingAverage(name.abuchen.portfolio.ui.views.SimpleMovingAverage) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Security(name.abuchen.portfolio.model.Security) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 5 with SimpleMovingAverage

use of name.abuchen.portfolio.ui.views.SimpleMovingAverage in project portfolio by buchen.

the class SimpleMovingAverageTest method testSecurityHasSparsePrice.

@Test
public void testSecurityHasSparsePrice() {
    Security security = new Security();
    LocalDate date = LocalDate.parse("2016-01-01");
    for (int ii = 0; ii < 100; ii++) {
        security.addPrice(new SecurityPrice(date, Values.Quote.factorize(10)));
        date = date.plusDays(1);
    }
    security.addPrice(new SecurityPrice(LocalDate.parse("2017-01-01"), Values.Quote.factorize(12)));
    LocalDate tmp = LocalDate.parse("2016-01-01");
    tmp = tmp.plusDays(99);
    Date lastSMADate = java.sql.Date.valueOf(tmp);
    ChartLineSeriesAxes SMALines = new SimpleMovingAverage(10, security, null).getSMA();
    assertThat(SMALines.getDates(), is(IsNull.notNullValue()));
    assertThat(SMALines.getDates()[SMALines.getDates().length - 1], is(lastSMADate));
}
Also used : ChartLineSeriesAxes(name.abuchen.portfolio.ui.views.ChartLineSeriesAxes) SimpleMovingAverage(name.abuchen.portfolio.ui.views.SimpleMovingAverage) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Security(name.abuchen.portfolio.model.Security) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Aggregations

ChartLineSeriesAxes (name.abuchen.portfolio.ui.views.ChartLineSeriesAxes)6 SimpleMovingAverage (name.abuchen.portfolio.ui.views.SimpleMovingAverage)6 Test (org.junit.Test)6 LocalDate (java.time.LocalDate)3 Security (name.abuchen.portfolio.model.Security)3 SecurityPrice (name.abuchen.portfolio.model.SecurityPrice)3 Date (java.util.Date)2