Search in sources :

Example 16 with PerformanceIndex

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

the class ReturnsVolatilityChartView method setChartSeries.

private void setChartSeries() {
    configurator.getSelectedDataSeries().forEach(series -> {
        PerformanceIndex index = cache.lookup(series, getReportingPeriod());
        Volatility volatility = index.getVolatility();
        ILineSeries lineSeries = chart.addScatterSeries(new double[] { volatility.getStandardDeviation() }, new double[] { index.getFinalAccumulatedPercentage() }, series.getLabel());
        Color color = resources.createColor(series.getColor());
        lineSeries.setLineColor(color);
        lineSeries.setSymbolColor(color);
        lineSeries.enableArea(series.isShowArea());
        lineSeries.setLineStyle(series.getLineStyle());
    });
}
Also used : Volatility(name.abuchen.portfolio.math.Risk.Volatility) ILineSeries(org.swtchart.ILineSeries) Color(org.eclipse.swt.graphics.Color) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex)

Example 17 with PerformanceIndex

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

the class MaxDrawdownDurationWidget method update.

@Override
public void update() {
    super.update();
    PerformanceIndex index = getDashboardData().getDataSeriesCache().lookup(get(DataSeriesConfig.class).getDataSeries(), get(ReportingPeriodConfig.class).getReportingPeriod());
    Drawdown drawdown = index.getDrawdown();
    Interval maxDDDuration = drawdown.getMaxDrawdownDuration();
    indicator.setText(MessageFormat.format(Messages.LabelXDays, maxDDDuration.getDays()));
    boolean isUntilEndOfPeriod = maxDDDuration.getEnd().equals(index.getReportInterval().getEndDate());
    String maxDDSupplement = isUntilEndOfPeriod ? Messages.TooltipMaxDrawdownDurationEndOfPeriod : Messages.TooltipMaxDrawdownDurationFromXtoY;
    // recovery time
    Interval recoveryTime = drawdown.getLongestRecoveryTime();
    isUntilEndOfPeriod = recoveryTime.getEnd().equals(index.getReportInterval().getEndDate());
    String recoveryTimeSupplement = isUntilEndOfPeriod ? Messages.TooltipMaxDrawdownDurationEndOfPeriod : Messages.TooltipMaxDrawdownDurationFromXtoY;
    InfoToolTip.attach(indicator, // $NON-NLS-1$
    Messages.TooltipMaxDrawdownDuration + "\n\n" + MessageFormat.format(maxDDSupplement, formatter.format(maxDDDuration.getStart()), formatter.format(maxDDDuration.getEnd())) + // $NON-NLS-1$
    "\n\n" + MessageFormat.format(Messages.TooltipMaxDurationLowToHigh, recoveryTime.getDays()) + MessageFormat.format(recoveryTimeSupplement, formatter.format(recoveryTime.getStart()), formatter.format(recoveryTime.getEnd())));
}
Also used : PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) Drawdown(name.abuchen.portfolio.math.Risk.Drawdown) Interval(name.abuchen.portfolio.util.Interval)

Example 18 with PerformanceIndex

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

the class DataSeriesCache method lookup.

public PerformanceIndex lookup(DataSeries series, ReportingPeriod reportingPeriod) {
    // Every data series is cached separately except the for the client. The
    // client data series are created out of the same PerformanceIndex
    // instance, e.g. accumulated and delta performance.
    // $NON-NLS-1$
    String uuid = series.getType() == DataSeries.Type.CLIENT ? "$client$" : series.getUUID();
    CacheKey key = new CacheKey(uuid, reportingPeriod);
    // #computeIfAbsent leads to a ConcurrentMapModificdation b/c #calculate
    // might call #lookup to calculcate other cache entries
    PerformanceIndex result = cache.get(key);
    if (result != null)
        return result;
    result = calculate(series, reportingPeriod);
    cache.put(key, result);
    return result;
}
Also used : PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex)

Example 19 with PerformanceIndex

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

the class ClientSecurityFilterTest method testThatAllSecuritiesHaveIdendicalPerformanceToClient.

@Test
public void testThatAllSecuritiesHaveIdendicalPerformanceToClient() {
    Client filtered = new ClientSecurityFilter(securityEUR, securityUSD).filter(client);
    assertThat(filtered.getAccounts(), hasSize(2));
    assertThat(filtered.getPortfolios(), hasSize(1));
    List<Exception> warnings = new ArrayList<>();
    TestCurrencyConverter converter = new TestCurrencyConverter();
    ReportingPeriod interval = new ReportingPeriod.FromXtoY(LocalDate.parse("2015-12-31"), LocalDate.parse("2017-01-31"));
    PerformanceIndex all = PerformanceIndex.forClient(client, converter, interval, warnings);
    assertThat(warnings, empty());
    PerformanceIndex filteredAll = PerformanceIndex.forClient(filtered, converter, interval, warnings);
    assertThat(warnings, empty());
    assertThat(all.getFinalAccumulatedPercentage(), is(filteredAll.getFinalAccumulatedPercentage()));
    assertThat(all.getDeltaPercentage(), is(filteredAll.getDeltaPercentage()));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) ArrayList(java.util.ArrayList) Client(name.abuchen.portfolio.model.Client) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) Test(org.junit.Test)

Example 20 with PerformanceIndex

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

the class ClassificationTestCase method testCase7_Account30Account30.

@Test
public void testCase7_Account30Account30() {
    Taxonomy case1 = client.getTaxonomies().stream().filter(t -> "case_7".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
    // check performance of 'subcategory'
    Classification ccategory = case1.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 -> "Konto 1".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-02T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2397.60 * 0.3)))))));
    // check that transfer between two accounts is created
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-25T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.TRANSFER_IN)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100 * 0.3)))))));
    txa = categoryClient.getAccounts().stream().filter(a -> "Konto 2".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
    assertThat(txa, hasItem(allOf(// 
    hasProperty("dateTime", is(LocalDateTime.parse("2012-01-25T00:00"))), // 
    hasProperty("type", is(AccountTransaction.Type.TRANSFER_OUT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100 * 0.3)))))));
    // create index
    List<Exception> warnings = new ArrayList<>();
    PerformanceIndex index_subcategory = PerformanceIndex.forClassification(client, converter, ccategory, interval, warnings);
    assertThat(warnings.isEmpty(), is(true));
    assertThat(index_subcategory.getTotals()[index_subcategory.getTotals().length - 1], is(Values.Amount.factorize(534.91)));
}
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)

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