use of name.abuchen.portfolio.model.Transaction in project portfolio by buchen.
the class ClientIRRYield method create.
public static ClientIRRYield create(Client client, ClientSnapshot snapshotStart, ClientSnapshot snapshotEnd) {
Interval interval = Interval.of(snapshotStart.getTime(), snapshotEnd.getTime());
List<Transaction> transactions = new ArrayList<>();
collectAccountTransactions(client, interval, transactions);
collectPortfolioTransactions(client, interval, transactions);
Collections.sort(transactions, new Transaction.ByDate());
List<LocalDate> dates = new ArrayList<>();
List<Double> values = new ArrayList<>();
collectDatesAndValues(interval, snapshotStart, snapshotEnd, transactions, dates, values);
double irr = IRR.calculate(dates, values);
return new ClientIRRYield(irr);
}
use of name.abuchen.portfolio.model.Transaction in project portfolio by buchen.
the class ClientIRRYield method collectDatesAndValues.
private static void collectDatesAndValues(Interval interval, ClientSnapshot snapshotStart, ClientSnapshot snapshotEnd, List<Transaction> transactions, List<LocalDate> dates, List<Double> values) {
CurrencyConverter converter = snapshotStart.getCurrencyConverter();
dates.add(interval.getStart());
// snapshots are always in target currency, no conversion needed
values.add(-snapshotStart.getMonetaryAssets().getAmount() / Values.Amount.divider());
for (Transaction t : transactions) {
dates.add(t.getDateTime().toLocalDate());
if (t instanceof AccountTransaction) {
AccountTransaction at = (AccountTransaction) t;
long amount = converter.convert(t.getDateTime(), t.getMonetaryAmount()).getAmount();
if (at.getType() == Type.DEPOSIT || at.getType() == Type.TRANSFER_IN)
amount = -amount;
values.add(amount / Values.Amount.divider());
} else if (t instanceof PortfolioTransaction) {
PortfolioTransaction pt = (PortfolioTransaction) t;
long amount = converter.convert(t.getDateTime(), t.getMonetaryAmount()).getAmount();
if (pt.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND || pt.getType() == PortfolioTransaction.Type.TRANSFER_IN)
amount = -amount;
values.add(amount / Values.Amount.divider());
} else {
throw new UnsupportedOperationException();
}
}
dates.add(interval.getEnd());
values.add(snapshotEnd.getMonetaryAssets().getAmount() / Values.Amount.divider());
}
use of name.abuchen.portfolio.model.Transaction in project portfolio by buchen.
the class SecurityPerformanceRecord method calculateMarketValue.
private void calculateMarketValue(CurrencyConverter converter, ReportingPeriod period) {
MutableMoney mv = MutableMoney.of(converter.getTermCurrency());
for (Transaction t : transactions) if (t instanceof DividendFinalTransaction)
mv.add(t.getMonetaryAmount().with(converter.at(t.getDateTime())));
this.marketValue = mv.toMoney();
this.quote = security.getSecurityPrice(period.getEndDate());
}
use of name.abuchen.portfolio.model.Transaction in project portfolio by buchen.
the class StockSplitModel method applyChanges.
@Override
public void applyChanges() {
// $NON-NLS-1$
SecurityEvent event = new SecurityEvent(exDate, SecurityEvent.Type.STOCK_SPLIT, newShares + ":" + oldShares);
security.addEvent(event);
if (isChangeTransactions()) {
List<TransactionPair<?>> transactions = security.getTransactions(getClient());
for (TransactionPair<?> pair : transactions) {
Transaction t = pair.getTransaction();
if (t.getDateTime().toLocalDate().isBefore(exDate))
t.setShares(t.getShares() * newShares / oldShares);
}
}
if (isChangeHistoricalQuotes()) {
List<SecurityPrice> quotes = security.getPrices();
for (SecurityPrice p : quotes) {
if (p.getDate().isBefore(exDate))
p.setValue(p.getValue() * oldShares / newShares);
}
}
}
Aggregations