Search in sources :

Example 26 with Portfolio

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());
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) LocalDate(java.time.LocalDate) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Example 27 with Portfolio

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))));
}
Also used : TestCurrencyConverter(name.abuchen.portfolio.TestCurrencyConverter) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) SecurityBuilder(name.abuchen.portfolio.SecurityBuilder) Test(org.junit.Test)

Example 28 with Portfolio

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));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Test(org.junit.Test)

Example 29 with Portfolio

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();
        }
    });
}
Also used : SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) Portfolio(name.abuchen.portfolio.model.Portfolio) Separator(org.eclipse.jface.action.Separator)

Example 30 with Portfolio

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;
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Transaction(name.abuchen.portfolio.model.Transaction) Account(name.abuchen.portfolio.model.Account) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Set(java.util.Set) Security(name.abuchen.portfolio.model.Security) Messages(name.abuchen.portfolio.Messages) MessageFormat(java.text.MessageFormat) Unit(name.abuchen.portfolio.model.Transaction.Unit) MoneyCollectors(name.abuchen.portfolio.money.MoneyCollectors) Optional(java.util.Optional) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) ImportAction(name.abuchen.portfolio.datatransfer.ImportAction) EnumSet(java.util.EnumSet) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) Portfolio(name.abuchen.portfolio.model.Portfolio) Money(name.abuchen.portfolio.money.Money) Security(name.abuchen.portfolio.model.Security)

Aggregations

Portfolio (name.abuchen.portfolio.model.Portfolio)75 Security (name.abuchen.portfolio.model.Security)52 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)44 Test (org.junit.Test)41 Account (name.abuchen.portfolio.model.Account)39 Client (name.abuchen.portfolio.model.Client)38 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)24 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)21 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)20 Unit (name.abuchen.portfolio.model.Transaction.Unit)19 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)17 LocalDate (java.time.LocalDate)16 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)12 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11 Money (name.abuchen.portfolio.money.Money)11 ArrayList (java.util.ArrayList)10 Values (name.abuchen.portfolio.money.Values)10 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)9 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)9 Collections (java.util.Collections)8