Search in sources :

Example 1 with SecurityPrice

use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.

the class SecurityBuilder method addPrice.

public SecurityBuilder addPrice(String date, long price) {
    SecurityPrice p = new SecurityPrice(LocalDate.parse(date), price);
    security.addPrice(p);
    return this;
}
Also used : SecurityPrice(name.abuchen.portfolio.model.SecurityPrice)

Example 2 with SecurityPrice

use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.

the class SecurityBuilder method generatePrices.

public SecurityBuilder generatePrices(long startPrice, LocalDate start, LocalDate end) {
    security.addPrice(new SecurityPrice(start, startPrice));
    Random random = new Random();
    LocalDate date = start;
    long price = startPrice;
    while (date.compareTo(end) < 0) {
        date = date.plusDays(1);
        if (date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY)
            continue;
        price = (long) ((double) price * ((random.nextDouble() * 0.2 - 0.1d) + 1));
        security.addPrice(new SecurityPrice(date, price));
    }
    return this;
}
Also used : Random(java.util.Random) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) LocalDate(java.time.LocalDate)

Example 3 with SecurityPrice

use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.

the class YahooFinanceQuoteFeed method updateHistoricalQuotes.

@Override
public final boolean updateHistoricalQuotes(Security security, List<Exception> errors) {
    LocalDate start = caculateStart(security);
    List<SecurityPrice> quotes = internalGetQuotes(SecurityPrice.class, security, start, errors);
    boolean isUpdated = false;
    if (quotes != null) {
        for (SecurityPrice p : quotes) {
            boolean isAdded = security.addPrice(p);
            isUpdated = isUpdated || isAdded;
        }
    }
    return isUpdated;
}
Also used : LatestSecurityPrice(name.abuchen.portfolio.model.LatestSecurityPrice) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) LocalDate(java.time.LocalDate)

Example 4 with SecurityPrice

use of name.abuchen.portfolio.model.SecurityPrice 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)

Example 5 with SecurityPrice

use of name.abuchen.portfolio.model.SecurityPrice in project portfolio by buchen.

the class ClientPerformanceSnapshotTest method testCapitalGains.

@Test
public void testCapitalGains() {
    Client client = new Client();
    Security security = new Security();
    security.addPrice(new SecurityPrice(LocalDate.of(2010, Month.JANUARY, 1), Values.Quote.factorize(100)));
    security.addPrice(new SecurityPrice(LocalDate.of(2011, Month.JUNE, 1), Values.Quote.factorize(110)));
    client.addSecurity(security);
    Portfolio portfolio = new Portfolio();
    portfolio.setReferenceAccount(new Account());
    portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 1_00, security, Values.Share.factorize(10), PortfolioTransaction.Type.BUY, 0, 0));
    client.addPortfolio(portfolio);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1000_00)));
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 0)));
    assertThat(snapshot.getValue(CategoryType.CAPITAL_GAINS), is(Money.of(CurrencyUnit.EUR, 100_00)));
    assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1100_00)));
    assertThat(snapshot.getAbsoluteDelta(), is(snapshot.getValue(CategoryType.FINAL_VALUE).subtract(snapshot.getValue(CategoryType.TRANSFERS)).subtract(snapshot.getValue(CategoryType.INITIAL_VALUE))));
}
Also used : Account(name.abuchen.portfolio.model.Account) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Aggregations

SecurityPrice (name.abuchen.portfolio.model.SecurityPrice)52 Security (name.abuchen.portfolio.model.Security)34 LocalDate (java.time.LocalDate)24 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)22 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)20 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)15 LatestSecurityPrice (name.abuchen.portfolio.model.LatestSecurityPrice)11 Client (name.abuchen.portfolio.model.Client)10 List (java.util.List)7 Values (name.abuchen.portfolio.money.Values)6 OpenDialogAction (name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction)6 MessageFormat (java.text.MessageFormat)5 BiFunction (java.util.function.BiFunction)5 Function (java.util.function.Function)5 Collectors (java.util.stream.Collectors)5 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)5 Taxonomy (name.abuchen.portfolio.model.Taxonomy)5 Watchlist (name.abuchen.portfolio.model.Watchlist)5 Factory (name.abuchen.portfolio.online.Factory)5