Search in sources :

Example 1 with Quote

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;
}
Also used : Quote(name.abuchen.portfolio.money.Quote) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) LocalDate(java.time.LocalDate)

Aggregations

LocalDate (java.time.LocalDate)1 LatestSecurityPrice (name.abuchen.portfolio.model.LatestSecurityPrice)1 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)1 SecurityPrice (name.abuchen.portfolio.model.SecurityPrice)1 Transaction (name.abuchen.portfolio.model.Transaction)1 Quote (name.abuchen.portfolio.money.Quote)1