Search in sources :

Example 1 with CurrencyConverter

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

the class AccountPerformanceTaxRefundTestCase method testAccountPerformanceTaxRefund.

/**
 * Feature: when calculating the performance of an account, do include taxes
 * and tax refunds but only those that are not paid for a security.
 */
@Test
public void testAccountPerformanceTaxRefund() throws IOException {
    Client client = ClientFactory.load(SecurityTestCase.class.getResourceAsStream("account_performance_tax_refund.xml"));
    Account account = client.getAccounts().get(0);
    ReportingPeriod period = new ReportingPeriod.FromXtoY(LocalDate.parse("2013-12-06"), LocalDate.parse("2014-12-06"));
    AccountTransaction deposit = account.getTransactions().get(0);
    // no changes in holdings, ttwror must be:
    double startValue = deposit.getAmount();
    double endValue = account.getCurrentAmount(LocalDateTime.of(2016, 1, 1, 10, 00));
    double ttwror = (endValue / startValue) - 1;
    List<Exception> warnings = new ArrayList<>();
    CurrencyConverter converter = new TestCurrencyConverter();
    PerformanceIndex accountPerformance = PerformanceIndex.forAccount(client, converter, account, period, warnings);
    assertThat(warnings, empty());
    double calculatedTtwror = accountPerformance.getFinalAccumulatedPercentage();
    assertThat(calculatedTtwror, closeTo(ttwror, 0.0001));
    // if the tax_refund is for a security, it must not be included in the
    // performance of the account
    AccountTransaction taxRefund = account.getTransactions().get(1);
    assertThat(taxRefund.getType(), is(AccountTransaction.Type.TAX_REFUND));
    taxRefund.setSecurity(new Security());
    accountPerformance = PerformanceIndex.forAccount(client, converter, account, period, warnings);
    assertThat(warnings, empty());
    assertThat(accountPerformance.getFinalAccumulatedPercentage(), lessThan(calculatedTtwror));
}
Also used : Account(name.abuchen.portfolio.model.Account) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 2 with CurrencyConverter

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

the class SecurityPerformanceTaxRefundTestCase method assertThatTTWROROfClassificationWithSecurityIsIdentical.

private void assertThatTTWROROfClassificationWithSecurityIsIdentical(Client client, ReportingPeriod period, double ttwror) {
    // performance of the category of the taxonomy must be identical
    Classification classification = client.getTaxonomy("32ac1de9-b9a7-480a-b464-36abf7984e0a").getClassificationById("a41d1836-9f8e-493c-9304-7434d9bbaa05");
    List<Exception> warnings = new ArrayList<Exception>();
    CurrencyConverter converter = new TestCurrencyConverter();
    PerformanceIndex classificationPerformance = PerformanceIndex.forClassification(client, converter, classification, period, warnings);
    assertThat(warnings, empty());
    assertThat(classificationPerformance.getFinalAccumulatedPercentage(), is(ttwror));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Classification(name.abuchen.portfolio.model.Classification) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 3 with CurrencyConverter

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

the class SecurityPerformanceTaxRefundTestCase method assertPerformanceOfClient.

private PerformanceIndex assertPerformanceOfClient(Client client, ReportingPeriod period, double ttwror) {
    // the performance of the client must include taxes though -> worse
    List<Exception> warnings = new ArrayList<Exception>();
    CurrencyConverter converter = new TestCurrencyConverter();
    PerformanceIndex clientIndex = PerformanceIndex.forClient(client, converter, period, warnings);
    assertThat(warnings, empty());
    assertThat(clientIndex.getFinalAccumulatedPercentage(), lessThan(ttwror));
    // the performance of portfolio + account must be identical to the
    // performance of the client
    PerformanceIndex portfolioPlusPerformance = PerformanceIndex.forPortfolioPlusAccount(client, converter, client.getPortfolios().get(0), period, warnings);
    assertThat(warnings, empty());
    assertThat(portfolioPlusPerformance.getFinalAccumulatedPercentage(), is(clientIndex.getFinalAccumulatedPercentage()));
    return clientIndex;
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter)

Example 4 with CurrencyConverter

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

the class ClassificationIndexTest method testThatPartialAssignmentIsNOTIdenticalToClientPerformance.

@Test
public void testThatPartialAssignmentIsNOTIdenticalToClientPerformance() {
    Client client = createClient(Classification.ONE_HUNDRED_PERCENT);
    Classification classification = client.getTaxonomies().get(0).getClassificationById("one");
    // remove account assignment
    classification.getAssignments().remove(1);
    List<Exception> warnings = new ArrayList<Exception>();
    CurrencyConverter converter = new TestCurrencyConverter();
    PerformanceIndex iClient = PerformanceIndex.forClient(client, converter, period, warnings);
    PerformanceIndex iClassification = PerformanceIndex.forClassification(client, converter, classification, period, warnings);
    assertThat(warnings.isEmpty(), is(true));
    assertThat(iClient.getAccumulatedPercentage(), is(not(iClassification.getAccumulatedPercentage())));
    assertThat(iClient.getDeltaPercentage(), is(not(iClassification.getDeltaPercentage())));
    assertThat(iClient.getTotals(), is(not(iClassification.getTotals())));
    assertThat(iClient.getTransferals(), is(not(iClassification.getTransferals())));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Classification(name.abuchen.portfolio.model.Classification) ArrayList(java.util.ArrayList) Client(name.abuchen.portfolio.model.Client) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Example 5 with CurrencyConverter

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

the class ClientIndexTest method testThatPerformanceOfInvestmentAndIndexIsIdendicalWhenInForeignCurrency.

@Test
public void testThatPerformanceOfInvestmentAndIndexIsIdendicalWhenInForeignCurrency() {
    LocalDate startDate = LocalDate.of(2015, 1, 1);
    LocalDate endDate = LocalDate.of(2015, 8, 1);
    long startPrice = Values.Quote.factorize(100);
    Client client = new Client();
    Security security = // 
    new SecurityBuilder("USD").generatePrices(startPrice, startDate, // 
    endDate).addTo(client);
    Account account = new AccountBuilder().addTo(client);
    // 
    new PortfolioBuilder(account).inbound_delivery(security, LocalDateTime.of(2014, 01, 01, 0, 0), Values.Share.factorize(100), // 
    100).addTo(client);
    ReportingPeriod.FromXtoY period = new ReportingPeriod.FromXtoY(startDate, endDate);
    List<Exception> warnings = new ArrayList<Exception>();
    CurrencyConverter converter = new TestCurrencyConverter().with(CurrencyUnit.EUR);
    PerformanceIndex index = PerformanceIndex.forClient(client, converter, period, warnings);
    assertTrue(warnings.isEmpty());
    PerformanceIndex benchmark = PerformanceIndex.forSecurity(index, security);
    assertTrue(warnings.isEmpty());
    assertThat(benchmark.getFinalAccumulatedPercentage(), IsCloseTo.closeTo(index.getFinalAccumulatedPercentage(), PRECISION));
    PerformanceIndex investment = PerformanceIndex.forInvestment(client, converter, security, period, warnings);
    assertTrue(warnings.isEmpty());
    assertThat(investment.getFinalAccumulatedPercentage(), is(index.getFinalAccumulatedPercentage()));
}
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) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) 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