Search in sources :

Example 36 with Account

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

the class DividendsViewModel method calculate.

private void calculate() {
    // determine the number of full months within period
    LocalDate now = LocalDate.now();
    if (startYear > now.getYear())
        throw new IllegalArgumentException();
    this.noOfmonths = (now.getYear() - startYear) * 12 + now.getMonthValue();
    Predicate<Transaction> predicate = new ReportingPeriod.FromXtoY(LocalDate.of(startYear - 1, Month.DECEMBER, 31), now).containsTransaction();
    Map<InvestmentVehicle, Line> vehicle2line = new HashMap<>();
    this.sum = new Line(null, this.noOfmonths);
    this.transactions = new ArrayList<>();
    Client filteredClient = clientFilter.getSelectedFilter().filter(client);
    for (Account account : filteredClient.getAccounts()) {
        for (AccountTransaction t : account.getTransactions()) {
            if (t.getType() != AccountTransaction.Type.DIVIDENDS)
                continue;
            if (!predicate.test(t))
                continue;
            transactions.add(new TransactionPair<>(account, t));
            Money dividendValue = useGrossValue ? t.getGrossValue() : t.getMonetaryAmount();
            long value = dividendValue.with(converter.at(t.getDateTime())).getAmount();
            int index = (t.getDateTime().getYear() - startYear) * 12 + t.getDateTime().getMonthValue() - 1;
            Line line = vehicle2line.computeIfAbsent(t.getSecurity(), s -> new Line(s, noOfmonths));
            line.values[index] += value;
            line.sum += value;
            sum.values[index] += value;
            sum.sum += value;
        }
    }
    this.lines = new ArrayList<>(vehicle2line.values());
}
Also used : Account(name.abuchen.portfolio.model.Account) HashMap(java.util.HashMap) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) LocalDate(java.time.LocalDate) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Money(name.abuchen.portfolio.money.Money) Transaction(name.abuchen.portfolio.model.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) Client(name.abuchen.portfolio.model.Client)

Example 37 with Account

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

the class TaxonomyModel method addUnassigned.

private void addUnassigned(Client client) {
    for (Security security : client.getSecurities()) {
        Assignment assignment = new Assignment(security);
        assignment.setWeight(0);
        investmentVehicle2weight.put(security, assignment);
    }
    for (Account account : client.getAccounts()) {
        Assignment assignment = new Assignment(account);
        assignment.setWeight(0);
        investmentVehicle2weight.put(account, assignment);
    }
    visitAll(node -> {
        if (!(node instanceof AssignmentNode))
            return;
        Assignment assignment = node.getAssignment();
        Assignment count = investmentVehicle2weight.get(assignment.getInvestmentVehicle());
        count.setWeight(count.getWeight() + assignment.getWeight());
    });
    List<Assignment> unassigned = new ArrayList<>();
    for (Assignment assignment : investmentVehicle2weight.values()) {
        if (assignment.getWeight() >= Classification.ONE_HUNDRED_PERCENT)
            continue;
        Assignment a = new Assignment(assignment.getInvestmentVehicle());
        a.setWeight(Classification.ONE_HUNDRED_PERCENT - assignment.getWeight());
        unassigned.add(a);
        assignment.setWeight(Classification.ONE_HUNDRED_PERCENT);
    }
    Collections.sort(unassigned, (o1, o2) -> o1.getInvestmentVehicle().toString().compareToIgnoreCase(o2.getInvestmentVehicle().toString()));
    for (Assignment assignment : unassigned) unassignedNode.addChild(assignment);
}
Also used : Assignment(name.abuchen.portfolio.model.Classification.Assignment) Account(name.abuchen.portfolio.model.Account) AssignmentNode(name.abuchen.portfolio.ui.views.taxonomy.TaxonomyNode.AssignmentNode) ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security)

Example 38 with Account

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

the class DataSeriesSet method buildCommonDataSeries.

private void buildCommonDataSeries(Client client, IPreferenceStore preferences, ColorWheel wheel) {
    int index = client.getSecurities().size();
    for (Security security : client.getSecurities()) {
        // as equity data series (only as benchmark)
        if (security.getCurrencyCode() == null)
            continue;
        availableSeries.add(new // 
        DataSeries(// 
        DataSeries.Type.SECURITY, // 
        security, // 
        security.getName(), wheel.getRGB(index++)));
    }
    for (Portfolio portfolio : client.getPortfolios()) availableSeries.add(new // 
    DataSeries(// 
    DataSeries.Type.PORTFOLIO, // 
    portfolio, // 
    portfolio.getName(), wheel.getRGB(index++)));
    // portfolio + reference account
    for (Portfolio portfolio : client.getPortfolios()) {
        DataSeries series = new DataSeries(DataSeries.Type.PORTFOLIO_PLUS_ACCOUNT, portfolio, // $NON-NLS-1$
        portfolio.getName() + " + " + portfolio.getReferenceAccount().getName(), wheel.getRGB(index++));
        availableSeries.add(series);
    }
    // custom client filters
    ClientFilterMenu menu = new ClientFilterMenu(client, preferences);
    // quick fix: users can create duplicate client filters that end up to
    // have the same UUID. Avoid adding both violates the precondition that
    // every data series must have a unique id
    Set<String> addedSeries = new HashSet<>();
    for (ClientFilterMenu.Item item : menu.getCustomItems()) {
        DataSeries series = new DataSeries(DataSeries.Type.CLIENT_FILTER, item, item.getLabel(), wheel.getRGB(index++));
        if (addedSeries.add(series.getUUID()))
            availableSeries.add(series);
    }
    for (Account account : client.getAccounts()) availableSeries.add(new DataSeries(DataSeries.Type.ACCOUNT, account, account.getName(), wheel.getRGB(index++)));
    for (Taxonomy taxonomy : client.getTaxonomies()) {
        taxonomy.foreach(new Taxonomy.Visitor() {

            @Override
            public void visit(Classification classification) {
                if (classification.getParent() == null)
                    return;
                availableSeries.add(new DataSeries(DataSeries.Type.CLASSIFICATION, classification, classification.getName(), Colors.toRGB(classification.getColor())));
            }
        });
    }
}
Also used : Account(name.abuchen.portfolio.model.Account) Taxonomy(name.abuchen.portfolio.model.Taxonomy) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) Classification(name.abuchen.portfolio.model.Classification) ClientDataSeries(name.abuchen.portfolio.ui.views.dataseries.DataSeries.ClientDataSeries) ClientFilterMenu(name.abuchen.portfolio.ui.util.ClientFilterMenu) HashSet(java.util.HashSet)

Example 39 with Account

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

the class ConsorsbankPDFExtractorTest method checkCurrency.

private void checkCurrency(final String accountCurrency, AccountTransaction transaction) {
    Account account = new Account();
    account.setCurrencyCode(accountCurrency);
    Status status = new CheckCurrenciesAction().process(transaction, account);
    assertThat(status.getCode(), is(Code.OK));
}
Also used : Status(name.abuchen.portfolio.datatransfer.ImportAction.Status) Account(name.abuchen.portfolio.model.Account) CheckCurrenciesAction(name.abuchen.portfolio.datatransfer.actions.CheckCurrenciesAction)

Example 40 with Account

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

the class SecurityPositionTest method testFIFOPurchasePriceWithForex.

@Test
public void testFIFOPurchasePriceWithForex() {
    CurrencyConverter currencyConverter = new TestCurrencyConverter().with(CurrencyUnit.USD);
    Security security = new Security("", CurrencyUnit.USD);
    PortfolioTransaction t = new PortfolioTransaction();
    t.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
    t.setDateTime(LocalDateTime.parse("2017-01-25T00:00"));
    t.setShares(Values.Share.factorize(13));
    t.setSecurity(security);
    t.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(9659.24)));
    t.addUnit(new Unit(Unit.Type.GROSS_VALUE, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(9644.24)), Money.of(CurrencyUnit.USD, Values.Amount.factorize(10287.13)), BigDecimal.valueOf(0.937470704040499)));
    t.addUnit(new Unit(Unit.Type.FEE, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(15)), Money.of(CurrencyUnit.USD, Values.Amount.factorize(16)), BigDecimal.valueOf(0.937470704040499)));
    List<PortfolioTransaction> tx = new ArrayList<>();
    tx.add(t);
    SecurityPosition position = new SecurityPosition(security, currencyConverter, new SecurityPrice(), tx);
    assertThat(position.getShares(), is(13L * Values.Share.factor()));
    // 10287.13 / 13 = 791.32
    assertThat(position.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(791.32))));
    assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(791.32))));
    // 9659.24 EUR x ( 1 / 0.937470704040499) = 10303,51
    assertThat(position.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(9659.24 * (1 / 0.937470704040499)))));
    Client client = new Client();
    client.addSecurity(security);
    Account a = new Account();
    client.addAccount(a);
    Portfolio p = new Portfolio();
    p.setReferenceAccount(a);
    p.addTransaction(t);
    client.addPortfolio(p);
    SecurityPerformanceSnapshot snapshot = SecurityPerformanceSnapshot.create(client, currencyConverter, new ReportingPeriod.FromXtoY(LocalDate.parse("2016-12-31"), LocalDate.parse("2017-02-01")));
    assertThat(snapshot.getRecords().size(), is(1));
    SecurityPerformanceRecord record = snapshot.getRecords().get(0);
    assertThat(record.getSecurity(), is(security));
    assertThat(record.getFifoCost(), is(position.getFIFOPurchaseValue()));
    assertThat(record.getFifoCostPerSharesHeld().toMoney(), is(position.getFIFOPurchasePrice()));
}
Also used : Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) ArrayList(java.util.ArrayList) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Security(name.abuchen.portfolio.model.Security) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Aggregations

Account (name.abuchen.portfolio.model.Account)75 Security (name.abuchen.portfolio.model.Security)39 Client (name.abuchen.portfolio.model.Client)38 Portfolio (name.abuchen.portfolio.model.Portfolio)37 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)35 Test (org.junit.Test)31 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)25 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)22 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)21 ArrayList (java.util.ArrayList)17 LocalDate (java.time.LocalDate)16 AccountBuilder (name.abuchen.portfolio.AccountBuilder)14 Unit (name.abuchen.portfolio.model.Transaction.Unit)14 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)13 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)12 Money (name.abuchen.portfolio.money.Money)12 Collections (java.util.Collections)11 List (java.util.List)11 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)11 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11