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