Search in sources :

Example 81 with AccountTransaction

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

the class ClientPerformanceSnapshotTest method testDividendTransactionWithTaxes.

@Test
public void testDividendTransactionWithTaxes() {
    Client client = new Client();
    Security security = new SecurityBuilder().addTo(client);
    Account account = new AccountBuilder().addTo(client);
    AccountTransaction dividend = new AccountTransaction();
    dividend.setDateTime(LocalDateTime.parse("2011-03-01T00:00"));
    dividend.setType(AccountTransaction.Type.DIVIDENDS);
    dividend.setSecurity(security);
    dividend.setMonetaryAmount(Money.of(CurrencyUnit.EUR, 100_00));
    dividend.addUnit(new Transaction.Unit(Transaction.Unit.Type.TAX, Money.of(CurrencyUnit.EUR, 10_00)));
    assertThat(dividend.getGrossValue(), is(Money.of(CurrencyUnit.EUR, 110_00)));
    account.addTransaction(dividend);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 110_00)));
    assertThat(snapshot.getValue(CategoryType.TAXES), is(Money.of(CurrencyUnit.EUR, 10_00)));
    assertThat(snapshot.getEarnings().size(), is(1));
    assertThat(snapshot.getCategoryByType(CategoryType.EARNINGS).getPositions().get(0).getValuation(), is(Money.of(CurrencyUnit.EUR, 110_00)));
    GroupEarningsByAccount.Item item = new GroupEarningsByAccount(snapshot).getItems().get(0);
    assertThat(item.getSum(), is(Money.of(CurrencyUnit.EUR, 110_00)));
    assertThatCalculationWorksOut(snapshot, converter);
}
Also used : Account(name.abuchen.portfolio.model.Account) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) Unit(name.abuchen.portfolio.model.Transaction.Unit) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Example 82 with AccountTransaction

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

the class ClientPerformanceSnapshotTest method testCurrencyGainsWithTransferalInOtherCurrencies.

@Test
public void testCurrencyGainsWithTransferalInOtherCurrencies() {
    Client client = new Client();
    Account usd = // 
    new AccountBuilder("USD").deposit_("2015-01-01", // 
    1000_00).addTo(client);
    Account cad = // 
    new AccountBuilder("CAD").deposit_("2015-01-01", // 
    1000_00).addTo(client);
    // insert account transfer
    AccountTransferEntry entry = new AccountTransferEntry(usd, cad);
    entry.setDate(LocalDateTime.parse("2015-01-10T00:00"));
    AccountTransaction source = entry.getSourceTransaction();
    AccountTransaction target = entry.getTargetTransaction();
    source.setMonetaryAmount(Money.of("USD", 500_00));
    target.setMonetaryAmount(Money.of("CAD", 1000_00));
    source.addUnit(new Unit(Unit.Type.GROSS_VALUE, source.getMonetaryAmount(), target.getMonetaryAmount(), BigDecimal.valueOf(.5)));
    entry.insert();
    // check currency gain calculation of client performance snapshot
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new // 
    ClientPerformanceSnapshot(// 
    client, // 
    converter, LocalDate.parse("2015-01-01"), LocalDate.parse("2015-01-15"));
    MutableMoney currencyGains = MutableMoney.of(converter.getTermCurrency());
    currencyGains.subtract(snapshot.getValue(CategoryType.INITIAL_VALUE));
    currencyGains.subtract(snapshot.getValue(CategoryType.CAPITAL_GAINS));
    currencyGains.subtract(snapshot.getValue(CategoryType.EARNINGS));
    currencyGains.add(snapshot.getValue(CategoryType.FEES));
    currencyGains.add(snapshot.getValue(CategoryType.TAXES));
    currencyGains.add(snapshot.getValue(CategoryType.TRANSFERS));
    currencyGains.add(snapshot.getValue(CategoryType.FINAL_VALUE));
    assertThat(snapshot.getCategoryByType(CategoryType.CURRENCY_GAINS).getValuation(), is(currencyGains.toMoney()));
}
Also used : Account(name.abuchen.portfolio.model.Account) MutableMoney(name.abuchen.portfolio.money.MutableMoney) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) AccountBuilder(name.abuchen.portfolio.AccountBuilder) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Client(name.abuchen.portfolio.model.Client) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 83 with AccountTransaction

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

the class ClientPerformanceSnapshotTest method testDepositPlusInterestLastDay.

@Test
public void testDepositPlusInterestLastDay() {
    Client client = new Client();
    Account account = new Account();
    account.addTransaction(new AccountTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 1000_00, null, AccountTransaction.Type.DEPOSIT));
    account.addTransaction(new AccountTransaction(LocalDateTime.of(2011, Month.DECEMBER, 31, 0, 0), CurrencyUnit.EUR, 50_00, null, AccountTransaction.Type.INTEREST));
    client.addAccount(account);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1000_00)));
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 50_00)));
    assertThat(snapshot.getValue(CategoryType.CAPITAL_GAINS), is(Money.of(CurrencyUnit.EUR, 0)));
    assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1050_00)));
    assertThat(snapshot.getAbsoluteDelta(), is(snapshot.getValue(CategoryType.FINAL_VALUE).subtract(snapshot.getValue(CategoryType.TRANSFERS)).subtract(snapshot.getValue(CategoryType.INITIAL_VALUE))));
}
Also used : Account(name.abuchen.portfolio.model.Account) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Client(name.abuchen.portfolio.model.Client) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 84 with AccountTransaction

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

the class AccountTransferModel method applyChanges.

@Override
public void applyChanges() {
    if (sourceAccount == null)
        throw new UnsupportedOperationException(Messages.MsgAccountFromMissing);
    if (targetAccount == null)
        throw new UnsupportedOperationException(Messages.MsgAccountToMissing);
    AccountTransferEntry t;
    if (source != null && sourceAccount.equals(source.getOwner(source.getSourceTransaction())) && targetAccount.equals(source.getOwner(source.getTargetTransaction()))) {
        // transaction stays in same accounts
        t = source;
    } else {
        if (source != null) {
            @SuppressWarnings("unchecked") TransactionOwner<Transaction> owner = (TransactionOwner<Transaction>) source.getOwner(source.getSourceTransaction());
            owner.deleteTransaction(source.getSourceTransaction(), client);
            source = null;
        }
        t = new AccountTransferEntry(sourceAccount, targetAccount);
        t.getSourceTransaction().setCurrencyCode(sourceAccount.getCurrencyCode());
        t.getTargetTransaction().setCurrencyCode(targetAccount.getCurrencyCode());
        t.insert();
    }
    t.setDate(date.atStartOfDay());
    t.setNote(note);
    // if source and target account have the same currencies, no forex data
    // needs to be stored
    AccountTransaction sourceTransaction = t.getSourceTransaction();
    sourceTransaction.clearUnits();
    if (sourceAccount.getCurrencyCode().equals(targetAccount.getCurrencyCode())) {
        sourceTransaction.setAmount(amount);
        t.getTargetTransaction().setAmount(amount);
    } else {
        // TODO improve naming of fields: the source amount is called
        // 'fxAmount' while the target amount is just called 'amount' but
        // then the source account holds the 'forex' which is switched
        sourceTransaction.setAmount(fxAmount);
        t.getTargetTransaction().setAmount(amount);
        Transaction.Unit forex = new // 
        Transaction.Unit(// 
        Transaction.Unit.Type.GROSS_VALUE, // 
        Money.of(sourceAccount.getCurrencyCode(), fxAmount), // 
        Money.of(targetAccount.getCurrencyCode(), amount), getInverseExchangeRate());
        sourceTransaction.addUnit(forex);
    }
}
Also used : Transaction(name.abuchen.portfolio.model.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) TransactionOwner(name.abuchen.portfolio.model.TransactionOwner)

Example 85 with AccountTransaction

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

the class SecuritiesChart method setupTooltip.

private void setupTooltip() {
    TimelineChartToolTip toolTip = chart.getToolTip();
    toolTip.setValueFormat(new DecimalFormat(Values.Quote.pattern()));
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.LabelChartDetailClosingIndicator + "Positive");
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.LabelChartDetailClosingIndicator + "Negative");
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.LabelChartDetailClosingIndicator + "Zero");
    toolTip.addSeriesExclude(Messages.SecurityMenuBuy);
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.SecurityMenuBuy + "1");
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.SecurityMenuBuy + "2");
    toolTip.addSeriesExclude(Messages.SecurityMenuSell);
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.SecurityMenuSell + "1");
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.SecurityMenuSell + "2");
    toolTip.addSeriesExclude(Messages.LabelChartDetailDividends);
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.LabelChartDetailDividends + "1");
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.LabelChartDetailDividends + "2");
    toolTip.addSeriesExclude(Messages.LabelChartDetailBollingerBands);
    toolTip.addExtraInfo((composite, focus) -> {
        if (focus instanceof Date) {
            Instant instant = ((Date) focus).toInstant();
            ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault());
            LocalDate date = zdt.toLocalDate();
            Interval displayInterval = Interval.of(date.minusDays(5), date.plusDays(5));
            // 
            customTooltipEvents.stream().filter(// 
            t -> displayInterval.contains(t.getDateTime())).forEach(t -> {
                if (t instanceof AccountTransaction)
                    addDividendTooltip(composite, (AccountTransaction) t);
                else if (t instanceof PortfolioTransaction)
                    addInvestmentTooltip(composite, (PortfolioTransaction) t);
            });
        }
    });
}
Also used : Arrays(java.util.Arrays) Client(name.abuchen.portfolio.model.Client) Transaction(name.abuchen.portfolio.model.Transaction) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) LineStyle(org.swtchart.LineStyle) Point(org.eclipse.swt.graphics.Point) Composite(org.eclipse.swt.widgets.Composite) ILineSeries(org.swtchart.ILineSeries) Interval(name.abuchen.portfolio.util.Interval) EnumSet(java.util.EnumSet) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Separator(org.eclipse.jface.action.Separator) Button(org.eclipse.swt.widgets.Button) MenuManager(org.eclipse.jface.action.MenuManager) Security(name.abuchen.portfolio.model.Security) Display(org.eclipse.swt.widgets.Display) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) List(java.util.List) Colors(name.abuchen.portfolio.ui.util.Colors) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) RowLayoutFactory(org.eclipse.jface.layout.RowLayoutFactory) SWT(org.eclipse.swt.SWT) ClientSecurityFilter(name.abuchen.portfolio.snapshot.filter.ClientSecurityFilter) SeriesType(org.swtchart.ISeries.SeriesType) Optional(java.util.Optional) Label(org.eclipse.swt.widgets.Label) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) SelectionListener(org.eclipse.swt.events.SelectionListener) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) PaintListener(org.eclipse.swt.events.PaintListener) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) IAxis(org.swtchart.IAxis) Images(name.abuchen.portfolio.ui.Images) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition) ArrayUtils(org.apache.commons.lang3.ArrayUtils) ISeries(org.swtchart.ISeries) TimelineChartToolTip(name.abuchen.portfolio.ui.util.chart.TimelineChartToolTip) Range(org.swtchart.Range) ArrayList(java.util.ArrayList) MessageFormat(com.ibm.icu.text.MessageFormat) Messages(name.abuchen.portfolio.ui.Messages) TemporalAmount(java.time.temporal.TemporalAmount) Period(java.time.Period) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) DecimalFormat(java.text.DecimalFormat) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) ILegend(org.swtchart.ILegend) Action(org.eclipse.jface.action.Action) TimelineChart(name.abuchen.portfolio.ui.util.chart.TimelineChart) PlotSymbolType(org.swtchart.ILineSeries.PlotSymbolType) PortfolioPlugin(name.abuchen.portfolio.ui.PortfolioPlugin) Color(org.eclipse.swt.graphics.Color) Unit(name.abuchen.portfolio.model.Transaction.Unit) IMenuManager(org.eclipse.jface.action.IMenuManager) DateTimeFormatter(java.time.format.DateTimeFormatter) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Collections(java.util.Collections) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TimelineChartToolTip(name.abuchen.portfolio.ui.util.chart.TimelineChartToolTip) ZonedDateTime(java.time.ZonedDateTime) DecimalFormat(java.text.DecimalFormat) Instant(java.time.Instant) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) Interval(name.abuchen.portfolio.util.Interval)

Aggregations

AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)218 Client (name.abuchen.portfolio.model.Client)169 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)152 Money (name.abuchen.portfolio.money.Money)148 IOException (java.io.IOException)141 Unit (name.abuchen.portfolio.model.Transaction.Unit)135 Test (org.junit.Test)133 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)131 Security (name.abuchen.portfolio.model.Security)129 ArrayList (java.util.ArrayList)125 Values (name.abuchen.portfolio.money.Values)117 List (java.util.List)110 LocalDateTime (java.time.LocalDateTime)109 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)103 CoreMatchers.is (org.hamcrest.CoreMatchers.is)102 Assert.assertThat (org.junit.Assert.assertThat)102 Item (name.abuchen.portfolio.datatransfer.Extractor.Item)99 SecurityItem (name.abuchen.portfolio.datatransfer.Extractor.SecurityItem)99 TransactionItem (name.abuchen.portfolio.datatransfer.Extractor.TransactionItem)99 Optional (java.util.Optional)87