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);
}
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());
}
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;
}
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());
}
}
}
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);
}
Aggregations