use of name.abuchen.portfolio.model.AccountTransaction in project portfolio by buchen.
the class ClientClassificationFilter method addTransferT.
private void addTransferT(CalculationState state, Account inboundAccount, AccountTransaction t) {
Account outboundAccount = (Account) t.getCrossEntry().getCrossOwner(t);
int inboundWeight = state.getWeight(inboundAccount);
int outboundWeight = state.getWeight(outboundAccount);
if (inboundWeight == outboundWeight && inboundWeight == Classification.ONE_HUNDRED_PERCENT) {
state.asReadOnly(inboundAccount).internalAddTransaction(t);
state.asReadOnly(outboundAccount).internalAddTransaction((AccountTransaction) t.getCrossEntry().getCrossTransaction(t));
} else if (inboundWeight == outboundWeight) {
AccountTransferEntry entry = createTransferEntry((AccountTransferEntry) t.getCrossEntry(), inboundWeight);
// entry#insert does not work with ReadOnlyAccount
state.asReadOnly(inboundAccount).internalAddTransaction(entry.getTargetTransaction());
state.asReadOnly(outboundAccount).internalAddTransaction(entry.getSourceTransaction());
} else if (inboundWeight < outboundWeight) {
AccountTransferEntry entry = createTransferEntry((AccountTransferEntry) t.getCrossEntry(), inboundWeight);
// entry#insert does not work with ReadOnlyAccount
state.asReadOnly(inboundAccount).internalAddTransaction(entry.getTargetTransaction());
state.asReadOnly(outboundAccount).internalAddTransaction(entry.getSourceTransaction());
AccountTransaction ot = (AccountTransaction) t.getCrossEntry().getCrossTransaction(t);
state.asReadOnly(outboundAccount).internalAddTransaction(new AccountTransaction(ot.getDateTime(), ot.getCurrencyCode(), value(ot.getAmount(), outboundWeight - inboundWeight), null, AccountTransaction.Type.REMOVAL));
} else // inboundWeight > outboundWeight
{
AccountTransferEntry entry = createTransferEntry((AccountTransferEntry) t.getCrossEntry(), outboundWeight);
// entry#insert does not work with ReadOnlyAccount
state.asReadOnly(inboundAccount).internalAddTransaction(entry.getTargetTransaction());
state.asReadOnly(outboundAccount).internalAddTransaction(entry.getSourceTransaction());
state.asReadOnly(inboundAccount).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), value(t.getAmount(), inboundWeight - outboundWeight), null, AccountTransaction.Type.DEPOSIT));
}
}
use of name.abuchen.portfolio.model.AccountTransaction in project portfolio by buchen.
the class ClientClassificationFilter method addSecurityRelatedAccountT.
private void addSecurityRelatedAccountT(CalculationState state, Account account, AccountTransaction t) {
int accountWeight = state.getWeight(account);
int securityWeight = state.getWeight(t.getSecurity());
long taxes = value(t.getUnitSum(Unit.Type.TAX).getAmount(), securityWeight);
long amount = value(t.getAmount(), securityWeight);
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), amount + taxes, t.getSecurity(), t.getType()));
long accountAmount = value(t.getAmount(), accountWeight);
long delta = accountAmount - amount - taxes;
if (delta != 0) {
AccountTransaction.Type deltaType = delta > 0 ^ t.getType().isDebit() ? AccountTransaction.Type.DEPOSIT : AccountTransaction.Type.REMOVAL;
state.asReadOnly(account).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), Math.abs(delta), null, deltaType));
}
}
use of name.abuchen.portfolio.model.AccountTransaction 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.AccountTransaction in project portfolio by buchen.
the class PortfolioClientFilter method convertTo.
private AccountTransaction convertTo(AccountTransaction t, AccountTransaction.Type type) {
AccountTransaction clone = new AccountTransaction();
clone.setType(type);
clone.setDateTime(t.getDateTime());
clone.setCurrencyCode(t.getCurrencyCode());
// no security for REMOVAL or DEPOSIT
clone.setSecurity(null);
clone.setAmount(t.getAmount());
clone.setShares(t.getShares());
// do *not* copy units as REMOVAL and DEPOSIT have never units
return clone;
}
use of name.abuchen.portfolio.model.AccountTransaction 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));
}
Aggregations