use of name.abuchen.portfolio.money.Quote in project portfolio by buchen.
the class QuoteFromTransactionExtractor method extractQuotes.
/**
* Extracts the quotes for the given {@link Security}.
*
* @param security
* {@link Security}
* @return true if quotes were found, else false
*/
public boolean extractQuotes(Security security) {
boolean bChanges = false;
SecurityPrice pLatest = null;
// walk through all all transactions for securiy
for (TransactionPair<?> p : security.getTransactions(client)) {
Transaction t = p.getTransaction();
// check the type of the transaction
if (t instanceof PortfolioTransaction) {
PortfolioTransaction pt = (PortfolioTransaction) t;
// get date and quote and build a price from it
Quote q = pt.getGrossPricePerShare();
LocalDate d = pt.getDateTime().toLocalDate();
SecurityPrice price = new SecurityPrice(d, q.getAmount());
bChanges |= security.addPrice(price);
// remember the lates price
if ((pLatest == null) || d.isAfter(pLatest.getDate())) {
pLatest = price;
}
}
}
// set the latest price (if at leas one price was found)
if (pLatest != null) {
LatestSecurityPrice lsp = new LatestSecurityPrice(pLatest.getDate(), pLatest.getValue());
bChanges |= security.setLatest(lsp);
}
return bChanges;
}
Aggregations