use of name.abuchen.portfolio.model.Classification.Assignment in project portfolio by buchen.
the class AccountBuilder method assign.
public AccountBuilder assign(Taxonomy taxonomy, String id, int weight) {
Classification classification = taxonomy.getClassificationById(id);
classification.addAssignment(new Assignment(account, weight));
return this;
}
use of name.abuchen.portfolio.model.Classification.Assignment in project portfolio by buchen.
the class ClientClassificationFilter method addBuySellT.
private void addBuySellT(CalculationState state, Portfolio portfolio, PortfolioTransaction t) {
int securityWeight = state.getWeight(t.getSecurity());
long taxes = value(t.getUnitSum(Unit.Type.TAX).getAmount(), securityWeight);
long securityAmount = value(t.getAmount(), securityWeight);
securityAmount = t.getType() == PortfolioTransaction.Type.BUY ? securityAmount - taxes : securityAmount + taxes;
Account account = (Account) t.getCrossEntry().getCrossOwner(t);
int accountWeight = state.getWeight(account);
long accountAmount = value(t.getAmount(), accountWeight);
long commonAmount = Math.min(securityAmount, accountAmount);
int commonWeight = (int) Math.round(((double) commonAmount / (double) securityAmount) * securityWeight);
// create a buy/sell transactions with the amount shared by the account
// assignment and the security assignment
BuySellEntry copy = new BuySellEntry(state.asReadOnly(portfolio), state.account2readonly.get(account));
copy.setDate(t.getDateTime());
copy.setCurrencyCode(t.getCurrencyCode());
copy.setSecurity(t.getSecurity());
copy.setType(t.getType());
copy.setNote(t.getNote());
copy.setShares(value(t.getShares(), commonWeight));
copy.setAmount(commonAmount);
// copy all units (except for taxes) over to the new transaction
t.getUnits().filter(u -> u.getType() != Unit.Type.TAX).forEach(u -> copy.getPortfolioTransaction().addUnit(value(u, commonWeight)));
state.asReadOnly(portfolio).internalAddTransaction(copy.getPortfolioTransaction());
state.asReadOnly(account).internalAddTransaction(copy.getAccountTransaction());
if (accountAmount - commonAmount > 0) {
AccountTransaction ta = new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), accountAmount - commonAmount, null, t.getType() == PortfolioTransaction.Type.BUY ? AccountTransaction.Type.REMOVAL : AccountTransaction.Type.DEPOSIT);
state.asReadOnly(account).internalAddTransaction(ta);
}
if (securityAmount - commonAmount > 0) {
PortfolioTransaction tp = new PortfolioTransaction();
tp.setDateTime(t.getDateTime());
tp.setCurrencyCode(t.getCurrencyCode());
tp.setSecurity(t.getSecurity());
tp.setShares(value(t.getShares(), securityWeight - commonWeight));
tp.setType(t.getType() == PortfolioTransaction.Type.BUY ? PortfolioTransaction.Type.DELIVERY_INBOUND : PortfolioTransaction.Type.DELIVERY_OUTBOUND);
tp.setAmount(securityAmount - commonAmount);
t.getUnits().filter(u -> u.getType() != Unit.Type.TAX).forEach(u -> tp.addUnit(value(u, securityWeight - commonWeight)));
state.asReadOnly(portfolio).internalAddTransaction(tp);
}
}
use of name.abuchen.portfolio.model.Classification.Assignment 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.Assignment in project portfolio by buchen.
the class AbstractNodeTreeViewer method fillContextMenu.
protected // NOSONAR
void fillContextMenu(// NOSONAR
IMenuManager manager) {
// do not show context menu if multiple nodes are selected
IStructuredSelection selection = (IStructuredSelection) nodeViewer.getSelection();
if (selection.isEmpty() || selection.size() > 1)
return;
TaxonomyNode node = (TaxonomyNode) selection.getFirstElement();
if (node.isUnassignedCategory())
return;
// allow inherited views to contribute to the context menu
manager.add(new Separator(MENU_GROUP_CUSTOM_ACTIONS));
manager.add(new Separator(MENU_GROUP_DEFAULT_ACTIONS));
if (node.isClassification()) {
manager.add(new SimpleAction(Messages.MenuTaxonomyClassificationCreate, a -> doAddClassification(node)));
TaxonomyNode unassigned = getModel().getUnassignedNode();
if (!unassigned.getChildren().isEmpty()) {
MenuManager subMenu = new MenuManager(Messages.MenuTaxonomyMakeAssignment);
addAvailableAssignments(subMenu, node);
manager.add(subMenu);
}
manager.add(new Separator());
MenuManager sorting = new MenuManager(Messages.MenuTaxonomySortTreeBy);
sorting.add(new SimpleAction(Messages.MenuTaxonomySortByTypName, a -> doSort(node, true)));
sorting.add(new SimpleAction(Messages.MenuTaxonomySortByName, a -> doSort(node, false)));
manager.add(sorting);
if (!node.isRoot()) {
manager.add(new Separator(MENU_GROUP_DELETE_ACTIONS));
manager.add(new SimpleAction(Messages.MenuTaxonomyClassificationDelete, a -> doDeleteClassification(node)));
}
} else {
// node is assignment, but not in unassigned category
if (!node.getParent().isUnassignedCategory()) {
manager.add(new SimpleAction(Messages.MenuTaxonomyAssignmentRemove, a -> {
int oldWeight = node.getWeight();
node.setWeight(0);
doChangeAssignmentWeight(node, oldWeight);
onTaxnomyNodeEdited(getModel().getVirtualRootNode());
}));
}
Security security = node.getBackingSecurity();
if (security != null) {
manager.add(new Separator());
manager.add(new BookmarkMenu(part, security));
}
}
}
use of name.abuchen.portfolio.model.Classification.Assignment in project portfolio by buchen.
the class AbstractNodeTreeViewer method doChangeAssignmentWeight.
private void doChangeAssignmentWeight(TaxonomyNode node, int oldWeight) {
int change = oldWeight - node.getWeight();
if (// was 'fixed' after editing, e.g. was >= 100%
change == 0)
return;
if (node.getWeight() == 0)
node.getParent().removeChild(node);
// change total weight as recorded in the model
InvestmentVehicle investmentVehicle = node.getAssignment().getInvestmentVehicle();
final int totalWeight = getModel().getWeightByInvestmentVehicle(investmentVehicle) - change;
getModel().setWeightByInvestmentVehicle(investmentVehicle, totalWeight);
// check if change is fixing weight errors -> no new unassigned vehicles
change = Math.min(change, Classification.ONE_HUNDRED_PERCENT - totalWeight);
if (change == 0)
return;
// change existing unassigned node *or* create new unassigned node
TaxonomyNode unassigned = getModel().getUnassignedNode().getChildByInvestmentVehicle(investmentVehicle);
if (unassigned != null) {
// change existing node in unassigned category
int newWeight = unassigned.getWeight() + change;
if (newWeight <= 0) {
getModel().getUnassignedNode().removeChild(unassigned);
getModel().setWeightByInvestmentVehicle(investmentVehicle, totalWeight - unassigned.getWeight());
} else {
unassigned.setWeight(newWeight);
getModel().setWeightByInvestmentVehicle(investmentVehicle, totalWeight + change);
}
} else if (change > 0) {
// create a new node, but only if change is positive
Assignment assignment = new Assignment(investmentVehicle);
assignment.setWeight(change);
getModel().getUnassignedNode().addChild(assignment);
getModel().setWeightByInvestmentVehicle(investmentVehicle, totalWeight + change);
}
// do not fire model change -> called within modification listener
}
Aggregations