use of name.abuchen.portfolio.snapshot.AssetPosition in project portfolio by buchen.
the class CurrencyTestCase method testUSDAssetPosition.
private void testUSDAssetPosition(GroupByTaxonomy grouping) {
AssetPosition equityUSD = getAssetPositionByName(grouping, securityUSD.getName());
assertThat(equityUSD.getPosition().getShares(), is(Values.Share.factorize(10)));
// purchase value must be sum of both purchases:
// the one in EUR account and the one in USD account
// must take the inverse of the exchange used within the transaction
BigDecimal rate = BigDecimal.ONE.divide(BigDecimal.valueOf(0.8237), 10, BigDecimal.ROUND_HALF_DOWN);
assertThat(equityUSD.getPosition().getFIFOPurchaseValue(), is(Money.of("USD", Math.round(454_60 * rate.doubleValue()) + 571_90)));
// price per share is the total purchase price minus 20 USD fees and
// taxes divided by the number of shares
Money pricePerShare = //
equityUSD.getPosition().getFIFOPurchaseValue().subtract(Money.of("USD", 20_00)).divide(10);
assertThat(equityUSD.getPosition().getFIFOPurchasePrice(), is(pricePerShare));
// profit loss w/o rounding differences
assertThat(equityUSD.getProfitLoss(), is(equityUSD.getValuation().subtract(equityUSD.getFIFOPurchaseValue())));
assertThat(equityUSD.getPosition().getProfitLoss(), is(equityUSD.getPosition().calculateValue().subtract(equityUSD.getPosition().getFIFOPurchaseValue())));
}
use of name.abuchen.portfolio.snapshot.AssetPosition in project portfolio by buchen.
the class CurrencyTestCase method testAssetCategories.
private void testAssetCategories(GroupByTaxonomy grouping) {
AssetCategory cash = getAssetCategoryByName(grouping, "Barvermögen");
Money cashValuation = Money.of(CurrencyUnit.EUR, 1000_00 + Math.round(1000_00 * (1 / 1.1588)));
assertThat(cash.getValuation(), is(cashValuation));
AssetPosition positionEUR = getAssetPositionByName(grouping, accountEUR.getName());
assertThat(positionEUR.getValuation(), is(Money.of(CurrencyUnit.EUR, 1000_00)));
AssetPosition positionUSD = getAssetPositionByName(grouping, accountUSD.getName());
assertThat(positionUSD.getValuation(), is(Money.of(CurrencyUnit.EUR, Math.round(1000_00 * (1 / 1.1588)))));
Money equityEURvaluation = Money.of(CurrencyUnit.EUR, Math.round(20 * securityEUR.getSecurityPrice(grouping.getDate()).getValue() / Values.Quote.dividerToMoney()));
Money equityUSDvaluation = Money.of("USD", Math.round(10 * securityUSD.getSecurityPrice(grouping.getDate()).getValue() / Values.Quote.dividerToMoney())).with(converter.at(grouping.getDate()));
Money equityValuation = Money.of(CurrencyUnit.EUR, equityEURvaluation.getAmount() + equityUSDvaluation.getAmount());
AssetCategory equity = getAssetCategoryByName(grouping, "Eigenkapital");
assertThat(equity.getValuation(), is(equityValuation));
AssetPosition equityEUR = getAssetPositionByName(grouping, securityEUR.getName());
assertThat(equityEUR.getValuation(), is(equityEURvaluation));
AssetPosition equityUSD = getAssetPositionByName(grouping, securityUSD.getName());
assertThat(equityUSD.getValuation(), is(equityUSDvaluation));
assertThat(grouping.getValuation(), is(cashValuation.add(equityValuation)));
}
use of name.abuchen.portfolio.snapshot.AssetPosition in project portfolio by buchen.
the class CurrencyTestCase method testFIFOPurchasePriceWithForex.
@Test
public void testFIFOPurchasePriceWithForex() {
ClientSnapshot snapshot = ClientSnapshot.create(client, converter, LocalDate.parse("2015-08-09"));
// 1.1. ........ -> 454.60 EUR
// 1.1. 571.90 $ -> 471.05 EUR (exchange rate: 1.2141)
// 3.8. 577.60 $ -> 498.45 EUR (exchange rate: 1.1588)
AssetPosition position = snapshot.getPositionsByVehicle().get(securityUSD);
assertThat(position.getPosition().getShares(), is(Values.Share.factorize(15)));
assertThat(position.getFIFOPurchaseValue(), is(Money.of(CurrencyUnit.EUR, 454_60 + 471_05 + 498_45)));
ReportingPeriod period = new ReportingPeriod.FromXtoY(LocalDate.parse("2014-12-31"), LocalDate.parse("2015-08-10"));
SecurityPerformanceSnapshot performance = SecurityPerformanceSnapshot.create(client, converter, period);
SecurityPerformanceRecord record = performance.getRecords().stream().filter(r -> r.getSecurity() == securityUSD).findAny().get();
assertThat(record.getSharesHeld(), is(Values.Share.factorize(15)));
assertThat(record.getFifoCost(), is(Money.of(CurrencyUnit.EUR, 454_60 + 471_05 + 498_45)));
}
use of name.abuchen.portfolio.snapshot.AssetPosition in project portfolio by buchen.
the class ReBalancingViewer method addColumns.
@Override
protected void addColumns(ShowHideColumnHelper support) {
addDimensionColumn(support);
addDesiredAllocationColumn(support);
// $NON-NLS-1$
Column column = new Column("targetvalue", Messages.ColumnTargetValue, SWT.RIGHT, 100);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
return node.isClassification() ? Values.Money.format(node.getTarget(), getModel().getCurrencyCode()) : null;
}
});
support.addColumn(column);
addActualColumns(support);
// $NON-NLS-1$
column = new Column("delta%", Messages.ColumnDeltaPercent, SWT.RIGHT, 60);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
if (node.getTarget() == null)
return null;
return Values.Percent.format(((double) node.getActual().getAmount() / (double) node.getTarget().getAmount()) - 1);
}
@Override
public Color getForeground(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
if (node.getTarget() == null)
return null;
return Display.getCurrent().getSystemColor(node.getActual().isGreaterOrEqualThan(node.getTarget()) ? SWT.COLOR_DARK_GREEN : SWT.COLOR_DARK_RED);
}
});
support.addColumn(column);
// $NON-NLS-1$
column = new Column("delta", Messages.ColumnDeltaValue, SWT.RIGHT, 100);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
if (node.getTarget() == null)
return null;
return Values.Money.format(node.getActual().subtract(node.getTarget()), getModel().getCurrencyCode());
}
@Override
public Color getForeground(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
if (node.getTarget() == null)
return null;
return Display.getCurrent().getSystemColor(node.getActual().isGreaterOrEqualThan(node.getTarget()) ? SWT.COLOR_DARK_GREEN : SWT.COLOR_DARK_RED);
}
});
support.addColumn(column);
// $NON-NLS-1$
column = new Column("quote", Messages.ColumnQuote, SWT.RIGHT, 60);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
Security security = node.getBackingSecurity();
if (security == null || security.getCurrencyCode() == null)
return null;
SecurityPrice price = security.getSecurityPrice(LocalDate.now());
return Values.Quote.format(security.getCurrencyCode(), price.getValue(), getModel().getCurrencyCode());
}
});
support.addColumn(column);
// $NON-NLS-1$
column = new Column("shares", Messages.ColumnSharesOwned, SWT.RIGHT, 60);
column.setLabelProvider(new SharesLabelProvider() {
@Override
public Long getValue(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
Security security = node.getBackingSecurity();
if (security == null || security.getCurrencyCode() == null)
return null;
AssetPosition position = getModel().getClientSnapshot().getPositionsByVehicle().get(security);
if (position == null)
return null;
return Math.round(position.getPosition().getShares() * node.getWeight() / (double) Classification.ONE_HUNDRED_PERCENT);
}
});
column.setVisible(false);
support.addColumn(column);
// $NON-NLS-1$
column = new Column("deltashares", Messages.ColumnDeltaShares, SWT.RIGHT, 100);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
TaxonomyNode node = (TaxonomyNode) element;
// no delta shares for unassigned securities
if (node.getParent() != null && node.getParent().isUnassignedCategory())
return null;
Security security = node.getBackingSecurity();
if (security == null || security.getCurrencyCode() == null)
return null;
String priceCurrency = security.getCurrencyCode();
long price = security.getSecurityPrice(LocalDate.now()).getValue();
long weightedPrice = Math.round(node.getWeight() * price / (double) Classification.ONE_HUNDRED_PERCENT);
if (weightedPrice == 0L)
return Values.Share.format(0L);
String deltaCurrency = node.getActual().getCurrencyCode();
long delta = node.getParent().getTarget().getAmount() - node.getParent().getActual().getAmount();
// delta in order to know how many shares need to bought or sold
if (!deltaCurrency.equals(priceCurrency)) {
delta = getModel().getCurrencyConverter().with(priceCurrency).convert(LocalDate.now(), Money.of(deltaCurrency, delta)).getAmount();
}
long shares = Math.round(delta * Values.Share.divider() * Values.Quote.dividerToMoney() / weightedPrice);
return Values.Share.format(shares);
}
});
support.addColumn(column);
addAdditionalColumns(support);
}
use of name.abuchen.portfolio.snapshot.AssetPosition in project portfolio by buchen.
the class TaxonomyModel method visitActuals.
private void visitActuals(ClientSnapshot snapshot, TaxonomyNode node) {
MutableMoney actual = MutableMoney.of(snapshot.getCurrencyCode());
for (TaxonomyNode child : node.getChildren()) {
visitActuals(snapshot, child);
actual.add(child.getActual());
}
if (node.isAssignment()) {
Assignment assignment = node.getAssignment();
AssetPosition p = snapshot.getPositionsByVehicle().get(assignment.getInvestmentVehicle());
if (p != null) {
Money valuation = p.getValuation();
actual.add(Money.of(valuation.getCurrencyCode(), Math.round(valuation.getAmount() * assignment.getWeight() / (double) Classification.ONE_HUNDRED_PERCENT)));
}
}
node.setActual(actual.toMoney());
}
Aggregations