Search in sources :

Example 16 with ReportingPeriod

use of name.abuchen.portfolio.snapshot.ReportingPeriod in project portfolio by buchen.

the class VolatilityTestCase method testVolatilityIfSecurityIsSoldDuringReportingPeriod.

@Test
public void testVolatilityIfSecurityIsSoldDuringReportingPeriod() throws IOException {
    ReportingPeriod report = new ReportingPeriod.FromXtoY(LocalDate.parse("2014-01-31"), LocalDate.parse("2015-01-31"));
    List<Exception> warnings = new ArrayList<>();
    Security basf = client.getSecurities().stream().filter(s -> "Basf SE".equals(s.getName())).findAny().get();
    PerformanceIndex index = PerformanceIndex.forInvestment(client, converter, basf, report, warnings);
    PerformanceIndex clientIndex = PerformanceIndex.forClient(client, converter, report, warnings);
    assertThat(warnings, empty());
    // excel
    assertThat(index.getVolatility().getStandardDeviation(), closeTo(0.200573810778, 0.1e-10));
    // excel
    assertThat(clientIndex.getVolatility().getStandardDeviation(), closeTo(0.200599730118, 0.1e-10));
    assertThat(index.getDates()[index.getDates().length - 1], is(LocalDate.parse("2015-01-31")));
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security) IOException(java.io.IOException) PerformanceIndex(name.abuchen.portfolio.snapshot.PerformanceIndex) Test(org.junit.Test)

Example 17 with ReportingPeriod

use of name.abuchen.portfolio.snapshot.ReportingPeriod in project portfolio by buchen.

the class ReportingPeriodColumnOptions method createNewOption.

@Override
public ReportingPeriod createNewOption(Shell shell) {
    ReportingPeriodDialog dialog = new ReportingPeriodDialog(shell, null);
    if (dialog.open() == ReportingPeriodDialog.OK) {
        ReportingPeriod p = dialog.getReportingPeriod();
        defaultOptions.add(p);
        return p;
    }
    return null;
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ReportingPeriodDialog(name.abuchen.portfolio.ui.dialogs.ReportingPeriodDialog)

Example 18 with ReportingPeriod

use of name.abuchen.portfolio.snapshot.ReportingPeriod in project portfolio by buchen.

the class ReportingPeriodDropDown method menuAboutToShow.

@Override
public void menuAboutToShow(IMenuManager manager) {
    boolean isFirst = true;
    for (final ReportingPeriod period : periods) {
        Action action = new Action(period.toString()) {

            @Override
            public void run() {
                periods.remove(period);
                periods.addFirst(period);
                setLabel(period.toString());
                if (listener != null)
                    listener.reportingPeriodUpdated();
            }
        };
        if (isFirst)
            action.setChecked(true);
        isFirst = false;
        manager.add(action);
    }
    manager.add(new Separator());
    manager.add(new Action(Messages.LabelReportingAddPeriod) {

        @Override
        public void run() {
            ReportingPeriodDialog dialog = new ReportingPeriodDialog(getToolBar().getShell(), periods.getFirst());
            if (dialog.open() == Dialog.OK) {
                ReportingPeriod period = dialog.getReportingPeriod();
                periods.addFirst(period);
                setLabel(period.toString());
                if (listener != null)
                    listener.reportingPeriodUpdated();
                if (periods.size() > 20)
                    periods.removeLast();
            }
        }
    });
    manager.add(new Action(Messages.MenuReportingPeriodManage) {

        @Override
        public void run() {
            EditReportingPeriodsDialog dialog = new EditReportingPeriodsDialog(getToolBar().getShell());
            dialog.setReportingPeriods(periods);
            if (dialog.open() == Dialog.OK) {
                ReportingPeriod currentSelection = periods.getFirst();
                periods.clear();
                periods.addAll(dialog.getReportingPeriods());
                // make sure at least one entry exists
                if (periods.isEmpty())
                    periods.add(currentSelection);
                if (listener != null && !currentSelection.equals(periods.getFirst())) {
                    setLabel(periods.getFirst().toString());
                    listener.reportingPeriodUpdated();
                }
            }
        }
    });
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Action(org.eclipse.jface.action.Action) EditReportingPeriodsDialog(name.abuchen.portfolio.ui.dialogs.EditReportingPeriodsDialog) Separator(org.eclipse.jface.action.Separator) ReportingPeriodDialog(name.abuchen.portfolio.ui.dialogs.ReportingPeriodDialog)

Example 19 with ReportingPeriod

use of name.abuchen.portfolio.snapshot.ReportingPeriod in project portfolio by buchen.

the class PortfolioPart method storeReportingPeriods.

public void storeReportingPeriods(List<ReportingPeriod> periods) {
    StringBuilder buf = new StringBuilder();
    for (ReportingPeriod p : periods) {
        p.writeTo(buf);
        buf.append(';');
    }
    getPreferenceStore().setValue(REPORTING_PERIODS_KEY, buf.toString());
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod)

Example 20 with ReportingPeriod

use of name.abuchen.portfolio.snapshot.ReportingPeriod in project portfolio by buchen.

the class Issue371PurchaseValueWithTransfers method testPurchaseValueOfSecurityPositionWithTransfers.

@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException {
    Client client = ClientFactory.load(Issue371PurchaseValueWithTransfers.class.getResourceAsStream(// $NON-NLS-1$
    "Issue371PurchaseValueWithTransfers.xml"));
    Security adidas = client.getSecurities().get(0);
    // $NON-NLS-1$
    assertThat(adidas.getName(), is("Adidas AG"));
    ReportingPeriod period = new // $NON-NLS-1$
    ReportingPeriod.FromXtoY(// $NON-NLS-1$
    LocalDate.parse("2010-11-20"), // $NON-NLS-1$
    LocalDate.parse("2015-11-20"));
    // make sure that the transfer entry exists
    assertThat(client.getPortfolios().size(), is(2));
    assertThat(client.getPortfolios().stream().flatMap(p -> p.getTransactions().stream()).filter(t -> t.getSecurity() == adidas).filter(t -> t.getCrossEntry() instanceof PortfolioTransferEntry).filter(t -> t.getType() == PortfolioTransaction.Type.TRANSFER_IN).findAny().isPresent(), is(true));
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientSnapshot snapshot = ClientSnapshot.create(client, converter, period.getEndDate());
    SecurityPosition securityPosition = snapshot.getPositionsByVehicle().get(adidas).getPosition();
    SecurityPerformanceSnapshot securitySnapshot = SecurityPerformanceSnapshot.create(client, converter, period);
    SecurityPerformanceRecord securityRecord = securitySnapshot.getRecords().get(0);
    assertThat(securityRecord.getSecurity(), is(adidas));
    assertThat(securityPosition.getFIFOPurchaseValue(), is(securityRecord.getFifoCost()));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Client(name.abuchen.portfolio.model.Client) IOException(java.io.IOException) Test(org.junit.Test) Security(name.abuchen.portfolio.model.Security) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Assert.assertThat(org.junit.Assert.assertThat) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) ClientFactory(name.abuchen.portfolio.model.ClientFactory) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) Security(name.abuchen.portfolio.model.Security) SecurityPerformanceSnapshot(name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) SecurityPosition(name.abuchen.portfolio.snapshot.SecurityPosition) TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Client(name.abuchen.portfolio.model.Client) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) Test(org.junit.Test)

Aggregations

ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)27 Test (org.junit.Test)14 Client (name.abuchen.portfolio.model.Client)13 ArrayList (java.util.ArrayList)11 Security (name.abuchen.portfolio.model.Security)11 IOException (java.io.IOException)8 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)8 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)8 PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)8 SecurityPerformanceRecord (name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord)8 SecurityPerformanceSnapshot (name.abuchen.portfolio.snapshot.security.SecurityPerformanceSnapshot)8 Portfolio (name.abuchen.portfolio.model.Portfolio)5 Composite (org.eclipse.swt.widgets.Composite)5 LocalDate (java.time.LocalDate)4 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)4 ExchangeRate (name.abuchen.portfolio.money.ExchangeRate)4 ClientSnapshot (name.abuchen.portfolio.snapshot.ClientSnapshot)4 List (java.util.List)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3