Search in sources :

Example 6 with Assignment

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

the class TaxonomyModel method addUnassigned.

private void addUnassigned(Client client) {
    for (Security security : client.getSecurities()) {
        Assignment assignment = new Assignment(security);
        assignment.setWeight(0);
        investmentVehicle2weight.put(security, assignment);
    }
    for (Account account : client.getAccounts()) {
        Assignment assignment = new Assignment(account);
        assignment.setWeight(0);
        investmentVehicle2weight.put(account, assignment);
    }
    visitAll(node -> {
        if (!(node instanceof AssignmentNode))
            return;
        Assignment assignment = node.getAssignment();
        Assignment count = investmentVehicle2weight.get(assignment.getInvestmentVehicle());
        count.setWeight(count.getWeight() + assignment.getWeight());
    });
    List<Assignment> unassigned = new ArrayList<>();
    for (Assignment assignment : investmentVehicle2weight.values()) {
        if (assignment.getWeight() >= Classification.ONE_HUNDRED_PERCENT)
            continue;
        Assignment a = new Assignment(assignment.getInvestmentVehicle());
        a.setWeight(Classification.ONE_HUNDRED_PERCENT - assignment.getWeight());
        unassigned.add(a);
        assignment.setWeight(Classification.ONE_HUNDRED_PERCENT);
    }
    Collections.sort(unassigned, (o1, o2) -> o1.getInvestmentVehicle().toString().compareToIgnoreCase(o2.getInvestmentVehicle().toString()));
    for (Assignment assignment : unassigned) unassignedNode.addChild(assignment);
}
Also used : Assignment(name.abuchen.portfolio.model.Classification.Assignment) Account(name.abuchen.portfolio.model.Account) AssignmentNode(name.abuchen.portfolio.ui.views.taxonomy.TaxonomyNode.AssignmentNode) ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security)

Example 7 with Assignment

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

the class TaxonomyModel method visitActuals.

private void visitActuals(ClientSnapshot snapshot, TaxonomyNode node) {
    MutableMoney actual = MutableMoney.of(snapshot.getCurrencyCode());
    for (TaxonomyNode child : node.getChildren()) {
        visitActuals(snapshot, child);
        actual.add(child.getActual());
    }
    if (node.isAssignment()) {
        Assignment assignment = node.getAssignment();
        AssetPosition p = snapshot.getPositionsByVehicle().get(assignment.getInvestmentVehicle());
        if (p != null) {
            Money valuation = p.getValuation();
            actual.add(Money.of(valuation.getCurrencyCode(), Math.round(valuation.getAmount() * assignment.getWeight() / (double) Classification.ONE_HUNDRED_PERCENT)));
        }
    }
    node.setActual(actual.toMoney());
}
Also used : Assignment(name.abuchen.portfolio.model.Classification.Assignment) Money(name.abuchen.portfolio.money.Money) MutableMoney(name.abuchen.portfolio.money.MutableMoney) MutableMoney(name.abuchen.portfolio.money.MutableMoney) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition)

Example 8 with Assignment

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

the class SecurityBuilder method assign.

public SecurityBuilder assign(Taxonomy taxonomy, String id, int weight) {
    Classification classification = taxonomy.getClassificationById(id);
    classification.addAssignment(new Assignment(security, weight));
    return this;
}
Also used : Assignment(name.abuchen.portfolio.model.Classification.Assignment) Classification(name.abuchen.portfolio.model.Classification)

Example 9 with Assignment

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

the class GroupByTaxonomy method createCategoriesAndAllocate.

private void createCategoriesAndAllocate(final Map<InvestmentVehicle, Item> vehicle2position) {
    for (Classification classification : taxonomy.getRoot().getChildren()) {
        final Map<InvestmentVehicle, Item> vehicle2item = new HashMap<>();
        // first: assign items to categories
        // item.weight records both the weight
        // (a) already assigned to any category
        // (b) assigned to this category
        classification.accept(new Taxonomy.Visitor() {

            @Override
            public void visit(Classification classification, Assignment assignment) {
                Item item = vehicle2position.get(assignment.getInvestmentVehicle());
                if (item != null) {
                    // record (a)
                    item.weight += assignment.getWeight();
                    SecurityPosition position = item.position;
                    if (assignment.getWeight() == Classification.ONE_HUNDRED_PERCENT) {
                        vehicle2item.put(assignment.getInvestmentVehicle(), item);
                    } else {
                        Item other = vehicle2item.get(assignment.getInvestmentVehicle());
                        if (other == null) {
                            other = new Item(position);
                            vehicle2item.put(assignment.getInvestmentVehicle(), other);
                        }
                        // record (b) into the copy
                        other.weight += assignment.getWeight();
                    }
                }
            }
        });
        if (!vehicle2item.isEmpty()) {
            AssetCategory category = new AssetCategory(classification, converter, date, valuation);
            categories.add(category);
            for (Entry<InvestmentVehicle, Item> entry : vehicle2item.entrySet()) {
                Item item = entry.getValue();
                SecurityPosition position = item.position;
                if (item.weight != Classification.ONE_HUNDRED_PERCENT)
                    position = SecurityPosition.split(position, item.weight);
                category.addPosition(new AssetPosition(position, converter, date, getValuation()));
            }
            // sort positions by name
            Collections.sort(category.getPositions(), new AssetPosition.ByDescription());
        }
    }
}
Also used : HashMap(java.util.HashMap) Taxonomy(name.abuchen.portfolio.model.Taxonomy) Assignment(name.abuchen.portfolio.model.Classification.Assignment) Classification(name.abuchen.portfolio.model.Classification) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle)

Example 10 with Assignment

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

the class ClientFactory method addAssetClassesAsTaxonomy.

private static void addAssetClassesAsTaxonomy(Client client) {
    // $NON-NLS-1$
    TaxonomyTemplate template = TaxonomyTemplate.byId("assetclasses");
    Taxonomy taxonomy = template.buildFromTemplate();
    // $NON-NLS-1$
    taxonomy.setId("assetclasses");
    int rank = 1;
    // $NON-NLS-1$
    Classification cash = taxonomy.getClassificationById("CASH");
    for (Account account : client.getAccounts()) {
        Assignment assignment = new Assignment(account);
        assignment.setRank(rank++);
        cash.addAssignment(assignment);
    }
    for (Security security : client.getSecurities()) {
        Classification classification = taxonomy.getClassificationById(security.getType());
        if (classification != null) {
            Assignment assignment = new Assignment(security);
            assignment.setRank(rank++);
            classification.addAssignment(assignment);
        }
    }
    client.addTaxonomy(taxonomy);
}
Also used : Assignment(name.abuchen.portfolio.model.Classification.Assignment)

Aggregations

Assignment (name.abuchen.portfolio.model.Classification.Assignment)12 Classification (name.abuchen.portfolio.model.Classification)6 InvestmentVehicle (name.abuchen.portfolio.model.InvestmentVehicle)4 Security (name.abuchen.portfolio.model.Security)4 ArrayList (java.util.ArrayList)3 Account (name.abuchen.portfolio.model.Account)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)2 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)2 Client (name.abuchen.portfolio.model.Client)2 Portfolio (name.abuchen.portfolio.model.Portfolio)2 Unit (name.abuchen.portfolio.model.Transaction.Unit)2 Money (name.abuchen.portfolio.money.Money)2 LocalDate (java.time.LocalDate)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1