Search in sources :

Example 16 with CurrencyConverter

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

the class ClientPerformanceSnapshotTest method testCapitalGains.

@Test
public void testCapitalGains() {
    Client client = new Client();
    Security security = new Security();
    security.addPrice(new SecurityPrice(LocalDate.of(2010, Month.JANUARY, 1), Values.Quote.factorize(100)));
    security.addPrice(new SecurityPrice(LocalDate.of(2011, Month.JUNE, 1), Values.Quote.factorize(110)));
    client.addSecurity(security);
    Portfolio portfolio = new Portfolio();
    portfolio.setReferenceAccount(new Account());
    portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 1_00, security, Values.Share.factorize(10), PortfolioTransaction.Type.BUY, 0, 0));
    client.addPortfolio(portfolio);
    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, 0)));
    assertThat(snapshot.getValue(CategoryType.CAPITAL_GAINS), is(Money.of(CurrencyUnit.EUR, 100_00)));
    assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1100_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) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 17 with CurrencyConverter

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

the class SecurityIndexTest method testWhenQuotesAreOnlyAvailableUntilTheMiddleOfTheReportInterval.

@Test
public void testWhenQuotesAreOnlyAvailableUntilTheMiddleOfTheReportInterval() {
    LocalDate startDate = LocalDate.of(2012, 12, 31);
    LocalDate middleDate = LocalDate.of(2013, 2, 18);
    LocalDate endDate = LocalDate.of(2013, 3, 31);
    // create model
    Client client = new Client();
    // 
    new AccountBuilder().deposit_(startDate.atStartOfDay(), // 
    100 * Values.Amount.factor()).interest(startDate.atStartOfDay().plusDays(10), // 
    10 * Values.Amount.factor()).addTo(client);
    int startPrice = 50 * Values.Amount.factor();
    Security security = // 
    new SecurityBuilder().generatePrices(startPrice, startDate, // 
    middleDate).addTo(client);
    // calculate performance indices
    List<Exception> warnings = new ArrayList<Exception>();
    ReportingPeriod reportInterval = new ReportingPeriod.FromXtoY(startDate, endDate);
    CurrencyConverter converter = new TestCurrencyConverter();
    PerformanceIndex clientIndex = PerformanceIndex.forClient(client, converter, reportInterval, warnings);
    PerformanceIndex securityIndex = PerformanceIndex.forSecurity(clientIndex, security);
    // asserts
    assertTrue(warnings.isEmpty());
    LocalDate[] clientDates = clientIndex.getDates();
    LocalDate[] securityDates = securityIndex.getDates();
    assertThat(securityDates[0], is(startDate));
    assertThat(securityDates[securityDates.length - 1], is(middleDate));
    assertThat(clientDates[0], is(securityDates[0]));
    double[] securityAccumulated = securityIndex.getAccumulatedPercentage();
    int index = Dates.daysBetween(startDate, middleDate);
    assertThat(clientDates[index], is(middleDate));
    assertThat(securityAccumulated[0], IsCloseTo.closeTo(0d, 0.000001d));
    long middlePrice = security.getSecurityPrice(middleDate).getValue();
    double performance = (double) (middlePrice - startPrice) / (double) startPrice;
    assertThat(securityAccumulated[securityAccumulated.length - 1], IsCloseTo.closeTo(performance, 0.000001d));
}
Also used : ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security) LocalDate(java.time.LocalDate) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Example 18 with CurrencyConverter

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

the class SecurityIndexTest method testIndexWhenNoQuotesExist.

@Test
public void testIndexWhenNoQuotesExist() {
    LocalDate startDate = LocalDate.of(2012, 12, 31);
    LocalDate endDate = LocalDate.of(2013, 3, 31);
    // create model
    Client client = new Client();
    // 
    new AccountBuilder().deposit_(startDate.atStartOfDay(), // 
    100 * Values.Amount.factor()).addTo(client);
    Security security = new Security();
    client.addSecurity(security);
    // calculate performance indices
    List<Exception> warnings = new ArrayList<Exception>();
    ReportingPeriod reportInterval = new ReportingPeriod.FromXtoY(startDate, endDate);
    CurrencyConverter converter = new TestCurrencyConverter();
    PerformanceIndex clientIndex = PerformanceIndex.forClient(client, converter, reportInterval, warnings);
    PerformanceIndex securityIndex = PerformanceIndex.forSecurity(clientIndex, security);
    // asserts
    assertTrue(warnings.isEmpty());
    assertThat(securityIndex.getDates().length, is(1));
    assertThat(securityIndex.getDates()[0], is(clientIndex.getFirstDataPoint().get()));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) ArrayList(java.util.ArrayList) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) LocalDate(java.time.LocalDate) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 19 with CurrencyConverter

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

the class SecuritiesPerformanceView method reportingPeriodUpdated.

@Override
public void reportingPeriodUpdated() {
    ReportingPeriod period = dropDown.getPeriods().getFirst();
    CurrencyConverter converter = new CurrencyConverterImpl(factory, getClient().getBaseCurrency());
    Client filteredClient = clientFilter.filter(getClient());
    records.setInput(SecurityPerformanceSnapshot.create(filteredClient, converter, period).getRecords());
    records.refresh();
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Client(name.abuchen.portfolio.model.Client) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 20 with CurrencyConverter

use of name.abuchen.portfolio.money.CurrencyConverter 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)

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