Search in sources :

Example 6 with TestCurrencyConverter

use of name.abuchen.portfolio.TestCurrencyConverter 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 7 with TestCurrencyConverter

use of name.abuchen.portfolio.TestCurrencyConverter 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 8 with TestCurrencyConverter

use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.

the class SecurityPerformanceTaxRefundTestCase method testSecurityPerformanceTaxRefund.

/**
 * Feature: when calculating the performance of a security, do not include
 * taxes and tax refunds. Include taxes and tax refunds only when
 * calculating a performance of a porfolio and/or client.
 */
@Test
public void testSecurityPerformanceTaxRefund() throws IOException {
    Client client = ClientFactory.load(SecurityTestCase.class.getResourceAsStream("security_performance_tax_refund.xml"));
    Security security = client.getSecurities().get(0);
    Portfolio portfolio = client.getPortfolios().get(0);
    PortfolioTransaction delivery = portfolio.getTransactions().get(0);
    ReportingPeriod period = new ReportingPeriod.FromXtoY(LocalDate.parse("2013-12-06"), LocalDate.parse("2014-12-06"));
    TestCurrencyConverter converter = new TestCurrencyConverter();
    SecurityPerformanceSnapshot snapshot = SecurityPerformanceSnapshot.create(client, converter, period);
    SecurityPerformanceRecord record = snapshot.getRecords().get(0);
    assertThat(record.getSecurity().getName(), is("Basf SE"));
    // no changes in holdings, ttwror must (without taxes and tax refunds):
    double startValue = delivery.getAmount() - delivery.getUnitSum(Unit.Type.TAX).getAmount();
    double endValue = delivery.getShares() * security.getSecurityPrice(LocalDate.parse("2014-12-06")).getValue() / Values.Share.divider() / Values.Quote.dividerToMoney();
    double ttwror = (endValue / startValue) - 1;
    assertThat(record.getTrueTimeWeightedRateOfReturn(), closeTo(ttwror, 0.0001));
    // accrued taxes must be 5 (paid 10 on delivery + 5 tax refund):
    assertThat(record.getTaxes(), is(Money.of(CurrencyUnit.EUR, 5_00L)));
    // accrued fees must be 10 (paid 10 on delivery)
    assertThat(record.getFees(), is(Money.of(CurrencyUnit.EUR, 10_00L)));
    // make sure that tax refund is included in transactions
    assertThat(record.getTransactions(), hasItem(isA(AccountTransaction.class)));
    // ttwror of classification must be identical to ttwror of security
    assertThatTTWROROfClassificationWithSecurityIsIdentical(client, period, ttwror);
    // check client performance + performance of portfolio + account
    PerformanceIndex clientIndex = assertPerformanceOfClient(client, period, ttwror);
    // the performance of the portfolio (w/o account) includes taxes
    // in this sample file, the valuation of the security drops by 971
    // euros. However, the client has total valuation of 8406 while the
    // portfolio has valuation of only 8401 as it does not include the tax
    // refund. Therefore the performances of the porfolio is worse than that
    // of the client.
    assertThatTTWROROfPortfolioIsLessThan(client, clientIndex, ttwror);
    // the irr must not include taxes as well (compared with Excel):
    assertThat(record.getIrr(), closeTo(-0.030745789, 0.0001));
    // ensure the performance of the account is zero
    List<Exception> warnings = new ArrayList<Exception>();
    PerformanceIndex accountIndex = PerformanceIndex.forAccount(client, converter, client.getAccounts().get(0), period, warnings);
    assertThat(warnings, empty());
    assertThat(accountIndex.getFinalAccumulatedPercentage(), is(0d));
}
Also used : Portfolio(name.abuchen.portfolio.model.Portfolio) ArrayList(java.util.ArrayList) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Security(name.abuchen.portfolio.model.Security) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) IOException(java.io.IOException) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 9 with TestCurrencyConverter

use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.

the class SecurityTestCase method testSecurityPerformanceWithMissingHistoricalQuotes.

/**
 * Issue: If historical quotes start only after the purchase (or delivery)
 * of a security, the security is valued at 0 (no quote available) and the
 * performance would go crazy to -100% (as reported in the forum). This
 * scenario makes sure that earliest available historical quote is used.
 */
@Test
public void testSecurityPerformanceWithMissingHistoricalQuotes() throws IOException {
    Client client = ClientFactory.load(SecurityTestCase.class.getResourceAsStream("security_performance_with_missing_historical_quotes.xml"));
    Security security = client.getSecurities().get(0);
    PortfolioTransaction delivery = client.getPortfolios().get(0).getTransactions().get(0);
    assertThat("delivery transaction must be before earliest historical quote", delivery.getDateTime().toLocalDate(), lessThan(security.getPrices().get(0).getDate()));
    ReportingPeriod period = new ReportingPeriod.FromXtoY(LocalDate.parse("2013-12-04"), LocalDate.parse("2014-12-04"));
    TestCurrencyConverter converter = new TestCurrencyConverter();
    SecurityPerformanceSnapshot snapshot = SecurityPerformanceSnapshot.create(client, converter, period);
    SecurityPerformanceRecord record = snapshot.getRecords().get(0);
    assertThat(record.getSecurity().getName(), is("Basf SE"));
    assertThat(record.getTrueTimeWeightedRateOfReturn(), closeTo(-0.0594, 0.0001));
    assertThat(record.getIrr(), closeTo(-0.0643, 0.0001));
    // actually, in this simple scenario (no cash transfers involved), the
    // ttwror is easy to calculate:
    double endvalue = delivery.getShares() * security.getSecurityPrice(LocalDate.parse("2014-12-04")).getValue() / Values.Share.divider() / Values.Quote.dividerToMoney();
    assertThat(record.getTrueTimeWeightedRateOfReturn(), closeTo((endvalue / delivery.getAmount()) - 1, 0.0001));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) Test(org.junit.Test)

Example 10 with TestCurrencyConverter

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

Aggregations

TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)74 Test (org.junit.Test)72 Client (name.abuchen.portfolio.model.Client)55 Security (name.abuchen.portfolio.model.Security)46 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)38 ArrayList (java.util.ArrayList)31 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)26 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)23 Portfolio (name.abuchen.portfolio.model.Portfolio)21 AccountBuilder (name.abuchen.portfolio.AccountBuilder)19 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)19 LocalDate (java.time.LocalDate)18 Account (name.abuchen.portfolio.model.Account)18 SecurityPrice (name.abuchen.portfolio.model.SecurityPrice)15 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)13 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)10 Taxonomy (name.abuchen.portfolio.model.Taxonomy)8 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)8 PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)8 IOException (java.io.IOException)7