use of name.abuchen.portfolio.model.LatestSecurityPrice in project portfolio by buchen.
the class YahooFinanceQuoteFeedTest method testParsingHistoricalQuotes.
@Test
public void testParsingHistoricalQuotes() throws IOException {
String responseBody = null;
try (Scanner scanner = new Scanner(getClass().getResourceAsStream("response_yahoo_historical.txt"), "UTF-8")) {
responseBody = scanner.useDelimiter("\\A").next();
}
Security security = new Security();
security.setTickerSymbol("DAI.DE");
YahooFinanceQuoteFeed feed = new YahooFinanceQuoteFeed();
List<LatestSecurityPrice> prices = feed.getHistoricalQuotes(responseBody, new ArrayList<Exception>());
Collections.sort(prices, new SecurityPrice.ByDate());
assertThat(prices.size(), is(2257));
LatestSecurityPrice price = new //
LatestSecurityPrice(//
LocalDate.of(2003, Month.JANUARY, 1), //
Values.Quote.factorize(29.35), //
Values.Quote.factorize(29.35), //
Values.Quote.factorize(29.35), 0);
assertThat(prices.get(0), equalTo(price));
price = new //
LatestSecurityPrice(//
LocalDate.of(2011, Month.SEPTEMBER, 22), //
Values.Quote.factorize(32.74), //
Values.Quote.factorize(34.16), //
Values.Quote.factorize(32.35), 10825200);
assertThat(prices.get(prices.size() - 1), equalTo(price));
}
use of name.abuchen.portfolio.model.LatestSecurityPrice in project portfolio by buchen.
the class SecuritiesTable method addDeltaColumn.
private // NOSONAR
void addDeltaColumn() {
Column column;
// $NON-NLS-1$
column = new Column("5", Messages.ColumnChangeOnPrevious, SWT.RIGHT, 60);
column.setMenuLabel(Messages.ColumnChangeOnPrevious_MenuLabel);
column.setLabelProvider(new NumberColorLabelProvider<>(Values.Percent2, element -> {
SecurityPrice price = ((Security) element).getSecurityPrice(LocalDate.now());
if (!(price instanceof LatestSecurityPrice))
return null;
LatestSecurityPrice latest = (LatestSecurityPrice) price;
if (latest.getPreviousClose() == LatestSecurityPrice.NOT_AVAILABLE)
return null;
return (latest.getValue() - latest.getPreviousClose()) / (double) latest.getPreviousClose();
}));
column.setSorter(ColumnViewerSorter.create((o1, o2) -> {
// NOSONAR
SecurityPrice p1 = ((Security) o1).getSecurityPrice(LocalDate.now());
SecurityPrice p2 = ((Security) o2).getSecurityPrice(LocalDate.now());
if (!(p1 instanceof LatestSecurityPrice))
p1 = null;
if (!(p2 instanceof LatestSecurityPrice))
p2 = null;
if (p1 == null)
return p2 == null ? 0 : -1;
if (p2 == null)
return 1;
LatestSecurityPrice l1 = (LatestSecurityPrice) p1;
LatestSecurityPrice l2 = (LatestSecurityPrice) p2;
double v1 = ((double) (l1.getValue() - l1.getPreviousClose())) / l1.getPreviousClose() * 100;
double v2 = ((double) (l2.getValue() - l2.getPreviousClose())) / l2.getPreviousClose() * 100;
return Double.compare(v1, v2);
}));
support.addColumn(column);
}
use of name.abuchen.portfolio.model.LatestSecurityPrice in project portfolio by buchen.
the class YahooFinanceQuoteFeedTest method testParsingHistoricalAdjustedCloseQuotes.
@Test
public void testParsingHistoricalAdjustedCloseQuotes() throws IOException {
String responseBody = null;
try (Scanner scanner = new Scanner(getClass().getResourceAsStream("response_yahoo_historical.txt"), "UTF-8")) {
responseBody = scanner.useDelimiter("\\A").next();
}
Security security = new Security();
security.setTickerSymbol("DAI.DE");
YahooFinanceAdjustedCloseQuoteFeed feed = new YahooFinanceAdjustedCloseQuoteFeed();
List<LatestSecurityPrice> prices = feed.getHistoricalQuotes(responseBody, new ArrayList<Exception>());
Collections.sort(prices, new SecurityPrice.ByDate());
assertThat(prices.size(), is(2257));
LatestSecurityPrice price = new //
LatestSecurityPrice(//
LocalDate.of(2003, Month.JANUARY, 1), //
Values.Quote.factorize(22.55), //
Values.Quote.factorize(29.35), //
Values.Quote.factorize(29.35), 0);
assertThat(prices.get(0), equalTo(price));
price = new //
LatestSecurityPrice(//
LocalDate.of(2011, Month.SEPTEMBER, 22), //
Values.Quote.factorize(32.74), //
Values.Quote.factorize(34.16), //
Values.Quote.factorize(32.35), 10825200);
assertThat(prices.get(prices.size() - 1), equalTo(price));
}
use of name.abuchen.portfolio.model.LatestSecurityPrice in project portfolio by buchen.
the class ImportQuotesWizard method performFinish.
@Override
public boolean performFinish() {
List<LatestSecurityPrice> quotes = reviewPage.getQuotes();
for (LatestSecurityPrice p : quotes) {
SecurityPrice quote = new SecurityPrice(p.getDate(), p.getValue());
security.addPrice(quote);
}
return true;
}
use of name.abuchen.portfolio.model.LatestSecurityPrice in project portfolio by buchen.
the class HTMLTableQuoteFeed method updateHistoricalQuotes.
@Override
public boolean updateHistoricalQuotes(Security security, List<Exception> errors) {
List<LatestSecurityPrice> quotes = internalGetQuotes(security, security.getFeedURL(), errors);
boolean isUpdated = false;
for (LatestSecurityPrice quote : quotes) {
boolean isAdded = security.addPrice(new SecurityPrice(quote.getDate(), quote.getValue()));
isUpdated = isUpdated || isAdded;
}
return isUpdated;
}
Aggregations