Search in sources :

Example 66 with Portfolio

use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.

the class PortfolioListView method addNewButton.

private void addNewButton(ToolBar toolBar) {
    SimpleAction.Runnable newPortfolioAction = a -> {
        Portfolio portfolio = new Portfolio();
        portfolio.setName(Messages.LabelNoName);
        if (!getClient().getAccounts().isEmpty()) {
            portfolio.setReferenceAccount(getClient().getAccounts().get(0));
        } else {
            Account account = new Account();
            account.setName(Messages.LabelDefaultReferenceAccountName);
            getClient().addAccount(account);
            portfolio.setReferenceAccount(account);
        }
        getClient().addPortfolio(portfolio);
        markDirty();
        setInput();
        portfolios.editElement(portfolio, 0);
    };
    AbstractDropDown.create(toolBar, Messages.MenuCreatePortfolioOrTransaction, Images.PLUS.image(), SWT.NONE, (dd, manager) -> {
        manager.add(new SimpleAction(Messages.PortfolioMenuAdd, newPortfolioAction));
        manager.add(new Separator());
        Portfolio portfolio = (Portfolio) portfolios.getStructuredSelection().getFirstElement();
        new SecurityContextMenu(PortfolioListView.this).menuAboutToShow(manager, null, portfolio);
    });
}
Also used : NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) TableViewer(org.eclipse.jface.viewers.TableViewer) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) ToolBar(org.eclipse.swt.widgets.ToolBar) Images(name.abuchen.portfolio.ui.Images) ListEditingSupport(name.abuchen.portfolio.ui.util.viewers.ListEditingSupport) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Inject(javax.inject.Inject) ModificationListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.ModificationListener) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) Portfolio(name.abuchen.portfolio.model.Portfolio) Separator(org.eclipse.jface.action.Separator) Account(name.abuchen.portfolio.model.Account) CTabFolder(org.eclipse.swt.custom.CTabFolder) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) MenuManager(org.eclipse.jface.action.MenuManager) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) Action(org.eclipse.jface.action.Action) Display(org.eclipse.swt.widgets.Display) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) PortfolioSnapshot(name.abuchen.portfolio.snapshot.PortfolioSnapshot) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) CTabItem(org.eclipse.swt.custom.CTabItem) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Separator(org.eclipse.jface.action.Separator)

Example 67 with Portfolio

use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.

the class PortfolioListView method createTopTable.

// //////////////////////////////////////////////////////////////
// top table: accounts
// //////////////////////////////////////////////////////////////
protected void createTopTable(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    portfolios = new TableViewer(container, SWT.FULL_SELECTION);
    ColumnEditingSupport.prepare(portfolios);
    portfolioColumns = new // $NON-NLS-1$
    ShowHideColumnHelper(// $NON-NLS-1$
    PortfolioListView.class.getSimpleName() + "@top2", getPreferenceStore(), portfolios, layout);
    // $NON-NLS-1$
    Column column = new NameColumn("0", Messages.ColumnPortfolio, SWT.None, 100);
    column.setLabelProvider(new NameColumnLabelProvider() {

        @Override
        public Color getForeground(Object e) {
            boolean isRetired = ((Portfolio) e).isRetired();
            return isRetired ? Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY) : null;
        }
    });
    column.getEditingSupport().addListener(this);
    portfolioColumns.addColumn(column);
    column = new Column(Messages.ColumnReferenceAccount, SWT.None, 160);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Portfolio p = (Portfolio) e;
            return p.getReferenceAccount() != null ? p.getReferenceAccount().getName() : null;
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(Portfolio.class, "referenceAccount").attachTo(column);
    // $NON-NLS-1$
    new ListEditingSupport(Portfolio.class, "referenceAccount", getClient().getAccounts()).addListener(this).attachTo(column);
    portfolioColumns.addColumn(column);
    column = new NoteColumn();
    column.getEditingSupport().addListener(this);
    portfolioColumns.addColumn(column);
    portfolioColumns.createColumns();
    portfolios.getTable().setHeaderVisible(true);
    portfolios.getTable().setLinesVisible(true);
    portfolios.setContentProvider(ArrayContentProvider.getInstance());
    setInput();
    portfolios.addSelectionChangedListener(event -> {
        Portfolio portfolio = (Portfolio) ((IStructuredSelection) event.getSelection()).getFirstElement();
        if (portfolio != null) {
            transactions.setInput(portfolio, portfolio.getTransactions());
            transactions.refresh();
            CurrencyConverter converter = new CurrencyConverterImpl(factory, portfolio.getReferenceAccount().getCurrencyCode());
            statementOfAssets.setInput(PortfolioSnapshot.create(portfolio, converter, LocalDate.now()));
        } else {
            transactions.setInput(null, null);
            transactions.refresh();
            statementOfAssets.setInput((PortfolioSnapshot) null);
        }
    });
    hookContextMenu(portfolios.getTable(), this::fillPortfolioContextMenu);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Color(org.eclipse.swt.graphics.Color) Portfolio(name.abuchen.portfolio.model.Portfolio) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) ListEditingSupport(name.abuchen.portfolio.ui.util.viewers.ListEditingSupport) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 68 with Portfolio

use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.

the class ReviewExtractedItemsPage method preselectDropDowns.

private void preselectDropDowns() {
    // idea: generally one type of document (i.e. from the same bank) will
    // be imported into the same account
    List<Account> activeAccounts = client.getActiveAccounts();
    if (!activeAccounts.isEmpty()) {
        String uuid = preferences.getString(IMPORT_TARGET_ACCOUNT + extractor.getClass().getSimpleName());
        // do not trigger selection listener (-> do not user #setSelection)
        primaryAccount.getCombo().select(IntStream.range(0, activeAccounts.size()).filter(i -> activeAccounts.get(i).getUUID().equals(uuid)).findAny().orElse(0));
        secondaryAccount.getCombo().select(0);
    }
    List<Portfolio> activePortfolios = client.getActivePortfolios();
    if (!activePortfolios.isEmpty()) {
        String uuid = preferences.getString(IMPORT_TARGET_PORTFOLIO + extractor.getClass().getSimpleName());
        // do not trigger selection listener (-> do not user #setSelection)
        primaryPortfolio.getCombo().select(IntStream.range(0, activePortfolios.size()).filter(i -> activePortfolios.get(i).getUUID().equals(uuid)).findAny().orElse(0));
        secondaryPortfolio.getCombo().select(0);
    }
    if (extractor instanceof AssistantPDFExtractor) {
        String clazz = preferences.getString(IMPORT_TARGET_EXTRACTOR);
        List<Extractor> availableExtractors = ((AssistantPDFExtractor) extractor).getAvailableExtractors();
        OptionalInt index = IntStream.range(0, availableExtractors.size()).filter(i -> clazz.equals(availableExtractors.get(i).getClass().getName())).findAny();
        index.ifPresent(ii -> comboExtractors.getCombo().select(ii));
    }
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) TableViewer(org.eclipse.jface.viewers.TableViewer) StyledString(org.eclipse.jface.viewers.StyledString) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) AbstractWizardPage(name.abuchen.portfolio.ui.wizards.AbstractWizardPage) IStatus(org.eclipse.core.runtime.IStatus) Extractor(name.abuchen.portfolio.datatransfer.Extractor) ViewerCell(org.eclipse.jface.viewers.ViewerCell) Composite(org.eclipse.swt.widgets.Composite) ImportAction(name.abuchen.portfolio.datatransfer.ImportAction) AbstractClientJob(name.abuchen.portfolio.ui.AbstractClientJob) CheckCurrenciesAction(name.abuchen.portfolio.datatransfer.actions.CheckCurrenciesAction) Button(org.eclipse.swt.widgets.Button) Account(name.abuchen.portfolio.model.Account) MenuManager(org.eclipse.jface.action.MenuManager) Status(org.eclipse.core.runtime.Status) Security(name.abuchen.portfolio.model.Security) Display(org.eclipse.swt.widgets.Display) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Collectors(java.util.stream.Collectors) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) Styler(org.eclipse.jface.viewers.StyledString.Styler) SWT(org.eclipse.swt.SWT) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) IntStream(java.util.stream.IntStream) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) LocalDateTime(java.time.LocalDateTime) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) TextStyle(org.eclipse.swt.graphics.TextStyle) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Table(org.eclipse.swt.widgets.Table) OptionalInt(java.util.OptionalInt) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ArrayList(java.util.ArrayList) Annotated(name.abuchen.portfolio.model.Annotated) Messages(name.abuchen.portfolio.ui.Messages) CheckValidTypesAction(name.abuchen.portfolio.datatransfer.actions.CheckValidTypesAction) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) DetectDuplicatesAction(name.abuchen.portfolio.datatransfer.actions.DetectDuplicatesAction) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) Portfolio(name.abuchen.portfolio.model.Portfolio) Combo(org.eclipse.swt.widgets.Combo) FormLayout(org.eclipse.swt.layout.FormLayout) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Action(org.eclipse.jface.action.Action) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) PortfolioPlugin(name.abuchen.portfolio.ui.PortfolioPlugin) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) FormDataFactory(name.abuchen.portfolio.ui.util.FormDataFactory) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) Collections(java.util.Collections) LabelProvider(org.eclipse.jface.viewers.LabelProvider) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) StyledString(org.eclipse.jface.viewers.StyledString) Extractor(name.abuchen.portfolio.datatransfer.Extractor) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) OptionalInt(java.util.OptionalInt)

Example 69 with Portfolio

use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.

the class ClientSnapshot method getJointPortfolio.

public PortfolioSnapshot getJointPortfolio() {
    if (this.jointPortfolio == null) {
        if (portfolios.isEmpty()) {
            Portfolio portfolio = new Portfolio();
            portfolio.setName(Messages.LabelJointPortfolio);
            portfolio.setReferenceAccount(new Account(Messages.LabelJointPortfolio));
            this.jointPortfolio = PortfolioSnapshot.create(portfolio, converter, date);
        } else if (portfolios.size() == 1) {
            this.jointPortfolio = portfolios.get(0);
        } else {
            this.jointPortfolio = PortfolioSnapshot.merge(portfolios, converter);
        }
    }
    return this.jointPortfolio;
}
Also used : Account(name.abuchen.portfolio.model.Account) ReadOnlyAccount(name.abuchen.portfolio.snapshot.filter.ReadOnlyAccount) Portfolio(name.abuchen.portfolio.model.Portfolio)

Example 70 with Portfolio

use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.

the class PerformanceIndex method calculateAbsoluteInvestedCapital.

/**
 * Calculates the absolute invested capital, i.e. starting with the first
 * transaction recorded for the client.
 */
public long[] calculateAbsoluteInvestedCapital() {
    ToLongBiFunction<Money, LocalDateTime> convertIfNecessary = (amount, date) -> {
        if (amount.getCurrencyCode().equals(getCurrencyConverter().getTermCurrency()))
            return amount.getAmount();
        else
            return getCurrencyConverter().convert(date, amount).getAmount();
    };
    long startValue = 0;
    Interval interval = getActualInterval();
    LocalDateTime intervalStart = interval.getStart().atStartOfDay();
    for (Account account : getClient().getAccounts()) startValue += // 
    account.getTransactions().stream().filter(t -> t.getType() == AccountTransaction.Type.DEPOSIT || t.getType() == AccountTransaction.Type.REMOVAL).filter(// 
    t -> t.getDateTime().isBefore(intervalStart)).mapToLong(t -> {
        if (t.getType() == AccountTransaction.Type.DEPOSIT)
            return convertIfNecessary.applyAsLong(t.getMonetaryAmount(), t.getDateTime());
        else if (t.getType() == AccountTransaction.Type.REMOVAL)
            return -convertIfNecessary.applyAsLong(t.getMonetaryAmount(), t.getDateTime());
        else
            return 0;
    }).sum();
    for (Portfolio portfolio : getClient().getPortfolios()) startValue += // 
    portfolio.getTransactions().stream().filter(t -> t.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND || t.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND).filter(// 
    t -> t.getDateTime().isBefore(intervalStart)).mapToLong(t -> {
        if (t.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND)
            return convertIfNecessary.applyAsLong(t.getMonetaryAmount(), t.getDateTime());
        else if (t.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND)
            return -convertIfNecessary.applyAsLong(t.getMonetaryAmount(), t.getDateTime());
        else
            return 0;
    }).sum();
    return calculateInvestedCapital(startValue);
}
Also used : LocalDateTime(java.time.LocalDateTime) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Arrays(java.util.Arrays) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) LocalDateTime(java.time.LocalDateTime) Messages(name.abuchen.portfolio.Messages) Classification(name.abuchen.portfolio.model.Classification) ToLongBiFunction(java.util.function.ToLongBiFunction) ClientClassificationFilter(name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter) OutputStreamWriter(java.io.OutputStreamWriter) Interval(name.abuchen.portfolio.util.Interval) TradeCalendar(name.abuchen.portfolio.util.TradeCalendar) Portfolio(name.abuchen.portfolio.model.Portfolio) Account(name.abuchen.portfolio.model.Account) Predicate(java.util.function.Predicate) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Volatility(name.abuchen.portfolio.math.Risk.Volatility) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Drawdown(name.abuchen.portfolio.math.Risk.Drawdown) Security(name.abuchen.portfolio.model.Security) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) ClientSecurityFilter(name.abuchen.portfolio.snapshot.filter.ClientSecurityFilter) Writer(java.io.Writer) Optional(java.util.Optional) Collections(java.util.Collections) CSVStrategy(org.apache.commons.csv.CSVStrategy) CSVPrinter(org.apache.commons.csv.CSVPrinter) Money(name.abuchen.portfolio.money.Money) Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) Interval(name.abuchen.portfolio.util.Interval)

Aggregations

Portfolio (name.abuchen.portfolio.model.Portfolio)75 Security (name.abuchen.portfolio.model.Security)52 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)44 Test (org.junit.Test)41 Account (name.abuchen.portfolio.model.Account)39 Client (name.abuchen.portfolio.model.Client)38 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)24 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)21 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)20 Unit (name.abuchen.portfolio.model.Transaction.Unit)19 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)17 LocalDate (java.time.LocalDate)16 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)12 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11 Money (name.abuchen.portfolio.money.Money)11 ArrayList (java.util.ArrayList)10 Values (name.abuchen.portfolio.money.Values)10 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)9 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)9 Collections (java.util.Collections)8