Search in sources :

Example 6 with ClientSnapshot

use of name.abuchen.portfolio.snapshot.ClientSnapshot in project portfolio by buchen.

the class CurrencyTestCase method testClientSnapshot.

@Test
public void testClientSnapshot() {
    LocalDate requestedTime = LocalDate.parse("2015-01-16");
    ClientSnapshot snapshot = ClientSnapshot.create(client, converter, requestedTime);
    AccountSnapshot accountEURsnapshot = lookupAccountSnapshot(snapshot, accountEUR);
    assertThat(accountEURsnapshot.getFunds(), is(Money.of(CurrencyUnit.EUR, 1000_00)));
    assertThat(accountEURsnapshot.getUnconvertedFunds(), is(Money.of(CurrencyUnit.EUR, 1000_00)));
    AccountSnapshot accountUSDsnapshot = lookupAccountSnapshot(snapshot, accountUSD);
    assertThat(accountUSDsnapshot.getFunds(), is(Money.of(CurrencyUnit.EUR, Math.round(1000_00 * (1 / 1.1588)))));
    assertThat(accountUSDsnapshot.getUnconvertedFunds(), is(Money.of("USD", 1000_00)));
    GroupByTaxonomy grouping = snapshot.groupByTaxonomy(client.getTaxonomy("30314ba9-949f-4bf4-944e-6a30802f5190"));
    testTotals(snapshot, grouping);
    testAssetCategories(grouping);
    testUSDAssetPosition(grouping);
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) AccountSnapshot(name.abuchen.portfolio.snapshot.AccountSnapshot) LocalDate(java.time.LocalDate) GroupByTaxonomy(name.abuchen.portfolio.snapshot.GroupByTaxonomy) Test(org.junit.Test)

Example 7 with ClientSnapshot

use of name.abuchen.portfolio.snapshot.ClientSnapshot 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 8 with ClientSnapshot

use of name.abuchen.portfolio.snapshot.ClientSnapshot 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 9 with ClientSnapshot

use of name.abuchen.portfolio.snapshot.ClientSnapshot 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 10 with ClientSnapshot

use of name.abuchen.portfolio.snapshot.ClientSnapshot in project portfolio by buchen.

the class SecuritiesChart method getMovingAveragePurchasePrice.

private Optional<Double> getMovingAveragePurchasePrice(Client filteredClient, CurrencyConverter currencyConverter, LocalDate date) {
    ClientSnapshot snapshot = ClientSnapshot.create(filteredClient, currencyConverter, date);
    AssetPosition position = snapshot.getPositionsByVehicle().get(security);
    if (position == null)
        return Optional.empty();
    Money purchasePrice = position.getPosition().getMovingAveragePurchasePrice();
    if (!purchasePrice.isZero())
        return Optional.of(purchasePrice.getAmount() / Values.Amount.divider());
    else
        return Optional.empty();
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) Money(name.abuchen.portfolio.money.Money) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition)

Aggregations

ClientSnapshot (name.abuchen.portfolio.snapshot.ClientSnapshot)12 LocalDate (java.time.LocalDate)5 Client (name.abuchen.portfolio.model.Client)5 Test (org.junit.Test)5 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)4 Money (name.abuchen.portfolio.money.Money)4 AssetPosition (name.abuchen.portfolio.snapshot.AssetPosition)4 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)4 SecurityPerformanceRecord (name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord)4 SecurityPerformanceSnapshot (name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot)4 IOException (java.io.IOException)3 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)3 ClientFactory (name.abuchen.portfolio.model.ClientFactory)3 Security (name.abuchen.portfolio.model.Security)3 CurrencyConverterImpl (name.abuchen.portfolio.money.CurrencyConverterImpl)3 CoreMatchers.is (org.hamcrest.CoreMatchers.is)3 Assert.assertThat (org.junit.Assert.assertThat)3 LocalDateTime (java.time.LocalDateTime)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2