Search in sources :

Example 6 with CurrencyConverter

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

the class ClientIndexTest method testExcelSampleAggregatedWeekly.

@Test
public void testExcelSampleAggregatedWeekly() {
    // first day of week is locale dependent
    Locale locale = Locale.getDefault();
    Locale.setDefault(Locale.GERMAN);
    try {
        Client client = createClient();
        ReportingPeriod.FromXtoY reportInterval = new // 
        ReportingPeriod.FromXtoY(LocalDate.of(2011, Month.DECEMBER, 31), LocalDate.of(2012, Month.JANUARY, 8));
        CurrencyConverter converter = new TestCurrencyConverter();
        PerformanceIndex index = PerformanceIndex.forClient(client, converter, reportInterval, new ArrayList<Exception>());
        index = Aggregation.aggregate(index, Aggregation.Period.WEEKLY);
        assertNotNull(index);
        double[] delta = index.getDeltaPercentage();
        assertThat(delta.length, is(2));
        assertThat(delta[0], IsCloseTo.closeTo(0.023d, PRECISION));
        assertThat(delta[1], IsCloseTo.closeTo(-0.077402422d, PRECISION));
        double[] accumulated = index.getAccumulatedPercentage();
        assertThat(accumulated[0], IsCloseTo.closeTo(0.023d, PRECISION));
        assertThat(accumulated[1], IsCloseTo.closeTo(-0.056182678d, PRECISION));
    } finally {
        Locale.setDefault(locale);
    }
}
Also used : Locale(java.util.Locale) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 7 with CurrencyConverter

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

the class ClientIndexTest method testThatNoValuationResultsInZeroPerformance.

@Test
public void testThatNoValuationResultsInZeroPerformance() {
    Client client = new Client();
    ReportingPeriod.FromXtoY period = new // 
    ReportingPeriod.FromXtoY(// 
    LocalDate.of(2012, Month.JANUARY, 1), LocalDate.of(2012, Month.JANUARY, 9));
    CurrencyConverter converter = new TestCurrencyConverter();
    PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, new ArrayList<Exception>());
    double[] accumulated = index.getAccumulatedPercentage();
    for (int ii = 0; ii < accumulated.length; ii++) assertThat(accumulated[ii], IsCloseTo.closeTo(0d, PRECISION));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 8 with CurrencyConverter

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

the class ClientIndexTest method testThatDepositsOnTheLastDayArePerformanceNeutral.

@Test
public void testThatDepositsOnTheLastDayArePerformanceNeutral() {
    Client client = new Client();
    // 
    new AccountBuilder().deposit_("2012-01-01", // 
    10000).interest("2012-01-02", // 
    1000).deposit_("2012-01-10", // 
    10000).addTo(client);
    ReportingPeriod.FromXtoY reportInterval = new // 
    ReportingPeriod.FromXtoY(// 
    LocalDate.of(2012, Month.JANUARY, 1), LocalDate.of(2012, Month.JANUARY, 10));
    CurrencyConverter converter = new TestCurrencyConverter();
    PerformanceIndex index = PerformanceIndex.forClient(client, converter, reportInterval, new ArrayList<Exception>());
    double[] accumulated = index.getAccumulatedPercentage();
    assertThat(accumulated[accumulated.length - 2], IsCloseTo.closeTo(0.1d, PRECISION));
    assertThat(accumulated[accumulated.length - 1], IsCloseTo.closeTo(0.1d, PRECISION));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 9 with CurrencyConverter

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

the class ClientPerformanceSnapshotTest method testEarningsFromSecurity.

@Test
public void testEarningsFromSecurity() {
    Client client = new Client();
    Security security = new Security();
    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);
    Account account = new Account();
    account.addTransaction(new AccountTransaction(LocalDateTime.of(2011, Month.JANUARY, 31, 0, 0), CurrencyUnit.EUR, 50_00, security, AccountTransaction.Type.INTEREST));
    client.addAccount(account);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 50_00)));
    assertThat(snapshot.getCategoryByType(CategoryType.EARNINGS).getPositions().size(), is(1));
    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) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) 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 10 with CurrencyConverter

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

the class ClientPerformanceSnapshotTest method testCapitalGainsWithPartialSellDuringReportPeriodWithFees.

@Test
public void testCapitalGainsWithPartialSellDuringReportPeriodWithFees() {
    Client client = new Client();
    Security security = // 
    new SecurityBuilder().addPrice("2010-01-01", // 
    Values.Quote.factorize(100)).addPrice("2011-06-01", // 
    Values.Quote.factorize(110)).addTo(client);
    Account account = // 
    new AccountBuilder().deposit_("2010-01-01", // 
    1_00).withdraw("2011-01-15", // 
    99_00).addTo(client);
    // 
    new PortfolioBuilder(account).buy(security, "2010-01-01", Values.Share.factorize(10), // 
    1_00).sell(security, "2011-01-15", Values.Share.factorize(1), 99_00, // 
    1).addTo(client);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.CAPITAL_GAINS), is(Money.of(CurrencyUnit.EUR, 1000 * 9 + (9900 - 10000) + 1)));
    assertThat(snapshot.getValue(CategoryType.FEES), is(Money.of(CurrencyUnit.EUR, 1)));
    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) AccountBuilder(name.abuchen.portfolio.AccountBuilder) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) 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