Search in sources :

Example 1 with ClientSnapshot

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

the class CurrencyTestCase method testFIFOPurchasePriceWithForex.

@Test
public void testFIFOPurchasePriceWithForex() {
    ClientSnapshot snapshot = ClientSnapshot.create(client, converter, LocalDate.parse("2015-08-09"));
    // 1.1. ........ -> 454.60 EUR
    // 1.1. 571.90 $ -> 471.05 EUR (exchange rate: 1.2141)
    // 3.8. 577.60 $ -> 498.45 EUR (exchange rate: 1.1588)
    AssetPosition position = snapshot.getPositionsByVehicle().get(securityUSD);
    assertThat(position.getPosition().getShares(), is(Values.Share.factorize(15)));
    assertThat(position.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.EUR, 454_60 + 471_05 + 498_45)));
    ReportingPeriod period = new ReportingPeriod.FromXtoY(LocalDate.parse("2014-12-31"), LocalDate.parse("2015-08-10"));
    SecurityPerformanceSnapshot performance = SecurityPerformanceSnapshot.create(client, converter, period);
    SecurityPerformanceRecord record = performance.getRecords().stream().filter(r -> r.getSecurity() == securityUSD).findAny().get();
    assertThat(record.getSharesHeld(), is(Values.Share.factorize(15)));
    assertThat(record.getFifoCost(), is(Money.of(CurrencyUnit.EUR, 454_60 + 471_05 + 498_45)));
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition) Test(org.junit.Test)

Example 2 with ClientSnapshot

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

the class SecurityTaxAndFeeAccountTransactionsTestCase method checkFilteredClientAdidas.

private void checkFilteredClientAdidas(Client filteredClient, double weight) {
    List<AccountTransaction> txa = filteredClient.getAccounts().stream().flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    // expect 4 transactions: the two fees-related ones plus the
    // deposit/removal to have the account balance at zero
    assertThat(txa.size(), is(4));
    // check balance is zero
    ClientSnapshot balance = ClientSnapshot.create(filteredClient, converter, interval.getEndDate());
    assertThat(balance.getMonetaryAssets(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1456.5 * weight))));
    assertThat(balance.getAccounts().size(), is(1));
    assertThat(balance.getAccounts().iterator().next().getFunds(), is(Money.of(CurrencyUnit.EUR, 0)));
    // check for additional transactions
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-09T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10.0 * weight)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-10T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(5.0 * weight)))))));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) BeforeClass(org.junit.BeforeClass) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) Classification(name.abuchen.portfolio.model.Classification) ArrayList(java.util.ArrayList) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) ClientFactory(name.abuchen.portfolio.model.ClientFactory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Taxonomy(name.abuchen.portfolio.model.Taxonomy) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Collectors(java.util.stream.Collectors) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) List(java.util.List) LocalDate(java.time.LocalDate) ClientSecurityFilter(name.abuchen.portfolio.snapshot.filter.ClientSecurityFilter) IsCloseTo.closeTo(org.hamcrest.number.IsCloseTo.closeTo) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 3 with ClientSnapshot

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

the class SecurityTaxAndFeeAccountTransactionsTestCase method checkPortfolioClientFilter.

@Test
public void checkPortfolioClientFilter() {
    Client filteredClient = new PortfolioClientFilter(client.getPortfolios().get(0)).filter(client);
    List<AccountTransaction> txa = filteredClient.getAccounts().stream().flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    // expect 8 transactions: the 4 tax and fees transactions plus the
    // offset transactions to keep the balance zero
    assertThat(txa.size(), is(8));
    // check balance is zero
    ClientSnapshot balance = ClientSnapshot.create(filteredClient, converter, interval.getEndDate());
    assertThat(balance.getMonetaryAssets(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1456.5))));
    assertThat(balance.getAccounts().size(), is(1));
    assertThat(balance.getAccounts().iterator().next().getFunds(), is(Money.of(CurrencyUnit.EUR, 0)));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-09T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(10.0)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-10T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(5.0)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-11T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.DEPOSIT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(25.0)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2017-01-12T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(5.0)))))));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) BeforeClass(org.junit.BeforeClass) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) Classification(name.abuchen.portfolio.model.Classification) ArrayList(java.util.ArrayList) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) ClientFactory(name.abuchen.portfolio.model.ClientFactory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Taxonomy(name.abuchen.portfolio.model.Taxonomy) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Collectors(java.util.stream.Collectors) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) List(java.util.List) LocalDate(java.time.LocalDate) ClientSecurityFilter(name.abuchen.portfolio.snapshot.filter.ClientSecurityFilter) IsCloseTo.closeTo(org.hamcrest.number.IsCloseTo.closeTo) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 4 with ClientSnapshot

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

the class StatementOfAssetsView method notifyModelUpdated.

@Override
public void notifyModelUpdated() {
    CurrencyConverter converter = new CurrencyConverterImpl(factory, getClient().getBaseCurrency());
    Client filteredClient = clientFilter.getSelectedFilter().filter(getClient());
    ClientSnapshot snapshot = ClientSnapshot.create(filteredClient, converter, snapshotDate);
    assetViewer.setInput(snapshot, clientFilter.getSelectedFilter());
    updateTitle(getDefaultTitle());
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) Client(name.abuchen.portfolio.model.Client) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 5 with ClientSnapshot

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

the class TaxonomyView method notifyModelUpdated.

@Override
public void notifyModelUpdated() {
    Client filteredClient = this.clientFilter.filter(getClient());
    ClientSnapshot snapshot = ClientSnapshot.create(filteredClient, model.getCurrencyConverter(), LocalDate.now());
    model.setClientSnapshot(filteredClient, snapshot);
    model.fireTaxonomyModelChange(model.getVirtualRootNode());
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) Client(name.abuchen.portfolio.model.Client)

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