Search in sources :

Example 41 with CurrencyConverter

use of name.abuchen.portfolio.money.CurrencyConverter in project portfolio by buchen.

the class AccountTransactionDialog method sharesMenuAboutToShow.

private // NOSONAR
void sharesMenuAboutToShow(// NOSONAR
IMenuManager manager) {
    manager.add(new LabelOnly(Messages.DividendsDialogTitleShares));
    CurrencyConverter converter = new CurrencyConverterImpl(model.getExchangeRateProviderFactory(), client.getBaseCurrency());
    ClientSnapshot snapshot = ClientSnapshot.create(client, converter, model().getDate());
    if (snapshot != null && model().getSecurity() != null) {
        PortfolioSnapshot jointPortfolio = snapshot.getJointPortfolio();
        addAction(manager, jointPortfolio, Messages.ColumnSharesOwned);
        List<PortfolioSnapshot> list = snapshot.getPortfolios();
        if (list.size() > 1) {
            for (PortfolioSnapshot ps : list) addAction(manager, ps, ps.getPortfolio().getName());
        }
    }
    manager.add(new Action(Messages.DividendsDialogLabelSpecialDistribution) {

        @Override
        public void run() {
            model().setShares(0);
        }
    });
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) Action(org.eclipse.jface.action.Action) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) PortfolioSnapshot(name.abuchen.portfolio.snapshot.PortfolioSnapshot) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 42 with CurrencyConverter

use of name.abuchen.portfolio.money.CurrencyConverter in project portfolio by buchen.

the class AccountTransactionModel method updateShares.

private void updateShares() {
    // transaction
    if (sourceTransaction != null)
        return;
    if (!supportsShares() || security == null)
        return;
    CurrencyConverter converter = new CurrencyConverterImpl(getExchangeRateProviderFactory(), client.getBaseCurrency());
    ClientSnapshot snapshot = ClientSnapshot.create(client, converter, date);
    SecurityPosition p = snapshot.getJointPortfolio().getPositionsBySecurity().get(security);
    setShares(p != null ? p.getShares() : 0);
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 43 with CurrencyConverter

use of name.abuchen.portfolio.money.CurrencyConverter in project portfolio by buchen.

the class SecurityTransferModel method updateSharesAndQuote.

private void updateSharesAndQuote() {
    // transaction
    if (source != null)
        return;
    SecurityPosition position = null;
    if (security != null) {
        CurrencyConverter converter = new CurrencyConverterImpl(getExchangeRateProviderFactory(), client.getBaseCurrency());
        PortfolioSnapshot snapshot = sourcePortfolio != null ? PortfolioSnapshot.create(sourcePortfolio, converter, date) : ClientSnapshot.create(client, converter, date).getJointPortfolio();
        position = snapshot.getPositionsBySecurity().get(security);
    }
    if (position != null) {
        setShares(position.getShares());
        // setAmount will also set quote
        setAmount(position.calculateValue().getAmount());
    } else if (security != null) {
        setShares(0);
        setQuote(new BigDecimal(security.getSecurityPrice(date).getValue() / Values.Quote.divider()));
    } else {
        setShares(0);
        setQuote(BigDecimal.ZERO);
    }
}
Also used : SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) PortfolioSnapshot(name.abuchen.portfolio.snapshot.PortfolioSnapshot) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) BigDecimal(java.math.BigDecimal) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 44 with CurrencyConverter

use of name.abuchen.portfolio.money.CurrencyConverter in project portfolio by buchen.

the class Issue371PurchaseValueWithTransfers method testPurchaseValueOfSecurityPositionWithTransfers.

@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException {
    Client client = ClientFactory.load(Issue371PurchaseValueWithTransfers.class.getResourceAsStream(// $NON-NLS-1$
    "Issue371PurchaseValueWithTransfers.xml"));
    Security adidas = client.getSecurities().get(0);
    // $NON-NLS-1$
    assertThat(adidas.getName(), is("Adidas AG"));
    ReportingPeriod period = new // $NON-NLS-1$
    ReportingPeriod.FromXtoY(// $NON-NLS-1$
    LocalDate.parse("2010-11-20"), // $NON-NLS-1$
    LocalDate.parse("2015-11-20"));
    // make sure that the transfer entry exists
    assertThat(client.getPortfolios().size(), is(2));
    assertThat(client.getPortfolios().stream().flatMap(p -> p.getTransactions().stream()).filter(t -> t.getSecurity() == adidas).filter(t -> t.getCrossEntry() instanceof PortfolioTransferEntry).filter(t -> t.getType() == PortfolioTransaction.Type.TRANSFER_IN).findAny().isPresent(), is(true));
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientSnapshot snapshot = ClientSnapshot.create(client, converter, period.getEndDate());
    SecurityPosition securityPosition = snapshot.getPositionsByVehicle().get(adidas).getPosition();
    SecurityPerformanceSnapshot securitySnapshot = SecurityPerformanceSnapshot.create(client, converter, period);
    SecurityPerformanceRecord securityRecord = securitySnapshot.getRecords().get(0);
    assertThat(securityRecord.getSecurity(), is(adidas));
    assertThat(securityPosition.getFIFOPurchaseValue(), is(securityRecord.getFifoCost()));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Client(name.abuchen.portfolio.model.Client) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Assert.assertThat(org.junit.Assert.assertThat) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) ClientFactory(name.abuchen.portfolio.model.ClientFactory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Security(name.abuchen.portfolio.model.Security) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) Test(org.junit.Test)

Example 45 with CurrencyConverter

use of name.abuchen.portfolio.money.CurrencyConverter in project portfolio by buchen.

the class Issue672CapitalGainsIfSecurityIsTransferred method testPurchaseValueOfSecurityPositionWithTransfers.

@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException {
    Client client = ClientFactory.load(Issue371PurchaseValueWithTransfers.class.getResourceAsStream(// $NON-NLS-1$
    "Issue672CapitalGainsIfSecurityIsTransferred.xml"));
    CurrencyConverter converter = new TestCurrencyConverter();
    Portfolio secondPortfolio = client.getPortfolios().get(1);
    ReportingPeriod period = new // $NON-NLS-1$
    ReportingPeriod.FromXtoY(// $NON-NLS-1$
    LocalDate.parse("2016-01-01"), // $NON-NLS-1$
    LocalDate.parse("2017-01-01"));
    SecurityPerformanceSnapshot snapshot = SecurityPerformanceSnapshot.create(client, converter, secondPortfolio, period);
    assertThat(snapshot.getRecords().size(), is(1));
    SecurityPerformanceRecord record = snapshot.getRecords().get(0);
    assertThat(record.getMarketValue(), is(Money.of(CurrencyUnit.EUR, Values.Money.factorize(971.41))));
    assertThat(record.getFifoCost(), is(Money.of(CurrencyUnit.EUR, Values.Money.factorize(883.1))));
    assertThat(record.getCapitalGainsOnHoldings(), is(Money.of(CurrencyUnit.EUR, Values.Money.factorize(88.31))));
    assertThat(record.getCapitalGainsOnHoldingsPercent(), is(IsCloseTo.closeTo(0.1d, 0.0000000001)));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Client(name.abuchen.portfolio.model.Client) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Aggregations

CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)53 Client (name.abuchen.portfolio.model.Client)41 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)38 Test (org.junit.Test)36 Security (name.abuchen.portfolio.model.Security)19 ArrayList (java.util.ArrayList)18 AccountBuilder (name.abuchen.portfolio.AccountBuilder)15 Account (name.abuchen.portfolio.model.Account)15 LocalDate (java.time.LocalDate)13 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)12 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)11 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)9 CurrencyConverterImpl (name.abuchen.portfolio.money.CurrencyConverterImpl)9 Portfolio (name.abuchen.portfolio.model.Portfolio)7 SecurityPrice (name.abuchen.portfolio.model.SecurityPrice)6 Transaction (name.abuchen.portfolio.model.Transaction)6 Unit (name.abuchen.portfolio.model.Transaction.Unit)6 ClientSnapshot (name.abuchen.portfolio.snapshot.ClientSnapshot)6 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)6 Classification (name.abuchen.portfolio.model.Classification)5