Search in sources :

Example 11 with Classification

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

Example 12 with Classification

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

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

the class OpenSampleHandler method applyTaxonomyLabels.

private void applyTaxonomyLabels(TaxonomyTemplate template, Taxonomy taxonomy) {
    Taxonomy original = template.buildOriginal();
    taxonomy.setName(original.getName());
    taxonomy.setDimensions(original.getDimensions());
    Map<String, Classification> translated = // 
    original.getAllClassifications().stream().collect(Collectors.toMap(c -> c.getId(), c -> c));
    taxonomy.foreach(new Visitor() {

        @Override
        public void visit(Classification classification) {
            Classification t = translated.get(classification.getId());
            if (t != null) {
                classification.setName(t.getName());
                classification.setNote(t.getNote());
            }
        }
    });
}
Also used : Client(name.abuchen.portfolio.model.Client) IServiceConstants(org.eclipse.e4.ui.services.IServiceConstants) ProgressMonitorInputStream(name.abuchen.portfolio.util.ProgressMonitorInputStream) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) Execute(org.eclipse.e4.core.di.annotations.Execute) Classification(name.abuchen.portfolio.model.Classification) MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) Visitor(name.abuchen.portfolio.model.Taxonomy.Visitor) Inject(javax.inject.Inject) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) TokenReplacingReader(name.abuchen.portfolio.util.TokenReplacingReader) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) ClientFactory(name.abuchen.portfolio.model.ClientFactory) Named(javax.inject.Named) ITokenResolver(name.abuchen.portfolio.util.TokenReplacingReader.ITokenResolver) Taxonomy(name.abuchen.portfolio.model.Taxonomy) TaxonomyTemplate(name.abuchen.portfolio.model.TaxonomyTemplate) UIConstants(name.abuchen.portfolio.ui.UIConstants) MApplication(org.eclipse.e4.ui.model.application.MApplication) Shell(org.eclipse.swt.widgets.Shell) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UISynchronize(org.eclipse.e4.ui.di.UISynchronize) PortfolioPlugin(name.abuchen.portfolio.ui.PortfolioPlugin) EModelService(org.eclipse.e4.ui.workbench.modeling.EModelService) PartState(org.eclipse.e4.ui.workbench.modeling.EPartService.PartState) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) InputStream(java.io.InputStream) Visitor(name.abuchen.portfolio.model.Taxonomy.Visitor) Taxonomy(name.abuchen.portfolio.model.Taxonomy) Classification(name.abuchen.portfolio.model.Classification)

Example 14 with Classification

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

the class ReBalancingViewer method doFixClassificationWeights.

private void doFixClassificationWeights(TaxonomyNode node) {
    Classification classification = node.getClassification();
    if (node.isUnassignedCategory()) {
        classification.setWeight(0);
    } else if (node.isRoot() || node.getParent().isRoot()) {
        classification.setWeight(Classification.ONE_HUNDRED_PERCENT);
    } else {
        classification.setWeight(0);
        int weight = Math.max(0, Classification.ONE_HUNDRED_PERCENT - classification.getParent().getChildrenWeight());
        classification.setWeight(weight);
    }
    onTaxnomyNodeEdited(node);
}
Also used : Classification(name.abuchen.portfolio.model.Classification)

Example 15 with Classification

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

the class TaxonomyNode method addChild.

/* package */
TaxonomyNode addChild(Classification newClassification) {
    Classification classification = getClassification();
    if (classification == null)
        return null;
    newClassification.setWeight(Classification.ONE_HUNDRED_PERCENT - classification.getChildrenWeight());
    newClassification.setParent(classification);
    classification.addChild(newClassification);
    TaxonomyNode newChild = new ClassificationNode(this, newClassification);
    // set actuals and target; will be calculated later but must not be null
    newChild.setActual(Money.of(actual.getCurrencyCode(), 0));
    newChild.setTarget(Money.of(target.getCurrencyCode(), 0));
    // unclassified node shall stay at the end
    int insertAt = isRoot() ? children.size() - 1 : children.size();
    children.add(insertAt, newChild);
    for (int ii = 0; ii < children.size(); ii++) children.get(ii).setRank(ii);
    return newChild;
}
Also used : Classification(name.abuchen.portfolio.model.Classification)

Aggregations

Classification (name.abuchen.portfolio.model.Classification)36 ArrayList (java.util.ArrayList)21 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)20 Client (name.abuchen.portfolio.model.Client)20 Taxonomy (name.abuchen.portfolio.model.Taxonomy)20 Test (org.junit.Test)20 IOException (java.io.IOException)18 Security (name.abuchen.portfolio.model.Security)17 PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)17 Collectors (java.util.stream.Collectors)16 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)16 ClientFactory (name.abuchen.portfolio.model.ClientFactory)16 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)16 LocalDate (java.time.LocalDate)15 LocalDateTime (java.time.LocalDateTime)15 List (java.util.List)15 Money (name.abuchen.portfolio.money.Money)15 Values (name.abuchen.portfolio.money.Values)15 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)15 ClientClassificationFilter (name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter)15