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