Search in sources :

Example 11 with Account

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

the class ClientSecurityFilter method filter.

@Override
public Client filter(Client client) {
    ReadOnlyClient pseudoClient = new ReadOnlyClient(client);
    Map<Account, ReadOnlyAccount> account2readonly = new HashMap<>();
    Map<Portfolio, ReadOnlyPortfolio> portfolio2readonly = new HashMap<>();
    Function<Account, ReadOnlyAccount> transformAccount = a -> account2readonly.computeIfAbsent(a, aa -> {
        ReadOnlyAccount readonly = new ReadOnlyAccount(aa);
        pseudoClient.internalAddAccount(readonly);
        return readonly;
    });
    Function<Portfolio, ReadOnlyPortfolio> transformPortfolio = p -> portfolio2readonly.computeIfAbsent(p, pp -> {
        ReadOnlyPortfolio pseudoPortfolio = new ReadOnlyPortfolio(pp);
        pseudoPortfolio.setReferenceAccount(transformAccount.apply(pp.getReferenceAccount()));
        pseudoClient.internalAddPortfolio(pseudoPortfolio);
        return pseudoPortfolio;
    });
    for (Security security : securities) {
        pseudoClient.internalAddSecurity(security);
        addSecurity(client, transformPortfolio, transformAccount, security);
    }
    return pseudoClient;
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Arrays(java.util.Arrays) Client(name.abuchen.portfolio.model.Client) Account(name.abuchen.portfolio.model.Account) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) TransactionPair(name.abuchen.portfolio.model.TransactionPair) HashMap(java.util.HashMap) Security(name.abuchen.portfolio.model.Security) Function(java.util.function.Function) List(java.util.List) Unit(name.abuchen.portfolio.model.Transaction.Unit) Map(java.util.Map) Portfolio(name.abuchen.portfolio.model.Portfolio) Account(name.abuchen.portfolio.model.Account) HashMap(java.util.HashMap) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security)

Example 12 with Account

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

the class PortfolioClientFilter method filter.

@Override
public Client filter(Client client) {
    ReadOnlyClient pseudoClient = new ReadOnlyClient(client);
    Map<Account, ReadOnlyAccount> account2pseudo = new HashMap<>();
    Set<Security> usedSecurities = new HashSet<>();
    for (Portfolio portfolio : portfolios) {
        ReadOnlyAccount pseudoAccount = account2pseudo.computeIfAbsent(portfolio.getReferenceAccount(), a -> {
            ReadOnlyAccount pa = new ReadOnlyAccount(a);
            pseudoClient.internalAddAccount(pa);
            return pa;
        });
        ReadOnlyPortfolio pseudoPortfolio = new ReadOnlyPortfolio(portfolio);
        pseudoPortfolio.setReferenceAccount(pseudoAccount);
        pseudoClient.internalAddPortfolio(pseudoPortfolio);
        adaptPortfolioTransactions(portfolio, pseudoPortfolio, usedSecurities);
        if (!accounts.contains(portfolio.getReferenceAccount()))
            collectSecurityRelevantTx(portfolio, pseudoAccount, usedSecurities);
    }
    for (Account account : accounts) {
        ReadOnlyAccount pseudoAccount = account2pseudo.computeIfAbsent(account, a -> {
            ReadOnlyAccount pa = new ReadOnlyAccount(a);
            pseudoClient.internalAddAccount(pa);
            return pa;
        });
        adaptAccountTransactions(account, pseudoAccount, usedSecurities);
    }
    for (Security security : usedSecurities) pseudoClient.internalAddSecurity(security);
    return pseudoClient;
}
Also used : Account(name.abuchen.portfolio.model.Account) HashMap(java.util.HashMap) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) HashSet(java.util.HashSet)

Example 13 with Account

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

the class SecurityPerformanceSnapshot method create.

public static SecurityPerformanceSnapshot create(Client client, CurrencyConverter converter, ReportingPeriod period) {
    Map<Security, SecurityPerformanceRecord> transactions = initRecords(client);
    for (Account account : client.getAccounts()) extractSecurityRelatedAccountTransactions(account, period, transactions);
    for (Portfolio portfolio : client.getPortfolios()) {
        extractSecurityRelatedPortfolioTransactions(portfolio, period, transactions);
        addPseudoValuationTansactions(portfolio, converter, period, transactions);
    }
    return doCreateSnapshot(client, converter, transactions, period);
}
Also used : Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security)

Example 14 with Account

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

the class AccountPerformanceTaxRefundTestCase method testAccountPerformanceTaxRefund.

/**
 * Feature: when calculating the performance of an account, do include taxes
 * and tax refunds but only those that are not paid for a security.
 */
@Test
public void testAccountPerformanceTaxRefund() throws IOException {
    Client client = ClientFactory.load(SecurityTestCase.class.getResourceAsStream("account_performance_tax_refund.xml"));
    Account account = client.getAccounts().get(0);
    ReportingPeriod period = new ReportingPeriod.FromXtoY(LocalDate.parse("2013-12-06"), LocalDate.parse("2014-12-06"));
    AccountTransaction deposit = account.getTransactions().get(0);
    // no changes in holdings, ttwror must be:
    double startValue = deposit.getAmount();
    double endValue = account.getCurrentAmount(LocalDateTime.of(2016, 1, 1, 10, 00));
    double ttwror = (endValue / startValue) - 1;
    List<Exception> warnings = new ArrayList<>();
    CurrencyConverter converter = new TestCurrencyConverter();
    PerformanceIndex accountPerformance = PerformanceIndex.forAccount(client, converter, account, period, warnings);
    assertThat(warnings, empty());
    double calculatedTtwror = accountPerformance.getFinalAccumulatedPercentage();
    assertThat(calculatedTtwror, closeTo(ttwror, 0.0001));
    // if the tax_refund is for a security, it must not be included in the
    // performance of the account
    AccountTransaction taxRefund = account.getTransactions().get(1);
    assertThat(taxRefund.getType(), is(AccountTransaction.Type.TAX_REFUND));
    taxRefund.setSecurity(new Security());
    accountPerformance = PerformanceIndex.forAccount(client, converter, account, period, warnings);
    assertThat(warnings, empty());
    assertThat(accountPerformance.getFinalAccumulatedPercentage(), lessThan(calculatedTtwror));
}
Also used : Account(name.abuchen.portfolio.model.Account) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 15 with Account

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

the class ClassificationIndexTest method testThatTaxesAreNotIncludedInTTWRORCalculation.

@Test
public void testThatTaxesAreNotIncludedInTTWRORCalculation() {
    Client client = new Client();
    Security security = // 
    new SecurityBuilder().addPrice("2015-12-31", // 
    Values.Quote.factorize(100)).addPrice("2016-12-31", // 
    Values.Quote.factorize(110)).addTo(client);
    Account account = // 
    new AccountBuilder().deposit_("2014-01-01", Values.Amount.factorize(1000)).addTo(client);
    AccountTransaction t = new AccountTransaction();
    t.setType(AccountTransaction.Type.DIVIDENDS);
    t.setDateTime(LocalDateTime.parse("2016-06-01T00:00"));
    t.setSecurity(security);
    t.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100)));
    t.setShares(Values.Share.factorize(10));
    account.addTransaction(t);
    Portfolio portfolio = // 
    new PortfolioBuilder(account).addTo(client);
    BuySellEntry buy = new BuySellEntry(portfolio, account);
    buy.setType(PortfolioTransaction.Type.BUY);
    buy.setDate(LocalDateTime.parse("2015-12-31T00:00"));
    buy.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1000)));
    buy.setShares(Values.Share.factorize(10));
    buy.setSecurity(security);
    buy.insert();
    BuySellEntry sell = new BuySellEntry(portfolio, account);
    sell.setType(PortfolioTransaction.Type.SELL);
    sell.setDate(LocalDateTime.parse("2016-12-31T00:00"));
    sell.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1070)));
    sell.setShares(Values.Share.factorize(10));
    sell.setSecurity(security);
    sell.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(30))));
    sell.insert();
    Classification classification = new Classification(null, null);
    classification.addAssignment(new Assignment(security));
    List<Exception> warnings = new ArrayList<Exception>();
    PerformanceIndex index = PerformanceIndex.forClassification(client, new TestCurrencyConverter(), classification, new ReportingPeriod.FromXtoY(LocalDate.parse("2015-01-01"), LocalDate.parse("2017-01-01")), warnings);
    assertThat(warnings.isEmpty(), is(true));
    // dividend payment 10% * quote change 10%
    assertThat(index.getFinalAccumulatedPercentage(), IsCloseTo.closeTo((1.1 * 1.1) - 1, 0.000000001d));
    // add taxes to dividend payment
    t.addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(50))));
    index = PerformanceIndex.forClassification(client, new TestCurrencyConverter(), classification, new ReportingPeriod.FromXtoY(LocalDate.parse("2015-01-01"), LocalDate.parse("2017-01-01")), warnings);
    // dividend payment 15% * quote change 10%
    assertThat(index.getFinalAccumulatedPercentage(), IsCloseTo.closeTo((1.15 * 1.1) - 1, 0.000000001d));
}
Also used : Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Portfolio(name.abuchen.portfolio.model.Portfolio) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Security(name.abuchen.portfolio.model.Security) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) Assignment(name.abuchen.portfolio.model.Classification.Assignment) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Classification(name.abuchen.portfolio.model.Classification) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) 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