use of name.abuchen.portfolio.PortfolioBuilder 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.PortfolioBuilder in project portfolio by buchen.
the class ClientSecurityFilterTest method setupClient.
@Before
public void setupClient() {
client = new Client();
securityUSD = //
new SecurityBuilder().addPrice("2016-06-01", //
Values.Quote.factorize(100)).addTo(client);
securityEUR = //
new SecurityBuilder(CurrencyUnit.USD).addPrice("2016-06-01", //
Values.Quote.factorize(100)).addTo(client);
accountEUR = //
new AccountBuilder(CurrencyUnit.EUR).dividend("2017-01-01", Values.Amount.factorize(20), //
securityEUR).addTo(client);
accountUSD = //
new AccountBuilder(CurrencyUnit.USD).dividend("2017-01-01", Values.Amount.factorize(20), //
securityUSD).addTo(client);
//
new PortfolioBuilder(accountEUR).inbound_delivery(securityEUR, "2016-06-01", Values.Share.factorize(20), //
Values.Amount.factorize(2000)).inbound_delivery(securityUSD, "2016-06-01", Values.Share.factorize(20), //
Values.Amount.factorize(2000)).addTo(client);
}
use of name.abuchen.portfolio.PortfolioBuilder 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.PortfolioBuilder 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.PortfolioBuilder in project portfolio by buchen.
the class PortfolioClientFilterTest method setupClient.
/**
* Creates three portfolios (A-C) with a reference account each.
*/
@Before
public void setupClient() {
client = new Client();
Security security = new SecurityBuilder().addTo(client);
// 2016-01-01 deposit
// 2016-02-01 buy
// 2016-03-01 dividend
Arrays.asList("A", "B", "C").forEach(index -> {
Account a = //
new AccountBuilder().deposit_("2016-01-01", Values.Amount.factorize(100)).dividend("2016-03-01", Values.Amount.factorize(10), //
security).addTo(client);
a.setName(index);
Portfolio p = //
new PortfolioBuilder(a).buy(security, "2016-02-01", Values.Share.factorize(1), Values.Amount.factorize(100)).addTo(client);
p.setName(index);
});
}
Aggregations