use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class CheckCurrenciesBuySellEntryTest method testBuySellEntry.
@Test
public void testBuySellEntry() {
Account account = new Account();
account.setCurrencyCode("EUR");
Security security = new Security();
security.setCurrencyCode("USD");
Portfolio portfolio = new Portfolio();
BuySellEntry entry = new BuySellEntry();
entry.setType(PortfolioTransaction.Type.BUY);
entry.setSecurity(security);
entry.setMonetaryAmount(Money.of("EUR", 100_00));
entry.getPortfolioTransaction().addUnit(new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 80_00), Money.of("USD", 100_00), BigDecimal.valueOf(0.8)));
assertThat(action.process(entry, account, portfolio).getCode(), is(Status.Code.OK));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class CheckCurrenciesPortfolioTransactionTest method testTransactionHasGrossValueMatchingSecurityCurrency.
@Test
public void testTransactionHasGrossValueMatchingSecurityCurrency() {
Portfolio portfolio = new Portfolio();
Security security = new Security("", "USD");
Unit unit = new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 1_00), Money.of("USD", 2_00), BigDecimal.valueOf(0.5));
PortfolioTransaction t = new PortfolioTransaction();
t.setType(Type.DELIVERY_INBOUND);
t.setMonetaryAmount(Money.of("EUR", 1_00));
t.setSecurity(security);
t.addUnit(unit);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.OK));
t.removeUnit(unit);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
Unit other = new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 1_00), Money.of("JPY", 2_00), BigDecimal.valueOf(0.5));
t.addUnit(other);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class CheckCurrenciesPortfolioTransactionTest method testTransactionForexTaxesAndFees.
@Test
public void testTransactionForexTaxesAndFees() {
Portfolio portfolio = new Portfolio();
Security security = new Security("", "USD");
Unit grossValue = new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 10_00), Money.of("USD", 20_00), BigDecimal.valueOf(0.5));
Unit tax = new Unit(Unit.Type.TAX, Money.of("EUR", 5_00), Money.of("USD", 10_00), BigDecimal.valueOf(0.5));
Unit tax2 = new Unit(Unit.Type.TAX, Money.of("EUR", 1_00));
Unit fee = new Unit(Unit.Type.FEE, Money.of("EUR", 5_00), Money.of("USD", 10_00), BigDecimal.valueOf(0.5));
PortfolioTransaction t = new PortfolioTransaction();
t.setType(Type.DELIVERY_OUTBOUND);
t.setMonetaryAmount(Money.of("EUR", 20_00));
t.setSecurity(security);
t.addUnit(grossValue);
t.addUnit(fee);
t.addUnit(tax);
t.addUnit(tax2);
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.OK));
t.removeUnit(fee);
t.addUnit(new Unit(Unit.Type.FEE, Money.of("EUR", 5_00), Money.of("JPY", 10_00), BigDecimal.valueOf(0.5)));
assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class CrossEntryTest method testBuySellEntry.
@Test
public void testBuySellEntry() {
Portfolio portfolio = client.getPortfolios().get(0);
Account account = client.getAccounts().get(0);
Security security = client.getSecurities().get(0);
BuySellEntry entry = new BuySellEntry(portfolio, account);
entry.setCurrencyCode(CurrencyUnit.EUR);
LocalDateTime date = LocalDateTime.now();
entry.setDate(date);
entry.setSecurity(security);
entry.setShares(1 * Values.Share.factor());
entry.getPortfolioTransaction().addUnit(new Unit(Unit.Type.FEE, Money.of(CurrencyUnit.EUR, 10)));
entry.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, 11)));
entry.setAmount(1000 * Values.Amount.factor());
entry.setType(PortfolioTransaction.Type.BUY);
entry.insert();
assertThat(portfolio.getTransactions().size(), is(1));
assertThat(account.getTransactions().size(), is(1));
PortfolioTransaction pt = portfolio.getTransactions().get(0);
AccountTransaction pa = account.getTransactions().get(0);
assertThat(pt.getSecurity(), is(security));
assertThat(pa.getSecurity(), is(security));
assertThat(pt.getAmount(), is(pa.getAmount()));
assertThat(pt.getDateTime(), is(date));
assertThat(pa.getDateTime(), is(date));
assertThat(pt.getUnitSum(Unit.Type.FEE), is(Money.of(CurrencyUnit.EUR, 10L)));
assertThat(pt.getUnitSum(Unit.Type.TAX), is(Money.of(CurrencyUnit.EUR, 11L)));
// check cross entity identification
assertThat(entry.getCrossOwner(pt), is((Object) account));
assertThat(entry.getCrossTransaction(pt), is((Transaction) pa));
assertThat(entry.getCrossOwner(pa), is((Object) portfolio));
assertThat(entry.getCrossTransaction(pa), is((Transaction) pt));
// check cross editing
pa.setDateTime(LocalDateTime.of(2013, Month.MARCH, 16, 0, 0));
entry.updateFrom(pa);
assertThat(pt.getDateTime(), is(pa.getDateTime()));
// check deletion
portfolio.deleteTransaction(pt, client);
assertThat(portfolio.getTransactions().size(), is(0));
assertThat(account.getTransactions().size(), is(0));
}
use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.
the class ClientPerformanceSnapshot method addEarnings.
private void addEarnings() {
MutableMoney mEarnings = MutableMoney.of(converter.getTermCurrency());
MutableMoney mOtherEarnings = MutableMoney.of(converter.getTermCurrency());
MutableMoney mFees = MutableMoney.of(converter.getTermCurrency());
MutableMoney mTaxes = MutableMoney.of(converter.getTermCurrency());
MutableMoney mDeposits = MutableMoney.of(converter.getTermCurrency());
MutableMoney mRemovals = MutableMoney.of(converter.getTermCurrency());
Map<Security, MutableMoney> earningsBySecurity = new HashMap<>();
for (Account account : client.getAccounts()) {
for (AccountTransaction t : account.getTransactions()) {
if (!period.containsTransaction().test(t))
continue;
switch(t.getType()) {
case DIVIDENDS:
case INTEREST:
addEarningTransaction(account, t, mEarnings, mOtherEarnings, mTaxes, earningsBySecurity);
break;
case INTEREST_CHARGE:
Money charged = t.getMonetaryAmount().with(converter.at(t.getDateTime()));
mEarnings.subtract(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
earnings.add(new TransactionPair<AccountTransaction>(account, t));
mOtherEarnings.subtract(charged);
break;
case DEPOSIT:
mDeposits.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case REMOVAL:
mRemovals.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case FEES:
mFees.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
fees.add(new TransactionPair<AccountTransaction>(account, t));
break;
case FEES_REFUND:
mFees.subtract(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
fees.add(new TransactionPair<AccountTransaction>(account, t));
break;
case TAXES:
mTaxes.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
taxes.add(new TransactionPair<AccountTransaction>(account, t));
break;
case TAX_REFUND:
mTaxes.subtract(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
taxes.add(new TransactionPair<AccountTransaction>(account, t));
break;
case BUY:
case SELL:
case TRANSFER_IN:
case TRANSFER_OUT:
// no operation
break;
default:
throw new UnsupportedOperationException();
}
}
}
for (Portfolio portfolio : client.getPortfolios()) {
for (PortfolioTransaction t : portfolio.getTransactions()) {
if (!period.containsTransaction().test(t))
continue;
Money unit = t.getUnitSum(Unit.Type.FEE, converter);
if (!unit.isZero()) {
mFees.add(unit);
fees.add(new TransactionPair<PortfolioTransaction>(portfolio, t));
}
unit = t.getUnitSum(Unit.Type.TAX, converter);
if (!unit.isZero()) {
mTaxes.add(unit);
taxes.add(new TransactionPair<PortfolioTransaction>(portfolio, t));
}
switch(t.getType()) {
case DELIVERY_INBOUND:
mDeposits.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case DELIVERY_OUTBOUND:
mRemovals.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
break;
case BUY:
case SELL:
case TRANSFER_IN:
case TRANSFER_OUT:
break;
default:
throw new UnsupportedOperationException();
}
}
}
Category earningsCategory = categories.get(CategoryType.EARNINGS);
earningsCategory.valuation = mEarnings.toMoney();
earningsCategory.positions = earningsBySecurity.entrySet().stream().filter(entry -> !entry.getValue().isZero()).map(entry -> new Position(entry.getKey(), entry.getValue().toMoney())).sorted(//
(p1, p2) -> p1.getLabel().compareToIgnoreCase(p2.getLabel())).collect(Collectors.toList());
if (!mOtherEarnings.isZero())
earningsCategory.positions.add(new Position(Messages.LabelInterest, mOtherEarnings.toMoney()));
categories.get(CategoryType.FEES).valuation = mFees.toMoney();
categories.get(CategoryType.TAXES).valuation = mTaxes.toMoney();
categories.get(CategoryType.TRANSFERS).valuation = mDeposits.toMoney().subtract(mRemovals.toMoney());
categories.get(CategoryType.TRANSFERS).positions.add(new Position(Messages.LabelDeposits, mDeposits.toMoney()));
categories.get(CategoryType.TRANSFERS).positions.add(new Position(Messages.LabelRemovals, mRemovals.toMoney()));
}
Aggregations