Search in sources :

Example 1 with Assignment

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;
}
Also used : Assignment(name.abuchen.portfolio.model.Classification.Assignment) Classification(name.abuchen.portfolio.model.Classification)

Example 2 with Assignment

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);
    }
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Client(name.abuchen.portfolio.model.Client) Account(name.abuchen.portfolio.model.Account) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Set(java.util.Set) HashMap(java.util.HashMap) Security(name.abuchen.portfolio.model.Security) Classification(name.abuchen.portfolio.model.Classification) Visitor(name.abuchen.portfolio.model.Taxonomy.Visitor) HashSet(java.util.HashSet) Unit(name.abuchen.portfolio.model.Transaction.Unit) Map(java.util.Map) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) Assignment(name.abuchen.portfolio.model.Classification.Assignment) Portfolio(name.abuchen.portfolio.model.Portfolio) Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 3 with Assignment

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));
}
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 4 with Assignment

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));
        }
    }
}
Also used : NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) Arrays(java.util.Arrays) DND(org.eclipse.swt.dnd.DND) Classification(name.abuchen.portfolio.model.Classification) ModificationListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.ModificationListener) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) Composite(org.eclipse.swt.widgets.Composite) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) UIConstants(name.abuchen.portfolio.ui.UIConstants) Separator(org.eclipse.jface.action.Separator) Predicate(java.util.function.Predicate) MenuManager(org.eclipse.jface.action.MenuManager) Set(java.util.Set) Security(name.abuchen.portfolio.model.Security) UUID(java.util.UUID) Display(org.eclipse.swt.widgets.Display) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ExchangeRate(name.abuchen.portfolio.money.ExchangeRate) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) Transfer(org.eclipse.swt.dnd.Transfer) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) List(java.util.List) Colors(name.abuchen.portfolio.ui.util.Colors) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SecurityTransfer(name.abuchen.portfolio.ui.dnd.SecurityTransfer) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TransferData(org.eclipse.swt.dnd.TransferData) DragSourceAdapter(org.eclipse.swt.dnd.DragSourceAdapter) ContextMenu(name.abuchen.portfolio.ui.util.ContextMenu) Values(name.abuchen.portfolio.money.Values) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) BookmarkMenu(name.abuchen.portfolio.ui.util.BookmarkMenu) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) Messages(name.abuchen.portfolio.ui.Messages) TreeSelection(org.eclipse.jface.viewers.TreeSelection) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) LinkedList(java.util.LinkedList) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport) Viewer(org.eclipse.jface.viewers.Viewer) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Column(name.abuchen.portfolio.ui.util.viewers.Column) Action(org.eclipse.jface.action.Action) TreeViewerCSVExporter(name.abuchen.portfolio.ui.util.TreeViewerCSVExporter) Preference(org.eclipse.e4.core.di.extensions.Preference) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) Named(name.abuchen.portfolio.model.Named) StringJoiner(java.util.StringJoiner) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) ToolTip(org.eclipse.jface.window.ToolTip) Collections(java.util.Collections) Control(org.eclipse.swt.widgets.Control) Assignment(name.abuchen.portfolio.model.Classification.Assignment) BookmarkMenu(name.abuchen.portfolio.ui.util.BookmarkMenu) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Security(name.abuchen.portfolio.model.Security) Separator(org.eclipse.jface.action.Separator)

Example 5 with Assignment

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
}
Also used : Assignment(name.abuchen.portfolio.model.Classification.Assignment) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle)

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