Search in sources :

Example 31 with CurrencyConverter

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

the class ClientIndexTest method testThatTransferalsDoNotChangePerformance.

@Test
public void testThatTransferalsDoNotChangePerformance() {
    double[] delta = { 0d, 0.023d, 0.043d, 0.02d, 0.05d, 0.08d, 0.1d, 0.04d, -0.05d };
    long[] transferals = { 1000000, 0, 20000, -40000, 0, 0, 540000, -369704, 0 };
    long[] transferals2 = { 1000000, 0, 0, 0, 0, 0, 0, 0, 0 };
    Client client = createClient(delta, transferals);
    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(delta[ii], PRECISION));
    Client anotherClient = createClient(delta, transferals2);
    index = PerformanceIndex.forClient(anotherClient, converter, period, new ArrayList<Exception>());
    accumulated = index.getAccumulatedPercentage();
    for (int ii = 0; ii < accumulated.length; ii++) assertThat(accumulated[ii], IsCloseTo.closeTo(delta[ii], PRECISION));
}
Also used : ArrayList(java.util.ArrayList) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 32 with CurrencyConverter

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

the class ClientIndexTest method testThatPerformanceOfAnInvestmentIntoAnIndexIsIdenticalToIndex.

@Test
public void testThatPerformanceOfAnInvestmentIntoAnIndexIsIdenticalToIndex() {
    LocalDate startDate = LocalDate.of(2012, 1, 1);
    // a weekend
    LocalDate endDate = LocalDate.of(2012, 4, 29);
    long startPrice = Values.Quote.factorize(100);
    Client client = new Client();
    Security security = // 
    new SecurityBuilder().generatePrices(startPrice, startDate, // 
    endDate).addTo(client);
    PortfolioBuilder portfolio = new PortfolioBuilder(new Account());
    // add some buy transactions
    LocalDate date = startDate;
    while (date.isBefore(endDate)) {
        // performance is only identical if the capital invested
        // additionally has the identical performance on its first day -->
        // use the closing quote of the previous day
        long p = security.getSecurityPrice(date.minusDays(1)).getValue();
        portfolio.inbound_delivery(security, date.atStartOfDay(), Values.Share.factorize(100), p);
        date = date.plusDays(20);
    }
    portfolio.addTo(client);
    ReportingPeriod.FromXtoY period = new ReportingPeriod.FromXtoY(startDate, endDate);
    List<Exception> warnings = new ArrayList<Exception>();
    CurrencyConverter converter = new TestCurrencyConverter();
    PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, warnings);
    assertTrue(warnings.isEmpty());
    double[] accumulated = index.getAccumulatedPercentage();
    long lastPrice = security.getSecurityPrice(endDate).getValue();
    assertThat((double) (lastPrice - startPrice) / (double) startPrice, IsCloseTo.closeTo(accumulated[accumulated.length - 1], PRECISION));
    PerformanceIndex benchmark = PerformanceIndex.forSecurity(index, security);
    assertThat(benchmark.getFinalAccumulatedPercentage(), IsCloseTo.closeTo(index.getFinalAccumulatedPercentage(), PRECISION));
}
Also used : Account(name.abuchen.portfolio.model.Account) ArrayList(java.util.ArrayList) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) 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) Client(name.abuchen.portfolio.model.Client) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Example 33 with CurrencyConverter

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

the class ClientPerformanceSnapshotTest method testFeesRefund.

@Test
public void testFeesRefund() {
    Client client = new Client();
    // 
    new AccountBuilder().fees_refund("2011-01-01", // 
    Values.Amount.factorize(100)).addTo(client);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.FEES), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(-100))));
    assertThat(snapshot.getFees().size(), is(1));
    assertThat(snapshot.getFees().get(0).getTransaction().getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100))));
    assertThatCalculationWorksOut(snapshot, converter);
}
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 34 with CurrencyConverter

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

the class ClientPerformanceSnapshotTest method testDepositPlusInterestFirstDay.

@Test
public void testDepositPlusInterestFirstDay() {
    Client client = new Client();
    Account account = new Account();
    account.addTransaction(new AccountTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 1000_00, null, AccountTransaction.Type.DEPOSIT));
    account.addTransaction(new AccountTransaction(LocalDateTime.of(2010, Month.DECEMBER, 31, 0, 0), CurrencyUnit.EUR, 50_00, null, AccountTransaction.Type.INTEREST));
    client.addAccount(account);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1050_00)));
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 0)));
    assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1050_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) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Client(name.abuchen.portfolio.model.Client) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 35 with CurrencyConverter

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

the class ClientPerformanceSnapshotTest method testInterestCharge.

@Test
public void testInterestCharge() {
    Client client = new Client();
    Account account = // 
    new AccountBuilder().interest_charge("2011-01-01", // 
    Values.Amount.factorize(100)).addTo(client);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(-100))));
    assertThat(snapshot.getCategoryByType(CategoryType.EARNINGS).getPositions().size(), is(1));
    assertThat(snapshot.getCategoryByType(CategoryType.EARNINGS).getPositions().get(0).getValuation(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(-100))));
    assertThat(snapshot.getEarnings().size(), is(1));
    assertThat(snapshot.getEarnings().get(0).getTransaction().getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100))));
    GroupEarningsByAccount grouping = new GroupEarningsByAccount(snapshot);
    assertThat(grouping.getItems().size(), is(1));
    assertThat(grouping.getItems().get(0).getAccount(), is(account));
    assertThat(grouping.getItems().get(0).getSum(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(-100))));
    assertThatCalculationWorksOut(snapshot, converter);
}
Also used : Account(name.abuchen.portfolio.model.Account) 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)

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