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;
}
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;
}
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);
}
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));
}
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));
}
Aggregations