use of name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord in project portfolio by buchen.
the class StatementOfAssetsViewer method addDividendColumns.
private void addDividendColumns(List<ReportingPeriod> options) {
ReportingPeriodLabelProvider labelProvider;
// $NON-NLS-1$
Column column = new Column("sumdiv", Messages.ColumnDividendSum, SWT.RIGHT, 80);
Function<Stream<Object>, Object> collector = elements -> elements.map(e -> (Money) e).collect(MoneyCollectors.sum(client.getBaseCurrency()));
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getSumOfDividends, collector, false);
// $NON-NLS-1$
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnDividendSum + " {0}", options));
column.setGroupLabel(Messages.GroupLabelDividends);
column.setMenuLabel(Messages.ColumnDividendSum_MenuLabel);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("d%", Messages.ColumnDividendTotalRateOfReturn, SWT.RIGHT, 80);
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getTotalRateOfReturnDiv, null, false);
// $NON-NLS-1$
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnDividendTotalRateOfReturn + " {0}", options));
column.setGroupLabel(Messages.GroupLabelDividends);
column.setDescription(Messages.ColumnDividendTotalRateOfReturn_Description);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("d%mvavg", Messages.ColumnDividendMovingAverageTotalRateOfReturn, SWT.RIGHT, 80);
labelProvider = new ReportingPeriodLabelProvider(SecurityPerformanceRecord::getTotalRateOfReturnDivMovingAverage, null, false);
// $NON-NLS-1$
column.setOptions(new ReportingPeriodColumnOptions(Messages.ColumnDividendMovingAverageTotalRateOfReturn + " {0}", options));
column.setGroupLabel(Messages.GroupLabelDividends);
column.setDescription(Messages.ColumnDividendMovingAverageTotalRateOfReturn_Description);
column.setLabelProvider(labelProvider);
column.setSorter(ColumnViewerSorter.create(new ElementComparator(labelProvider)));
column.setVisible(false);
support.addColumn(column);
}
use of name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord in project portfolio by buchen.
the class SecurityPositionTest method testFIFOPurchasePriceWithForex.
@Test
public void testFIFOPurchasePriceWithForex() {
CurrencyConverter currencyConverter = new TestCurrencyConverter().with(CurrencyUnit.USD);
Security security = new Security("", CurrencyUnit.USD);
PortfolioTransaction t = new PortfolioTransaction();
t.setType(PortfolioTransaction.Type.DELIVERY_INBOUND);
t.setDateTime(LocalDateTime.parse("2017-01-25T00:00"));
t.setShares(Values.Share.factorize(13));
t.setSecurity(security);
t.setMonetaryAmount(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(9659.24)));
t.addUnit(new Unit(Unit.Type.GROSS_VALUE, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(9644.24)), Money.of(CurrencyUnit.USD, Values.Amount.factorize(10287.13)), BigDecimal.valueOf(0.937470704040499)));
t.addUnit(new Unit(Unit.Type.FEE, Money.of(CurrencyUnit.EUR, Values.Amount.factorize(15)), Money.of(CurrencyUnit.USD, Values.Amount.factorize(16)), BigDecimal.valueOf(0.937470704040499)));
List<PortfolioTransaction> tx = new ArrayList<>();
tx.add(t);
SecurityPosition position = new SecurityPosition(security, currencyConverter, new SecurityPrice(), tx);
assertThat(position.getShares(), is(13L * Values.Share.factor()));
// 10287.13 / 13 = 791.32
assertThat(position.getFIFOPurchasePrice(), is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(791.32))));
assertThat(position.getMovingAveragePurchasePrice(), is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(791.32))));
// 9659.24 EUR x ( 1 / 0.937470704040499) = 10303,51
assertThat(position.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(9659.24 * (1 / 0.937470704040499)))));
Client client = new Client();
client.addSecurity(security);
Account a = new Account();
client.addAccount(a);
Portfolio p = new Portfolio();
p.setReferenceAccount(a);
p.addTransaction(t);
client.addPortfolio(p);
SecurityPerformanceSnapshot snapshot = SecurityPerformanceSnapshot.create(client, currencyConverter, new ReportingPeriod.FromXtoY(LocalDate.parse("2016-12-31"), LocalDate.parse("2017-02-01")));
assertThat(snapshot.getRecords().size(), is(1));
SecurityPerformanceRecord record = snapshot.getRecords().get(0);
assertThat(record.getSecurity(), is(security));
assertThat(record.getFifoCost(), is(position.getFIFOPurchaseValue()));
assertThat(record.getFifoCostPerSharesHeld().toMoney(), is(position.getFIFOPurchasePrice()));
}
use of name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord 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()));
}
use of name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord in project portfolio by buchen.
the class Issue672CapitalGainsIfSecurityIsTransferred method testPurchaseValueOfSecurityPositionWithTransfers.
@Test
public void testPurchaseValueOfSecurityPositionWithTransfers() throws IOException {
Client client = ClientFactory.load(Issue371PurchaseValueWithTransfers.class.getResourceAsStream(// $NON-NLS-1$
"Issue672CapitalGainsIfSecurityIsTransferred.xml"));
CurrencyConverter converter = new TestCurrencyConverter();
Portfolio secondPortfolio = client.getPortfolios().get(1);
ReportingPeriod period = new // $NON-NLS-1$
ReportingPeriod.FromXtoY(// $NON-NLS-1$
LocalDate.parse("2016-01-01"), // $NON-NLS-1$
LocalDate.parse("2017-01-01"));
SecurityPerformanceSnapshot snapshot = SecurityPerformanceSnapshot.create(client, converter, secondPortfolio, period);
assertThat(snapshot.getRecords().size(), is(1));
SecurityPerformanceRecord record = snapshot.getRecords().get(0);
assertThat(record.getMarketValue(), is(Money.of(CurrencyUnit.EUR, Values.Money.factorize(971.41))));
assertThat(record.getFifoCost(), is(Money.of(CurrencyUnit.EUR, Values.Money.factorize(883.1))));
assertThat(record.getCapitalGainsOnHoldings(), is(Money.of(CurrencyUnit.EUR, Values.Money.factorize(88.31))));
assertThat(record.getCapitalGainsOnHoldingsPercent(), is(IsCloseTo.closeTo(0.1d, 0.0000000001)));
}
use of name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord in project portfolio by buchen.
the class SecuritiesPerformanceView method notifyModelUpdated.
@Override
public void notifyModelUpdated() {
// keep security selected even though SecurityPerformacneRecord changes
Set<Security> oldSelection = new HashSet<>();
for (Iterator<?> iter = records.getStructuredSelection().iterator(); iter.hasNext(); ) oldSelection.add(((SecurityPerformanceRecord) iter.next()).getSecurity());
reportingPeriodUpdated();
updateTitle(getDefaultTitle());
List<SecurityPerformanceRecord> newSelection = ((List<?>) records.getInput()).stream().map(//
e -> (SecurityPerformanceRecord) e).filter(//
e -> oldSelection.contains(e.getSecurity())).collect(Collectors.toList());
records.setSelection(new StructuredSelection(newSelection));
}
Aggregations