use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class ClientClassificationFilter method addDeliveryT.
private void addDeliveryT(CalculationState state, Portfolio portfolio, PortfolioTransaction t, PortfolioTransaction.Type targetType, int weight) {
PortfolioTransaction copy = new PortfolioTransaction();
copy.setDateTime(t.getDateTime());
copy.setCurrencyCode(t.getCurrencyCode());
copy.setSecurity(t.getSecurity());
copy.setShares(value(t.getShares(), weight));
copy.setType(targetType);
// calculation is without taxes -> remove any taxes & adapt total
// accordingly
long taxes = value(t.getUnitSum(Unit.Type.TAX).getAmount(), weight);
long amount = value(t.getAmount(), weight);
copy.setAmount(copy.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND ? amount - taxes : amount + taxes);
// copy all units (except for taxes) over to the new transaction
t.getUnits().filter(u -> u.getType() != Unit.Type.TAX).forEach(u -> copy.addUnit(value(u, weight)));
state.asReadOnly(portfolio).internalAddTransaction(copy);
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class ClientClassificationFilter method addBuySellT.
private void addBuySellT(CalculationState state, Portfolio portfolio, PortfolioTransaction t) {
int securityWeight = state.getWeight(t.getSecurity());
long taxes = value(t.getUnitSum(Unit.Type.TAX).getAmount(), securityWeight);
long securityAmount = value(t.getAmount(), securityWeight);
securityAmount = t.getType() == PortfolioTransaction.Type.BUY ? securityAmount - taxes : securityAmount + taxes;
Account account = (Account) t.getCrossEntry().getCrossOwner(t);
int accountWeight = state.getWeight(account);
long accountAmount = value(t.getAmount(), accountWeight);
long commonAmount = Math.min(securityAmount, accountAmount);
int commonWeight = (int) Math.round(((double) commonAmount / (double) securityAmount) * securityWeight);
// create a buy/sell transactions with the amount shared by the account
// assignment and the security assignment
BuySellEntry copy = new BuySellEntry(state.asReadOnly(portfolio), state.account2readonly.get(account));
copy.setDate(t.getDateTime());
copy.setCurrencyCode(t.getCurrencyCode());
copy.setSecurity(t.getSecurity());
copy.setType(t.getType());
copy.setNote(t.getNote());
copy.setShares(value(t.getShares(), commonWeight));
copy.setAmount(commonAmount);
// copy all units (except for taxes) over to the new transaction
t.getUnits().filter(u -> u.getType() != Unit.Type.TAX).forEach(u -> copy.getPortfolioTransaction().addUnit(value(u, commonWeight)));
state.asReadOnly(portfolio).internalAddTransaction(copy.getPortfolioTransaction());
state.asReadOnly(account).internalAddTransaction(copy.getAccountTransaction());
if (accountAmount - commonAmount > 0) {
AccountTransaction ta = new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), accountAmount - commonAmount, null, t.getType() == PortfolioTransaction.Type.BUY ? AccountTransaction.Type.REMOVAL : AccountTransaction.Type.DEPOSIT);
state.asReadOnly(account).internalAddTransaction(ta);
}
if (securityAmount - commonAmount > 0) {
PortfolioTransaction tp = new PortfolioTransaction();
tp.setDateTime(t.getDateTime());
tp.setCurrencyCode(t.getCurrencyCode());
tp.setSecurity(t.getSecurity());
tp.setShares(value(t.getShares(), securityWeight - commonWeight));
tp.setType(t.getType() == PortfolioTransaction.Type.BUY ? PortfolioTransaction.Type.DELIVERY_INBOUND : PortfolioTransaction.Type.DELIVERY_OUTBOUND);
tp.setAmount(securityAmount - commonAmount);
t.getUnits().filter(u -> u.getType() != Unit.Type.TAX).forEach(u -> tp.addUnit(value(u, securityWeight - commonWeight)));
state.asReadOnly(portfolio).internalAddTransaction(tp);
}
}
use of name.abuchen.portfolio.model.Portfolio 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.Portfolio 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.Portfolio 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);
}
Aggregations