use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class DividendsViewModel method calculate.
private void calculate() {
// determine the number of full months within period
LocalDate now = LocalDate.now();
if (startYear > now.getYear())
throw new IllegalArgumentException();
this.noOfmonths = (now.getYear() - startYear) * 12 + now.getMonthValue();
Predicate<Transaction> predicate = new ReportingPeriod.FromXtoY(LocalDate.of(startYear - 1, Month.DECEMBER, 31), now).containsTransaction();
Map<InvestmentVehicle, Line> vehicle2line = new HashMap<>();
this.sum = new Line(null, this.noOfmonths);
this.transactions = new ArrayList<>();
Client filteredClient = clientFilter.getSelectedFilter().filter(client);
for (Account account : filteredClient.getAccounts()) {
for (AccountTransaction t : account.getTransactions()) {
if (t.getType() != AccountTransaction.Type.DIVIDENDS)
continue;
if (!predicate.test(t))
continue;
transactions.add(new TransactionPair<>(account, t));
Money dividendValue = useGrossValue ? t.getGrossValue() : t.getMonetaryAmount();
long value = dividendValue.with(converter.at(t.getDateTime())).getAmount();
int index = (t.getDateTime().getYear() - startYear) * 12 + t.getDateTime().getMonthValue() - 1;
Line line = vehicle2line.computeIfAbsent(t.getSecurity(), s -> new Line(s, noOfmonths));
line.values[index] += value;
line.sum += value;
sum.values[index] += value;
sum.sum += value;
}
}
this.lines = new ArrayList<>(vehicle2line.values());
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class TaxonomyModel method addUnassigned.
private void addUnassigned(Client client) {
for (Security security : client.getSecurities()) {
Assignment assignment = new Assignment(security);
assignment.setWeight(0);
investmentVehicle2weight.put(security, assignment);
}
for (Account account : client.getAccounts()) {
Assignment assignment = new Assignment(account);
assignment.setWeight(0);
investmentVehicle2weight.put(account, assignment);
}
visitAll(node -> {
if (!(node instanceof AssignmentNode))
return;
Assignment assignment = node.getAssignment();
Assignment count = investmentVehicle2weight.get(assignment.getInvestmentVehicle());
count.setWeight(count.getWeight() + assignment.getWeight());
});
List<Assignment> unassigned = new ArrayList<>();
for (Assignment assignment : investmentVehicle2weight.values()) {
if (assignment.getWeight() >= Classification.ONE_HUNDRED_PERCENT)
continue;
Assignment a = new Assignment(assignment.getInvestmentVehicle());
a.setWeight(Classification.ONE_HUNDRED_PERCENT - assignment.getWeight());
unassigned.add(a);
assignment.setWeight(Classification.ONE_HUNDRED_PERCENT);
}
Collections.sort(unassigned, (o1, o2) -> o1.getInvestmentVehicle().toString().compareToIgnoreCase(o2.getInvestmentVehicle().toString()));
for (Assignment assignment : unassigned) unassignedNode.addChild(assignment);
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class DataSeriesSet method buildCommonDataSeries.
private void buildCommonDataSeries(Client client, IPreferenceStore preferences, ColorWheel wheel) {
int index = client.getSecurities().size();
for (Security security : client.getSecurities()) {
// as equity data series (only as benchmark)
if (security.getCurrencyCode() == null)
continue;
availableSeries.add(new //
DataSeries(//
DataSeries.Type.SECURITY, //
security, //
security.getName(), wheel.getRGB(index++)));
}
for (Portfolio portfolio : client.getPortfolios()) availableSeries.add(new //
DataSeries(//
DataSeries.Type.PORTFOLIO, //
portfolio, //
portfolio.getName(), wheel.getRGB(index++)));
// portfolio + reference account
for (Portfolio portfolio : client.getPortfolios()) {
DataSeries series = new DataSeries(DataSeries.Type.PORTFOLIO_PLUS_ACCOUNT, portfolio, // $NON-NLS-1$
portfolio.getName() + " + " + portfolio.getReferenceAccount().getName(), wheel.getRGB(index++));
availableSeries.add(series);
}
// custom client filters
ClientFilterMenu menu = new ClientFilterMenu(client, preferences);
// quick fix: users can create duplicate client filters that end up to
// have the same UUID. Avoid adding both violates the precondition that
// every data series must have a unique id
Set<String> addedSeries = new HashSet<>();
for (ClientFilterMenu.Item item : menu.getCustomItems()) {
DataSeries series = new DataSeries(DataSeries.Type.CLIENT_FILTER, item, item.getLabel(), wheel.getRGB(index++));
if (addedSeries.add(series.getUUID()))
availableSeries.add(series);
}
for (Account account : client.getAccounts()) availableSeries.add(new DataSeries(DataSeries.Type.ACCOUNT, account, account.getName(), wheel.getRGB(index++)));
for (Taxonomy taxonomy : client.getTaxonomies()) {
taxonomy.foreach(new Taxonomy.Visitor() {
@Override
public void visit(Classification classification) {
if (classification.getParent() == null)
return;
availableSeries.add(new DataSeries(DataSeries.Type.CLASSIFICATION, classification, classification.getName(), Colors.toRGB(classification.getColor())));
}
});
}
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ConsorsbankPDFExtractorTest method checkCurrency.
private void checkCurrency(final String accountCurrency, AccountTransaction transaction) {
Account account = new Account();
account.setCurrencyCode(accountCurrency);
Status status = new CheckCurrenciesAction().process(transaction, account);
assertThat(status.getCode(), is(Code.OK));
}
use of name.abuchen.portfolio.model.Account 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()));
}
Aggregations