Search in sources :

Example 11 with TestCurrencyConverter

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

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

Example 13 with TestCurrencyConverter

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

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

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

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