use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class PortfolioSnapshotTest method testBuyAndSellLeavesNoEntryInSnapshot.
@Test
public void testBuyAndSellLeavesNoEntryInSnapshot() {
Client client = new Client();
Security a = //
new SecurityBuilder().addPrice("2010-01-01", //
1000).addTo(client);
Portfolio portfolio = //
new PortfolioBuilder().buy(a, "2010-01-01", 1000000, //
10000).sell(a, "2010-01-02", 700000, //
12000).sell(a, "2010-01-03", 300000, //
12000).addTo(client);
LocalDate date = LocalDate.parse("2010-01-31");
PortfolioSnapshot snapshot = PortfolioSnapshot.create(portfolio, new TestCurrencyConverter(), date);
assertTrue(snapshot.getPositions().isEmpty());
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class CostCalculationTest method testFifoBuySellTransactions2.
@Test
public void testFifoBuySellTransactions2() {
Client client = new Client();
Security security = //
new SecurityBuilder().addTo(client);
Portfolio portfolio = //
new PortfolioBuilder().buy(security, "2010-01-01", 109 * Values.Share.factor(), //
Values.Amount.factorize(3149.20)).buy(security, "2010-02-01", 52 * Values.Share.factor(), //
Values.Amount.factorize(1684.92)).sell(security, "2010-03-01", 15 * Values.Share.factor(), //
Values.Amount.factorize(531.50)).addTo(client);
CostCalculation cost = new CostCalculation();
cost.setTermCurrency(CurrencyUnit.EUR);
cost.visitAll(new TestCurrencyConverter(), portfolio.getTransactions());
// expected:
// 3149,20 + 1684,92 - round(3149,20 * 15/109) = 4400,743853211009174
assertThat(cost.getFifoCost(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(4400.74))));
// expected moving average is identical because it is only one buy
// transaction
// (3149,20 + 1684.92) * 146/161 = 4383,736149068322981
assertThat(cost.getMovingAverageCost(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(4383.74))));
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class TransactionComparatorTest method testThatDatePreceedsType.
@Test
public void testThatDatePreceedsType() {
Portfolio portfolio = //
new PortfolioBuilder().sell(security, "2010-01-01", 100, //
100).buy(security, "2010-01-02", 100, //
100).addTo(client);
List<PortfolioTransaction> list = portfolio.getTransactions();
Collections.sort(list, new TransactionComparator());
assertThat(list.get(0).getType(), is(Type.SELL));
assertThat(list.get(1).getType(), is(Type.BUY));
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class PortfolioListView method fillPortfolioContextMenu.
private void fillPortfolioContextMenu(IMenuManager manager) {
final Portfolio portfolio = (Portfolio) ((IStructuredSelection) portfolios.getSelection()).getFirstElement();
if (portfolio == null)
return;
new SecurityContextMenu(this).menuAboutToShow(manager, null, portfolio);
manager.add(new Separator());
manager.add(new Action(portfolio.isRetired() ? Messages.PortfolioMenuActivate : Messages.PortfolioMenuDeactivate) {
@Override
public void run() {
portfolio.setRetired(!portfolio.isRetired());
markDirty();
setInput();
}
});
manager.add(new Action(Messages.PortfolioMenuDelete) {
@Override
public void run() {
getClient().removePortfolio(portfolio);
markDirty();
setInput();
}
});
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class CheckCurrenciesAction method process.
@Override
public Status process(PortfolioTransaction transaction, Portfolio portfolio) {
Security security = transaction.getSecurity();
if (security == null)
return new Status(Status.Code.ERROR, MessageFormat.format(Messages.MsgCheckMissingSecurity, transaction.getType().toString()));
Status status = checkGrossValueAndUnitsAgainstSecurity(transaction);
if (status.getCode() != Status.Code.OK)
return status;
if (transaction.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND || transaction.getType() == PortfolioTransaction.Type.SELL) {
// tax + fees must be < than transaction amount
Money taxAndFees = //
transaction.getUnits().filter(//
u -> u.getType() == Unit.Type.TAX || u.getType() == Unit.Type.FEE).map(//
u -> u.getAmount()).collect(MoneyCollectors.sum(transaction.getCurrencyCode()));
if (!transaction.getMonetaryAmount().isGreaterOrEqualThan(taxAndFees))
return new Status(Status.Code.ERROR, MessageFormat.format(Messages.MsgCheckTaxAndFeesTooHigh, Values.Money.format(transaction.getMonetaryAmount()), Values.Money.format(taxAndFees)));
}
return Status.OK_STATUS;
}
Aggregations