Search in sources :

Example 16 with Portfolio

use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.

the class SecurityPerformanceTaxRefundTestCase method testSecurityPerformanceTaxRefundAllSold.

/**
 * Feature: Same as {@link #testSecurityPerformanceTaxRefunds} except that
 * now the security has been sold. Taxes paid when selling the security must
 * be ignored.
 */
@Test
public void testSecurityPerformanceTaxRefundAllSold() throws IOException {
    Client client = ClientFactory.load(SecurityTestCase.class.getResourceAsStream("security_performance_tax_refund_all_sold.xml"));
    Portfolio portfolio = client.getPortfolios().get(0);
    PortfolioTransaction delivery = portfolio.getTransactions().get(0);
    PortfolioTransaction sell = portfolio.getTransactions().get(1);
    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"));
    assertThat(record.getSharesHeld(), is(0L));
    // no changes in holdings, ttwror must (without taxes and tax refunds):
    double startValue = delivery.getAmount() - delivery.getUnitSum(Unit.Type.TAX).getAmount();
    double endValue = sell.getAmount() + sell.getUnitSum(Unit.Type.TAX).getAmount();
    double ttwror = (endValue / startValue) - 1;
    assertThat(record.getTrueTimeWeightedRateOfReturn(), closeTo(ttwror, 0.0001));
    // accrued taxes must be 0 (paid 10 on delivery + 5 tax refund + 10
    // taxes on sell):
    assertThat(record.getTaxes(), is(Money.of(CurrencyUnit.EUR, 15_00L)));
    // accrued fees must be 20 (paid 10 on delivery + 10 on sell)
    assertThat(record.getFees(), is(Money.of(CurrencyUnit.EUR, 20_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
    assertThatTTWROROfPortfolioIsLessThan(client, clientIndex, ttwror);
    // the irr must not include taxes as well (compared with Excel):
    assertThat(record.getIrr(), closeTo(-0.032248297, 0.0001));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Client(name.abuchen.portfolio.model.Client) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) Test(org.junit.Test)

Example 17 with Portfolio

use of name.abuchen.portfolio.model.Portfolio 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 18 with Portfolio

use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.

the class ClassificationIndexTest method testThatTaxesAreNotIncludedInTTWRORCalculation.

@Test
public void testThatTaxesAreNotIncludedInTTWRORCalculation() {
    Client client = new Client();
    Security security = // 
    new SecurityBuilder().addPrice("2015-12-31", // 
    Values.Quote.factorize(100)).addPrice("2016-12-31", // 
    Values.Quote.factorize(110)).addTo(client);
    Account account = // 
    new AccountBuilder().deposit_("2014-01-01", Values.Amount.factorize(1000)).addTo(client);
    AccountTransaction t = new AccountTransaction();
    t.setType(AccountTransaction.Type.DIVIDENDS);
    t.setDateTime(LocalDateTime.parse("2016-06-01T00:00"));
    t.setSecurity(security);
    t.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100)));
    t.setShares(Values.Share.factorize(10));
    account.addTransaction(t);
    Portfolio portfolio = // 
    new PortfolioBuilder(account).addTo(client);
    BuySellEntry buy = new BuySellEntry(portfolio, account);
    buy.setType(PortfolioTransaction.Type.BUY);
    buy.setDate(LocalDateTime.parse("2015-12-31T00:00"));
    buy.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1000)));
    buy.setShares(Values.Share.factorize(10));
    buy.setSecurity(security);
    buy.insert();
    BuySellEntry sell = new BuySellEntry(portfolio, account);
    sell.setType(PortfolioTransaction.Type.SELL);
    sell.setDate(LocalDateTime.parse("2016-12-31T00:00"));
    sell.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(1070)));
    sell.setShares(Values.Share.factorize(10));
    sell.setSecurity(security);
    sell.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(30))));
    sell.insert();
    Classification classification = new Classification(null, null);
    classification.addAssignment(new Assignment(security));
    List<Exception> warnings = new ArrayList<Exception>();
    PerformanceIndex index = PerformanceIndex.forClassification(client, new TestCurrencyConverter(), classification, new ReportingPeriod.FromXtoY(LocalDate.parse("2015-01-01"), LocalDate.parse("2017-01-01")), warnings);
    assertThat(warnings.isEmpty(), is(true));
    // dividend payment 10% * quote change 10%
    assertThat(index.getFinalAccumulatedPercentage(), IsCloseTo.closeTo((1.1 * 1.1) - 1, 0.000000001d));
    // add taxes to dividend payment
    t.addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(50))));
    index = PerformanceIndex.forClassification(client, new TestCurrencyConverter(), classification, new ReportingPeriod.FromXtoY(LocalDate.parse("2015-01-01"), LocalDate.parse("2017-01-01")), warnings);
    // dividend payment 15% * quote change 10%
    assertThat(index.getFinalAccumulatedPercentage(), IsCloseTo.closeTo((1.15 * 1.1) - 1, 0.000000001d));
}
Also used : Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Portfolio(name.abuchen.portfolio.model.Portfolio) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Security(name.abuchen.portfolio.model.Security) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) Assignment(name.abuchen.portfolio.model.Classification.Assignment) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Classification(name.abuchen.portfolio.model.Classification) AccountBuilder(name.abuchen.portfolio.AccountBuilder) Client(name.abuchen.portfolio.model.Client) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Example 19 with Portfolio

use of name.abuchen.portfolio.model.Portfolio 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 20 with Portfolio

use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.

the class ClientPerformanceSnapshotTest method testInboundDeliveryWithFees.

@Test
public void testInboundDeliveryWithFees() {
    Client client = new Client();
    Security security = new SecurityBuilder().addTo(client);
    Portfolio portfolio = new PortfolioBuilder().addTo(client);
    PortfolioTransaction delivery = new PortfolioTransaction();
    delivery.setDateTime(LocalDateTime.parse("2011-03-01T00:00"));
    delivery.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
    delivery.setSecurity(security);
    delivery.setMonetaryAmount(Money.of(CurrencyUnit.EUR, 100_00));
    delivery.addUnit(new Transaction.Unit(Transaction.Unit.Type.TAX, Money.of(CurrencyUnit.EUR, 10_00)));
    delivery.addUnit(new Transaction.Unit(Transaction.Unit.Type.FEE, Money.of(CurrencyUnit.EUR, 10_00)));
    assertThat(delivery.getGrossValue(), is(Money.of(CurrencyUnit.EUR, 80_00)));
    portfolio.addTransaction(delivery);
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
    assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 0)));
    assertThat(snapshot.getValue(CategoryType.FEES), is(Money.of(CurrencyUnit.EUR, 10_00)));
    assertThat(snapshot.getValue(CategoryType.TAXES), is(Money.of(CurrencyUnit.EUR, 10_00)));
    assertThat(snapshot.getValue(CategoryType.TRANSFERS), is(Money.of(CurrencyUnit.EUR, 100_00)));
    assertThatCalculationWorksOut(snapshot, converter);
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Transaction(name.abuchen.portfolio.model.Transaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Unit(name.abuchen.portfolio.model.Transaction.Unit) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) Test(org.junit.Test)

Aggregations

Portfolio (name.abuchen.portfolio.model.Portfolio)75 Security (name.abuchen.portfolio.model.Security)52 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)44 Test (org.junit.Test)41 Account (name.abuchen.portfolio.model.Account)39 Client (name.abuchen.portfolio.model.Client)38 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)24 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)21 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)20 Unit (name.abuchen.portfolio.model.Transaction.Unit)19 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)17 LocalDate (java.time.LocalDate)16 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)12 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11 Money (name.abuchen.portfolio.money.Money)11 ArrayList (java.util.ArrayList)10 Values (name.abuchen.portfolio.money.Values)10 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)9 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)9 Collections (java.util.Collections)8