Search in sources :

Example 26 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.

the class ClassificationTestCase method testCase12_ForexAccountOut100_AccountIn50.

@Test
public void testCase12_ForexAccountOut100_AccountIn50() {
    Taxonomy case12 = client.getTaxonomies().stream().filter(t -> "case_12".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    // check performance of 'subcategory'
    Classification ccategory = case12.getAllClassifications().stream().filter(c -> "category".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    Client categoryClient = new ClientClassificationFilter(ccategory).filter(client);
    List<PortfolioTransaction> txp = categoryClient.getPortfolios().stream().flatMap(p -> p.getTransactions().stream()).collect(Collectors.toList());
    assertThat(txp, hasSize(0));
    List<AccountTransaction> txa = categoryClient.getAccounts().stream().filter(a -> "Account Forex".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    // check cash transfers
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.TRANSFER_OUT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(50)))))));
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(50)))))));
    txa = categoryClient.getAccounts().stream().filter(a -> "Konto 3".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.TRANSFER_IN)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(78.19 * 0.5d)))))));
    // create index
    List<Exception> warnings = new ArrayList<>();
    PerformanceIndex index_subcategory = PerformanceIndex.forClassification(client, converter, ccategory, interval, warnings);
    assertThat(warnings.isEmpty(), is(true));
    // 343.42 EUR (Konto 3 EUR)
    // 423.52 USD / 1.2141 (exchange rate in TestCurrencyConverter)
    assertThat(index_subcategory.getTotals()[index_subcategory.getTotals().length - 1], is(// 
    Values.Amount.factorize(343.42) + Values.Amount.factorize(423.52 / 1.2141)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) BeforeClass(org.junit.BeforeClass) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) LocalDateTime(java.time.LocalDateTime) Classification(name.abuchen.portfolio.model.Classification) ArrayList(java.util.ArrayList) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Assert.assertThat(org.junit.Assert.assertThat) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) ClientFactory(name.abuchen.portfolio.model.ClientFactory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Taxonomy(name.abuchen.portfolio.model.Taxonomy) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) Collectors(java.util.stream.Collectors) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) List(java.util.List) LocalDate(java.time.LocalDate) Taxonomy(name.abuchen.portfolio.model.Taxonomy) ArrayList(java.util.ArrayList) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) Classification(name.abuchen.portfolio.model.Classification) Client(name.abuchen.portfolio.model.Client) Test(org.junit.Test)

Example 27 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.

the class VolatilityTestCase method testVolatilityOfSharesHeldIsIdenticalToExcel.

@Test
public void testVolatilityOfSharesHeldIsIdenticalToExcel() throws IOException {
    ReportingPeriod report = new ReportingPeriod.FromXtoY(LocalDate.parse("2014-01-31"), LocalDate.parse("2014-07-31"));
    List<Exception> warnings = new ArrayList<>();
    PerformanceIndex index = PerformanceIndex.forClient(client, converter, report, warnings);
    assertThat(warnings, empty());
    // excel
    assertThat(index.getVolatility().getStandardDeviation(), closeTo(0.141568791460, 0.1e-10));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) Test(org.junit.Test)

Example 28 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.

the class VolatilityTestCase method testVolatilityIfSecurityIsSoldDuringReportingPeriod.

@Test
public void testVolatilityIfSecurityIsSoldDuringReportingPeriod() throws IOException {
    ReportingPeriod report = new ReportingPeriod.FromXtoY(LocalDate.parse("2014-01-31"), LocalDate.parse("2015-01-31"));
    List<Exception> warnings = new ArrayList<>();
    Security basf = client.getSecurities().stream().filter(s -> "Basf SE".equals(s.getName())).findAny().get();
    PerformanceIndex index = PerformanceIndex.forInvestment(client, converter, basf, report, warnings);
    PerformanceIndex clientIndex = PerformanceIndex.forClient(client, converter, report, warnings);
    assertThat(warnings, empty());
    // excel
    assertThat(index.getVolatility().getStandardDeviation(), closeTo(0.200573810778, 0.1e-10));
    // excel
    assertThat(clientIndex.getVolatility().getStandardDeviation(), closeTo(0.200599730118, 0.1e-10));
    assertThat(index.getDates()[index.getDates().length - 1], is(LocalDate.parse("2015-01-31")));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) Test(org.junit.Test)

Example 29 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.

the class SecurityPerformanceRecord method calculateTTWROR.

private void calculateTTWROR(Client client, CurrencyConverter converter, ReportingPeriod period) {
    PerformanceIndex index = PerformanceIndex.forInvestment(client, converter, security, period, new ArrayList<Exception>());
    this.twror = index.getFinalAccumulatedPercentage();
    this.drawdown = index.getDrawdown();
    this.volatility = index.getVolatility();
}
Also used : PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex)

Example 30 with PerformanceIndex

use of name.abuchen.portfolio.snapshot.PerformanceIndex in project portfolio by buchen.

the class PerformanceCalculationWidget method update.

@Override
public void update() {
    title.setText(getWidget().getLabel());
    PerformanceIndex index = getDashboardData().calculate(get(DataSeriesConfig.class).getDataSeries(), get(ReportingPeriodConfig.class).getReportingPeriod());
    ClientPerformanceSnapshot snapshot = index.getClientPerformanceSnapshot();
    int ii = 0;
    for (ClientPerformanceSnapshot.Category category : snapshot.getCategories()) {
        signs[ii].setText(category.getSign());
        labels[ii].setText(category.getLabel());
        values[ii].setText(Values.Money.format(category.getValuation(), getClient().getBaseCurrency()));
        if (++ii >= labels.length)
            break;
    }
    container.layout();
}
Also used : PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) ClientPerformanceSnapshot(name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot)

Aggregations

PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)33 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)23 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)22 Test (org.junit.Test)22 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)19 Security (name.abuchen.portfolio.model.Security)18 Client (name.abuchen.portfolio.model.Client)17 Classification (name.abuchen.portfolio.model.Classification)15 LocalDate (java.time.LocalDate)14 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)14 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)14 Taxonomy (name.abuchen.portfolio.model.Taxonomy)14 LocalDateTime (java.time.LocalDateTime)13 List (java.util.List)13 Collectors (java.util.stream.Collectors)13 ClientFactory (name.abuchen.portfolio.model.ClientFactory)13 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)13 Money (name.abuchen.portfolio.money.Money)13 Values (name.abuchen.portfolio.money.Values)13