use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testDepositPlusInterestFirstDay.
@Test
public void testDepositPlusInterestFirstDay() {
Client client = new Client();
Account account = new Account();
account.addTransaction(new AccountTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 1000_00, null, AccountTransaction.Type.DEPOSIT));
account.addTransaction(new AccountTransaction(LocalDateTime.of(2010, Month.DECEMBER, 31, 0, 0), CurrencyUnit.EUR, 50_00, null, AccountTransaction.Type.INTEREST));
client.addAccount(account);
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
assertThat(snapshot.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1050_00)));
assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 0)));
assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1050_00)));
assertThat(snapshot.getAbsoluteDelta(), is(snapshot.getValue(CategoryType.FINAL_VALUE).subtract(snapshot.getValue(CategoryType.TRANSFERS)).subtract(snapshot.getValue(CategoryType.INITIAL_VALUE))));
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testInterestCharge.
@Test
public void testInterestCharge() {
Client client = new Client();
Account account = //
new AccountBuilder().interest_charge("2011-01-01", //
Values.Amount.factorize(100)).addTo(client);
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(-100))));
assertThat(snapshot.getCategoryByType(CategoryType.EARNINGS).getPositions().size(), is(1));
assertThat(snapshot.getCategoryByType(CategoryType.EARNINGS).getPositions().get(0).getValuation(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(-100))));
assertThat(snapshot.getEarnings().size(), is(1));
assertThat(snapshot.getEarnings().get(0).getTransaction().getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(100))));
GroupEarningsByAccount grouping = new GroupEarningsByAccount(snapshot);
assertThat(grouping.getItems().size(), is(1));
assertThat(grouping.getItems().get(0).getAccount(), is(account));
assertThat(grouping.getItems().get(0).getSum(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(-100))));
assertThatCalculationWorksOut(snapshot, converter);
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testCapitalGainsWithPartialSellDuringReportPeriod.
@Test
public void testCapitalGainsWithPartialSellDuringReportPeriod() {
Client client = new Client();
Security security = //
new SecurityBuilder().addPrice("2010-01-01", //
Values.Quote.factorize(100)).addPrice("2011-06-01", //
Values.Quote.factorize(110)).addTo(client);
Account account = //
new AccountBuilder().deposit_("2010-01-01", //
1_00).withdraw("2011-01-15", //
99_00).addTo(client);
//
new PortfolioBuilder(account).buy(security, "2010-01-01", Values.Share.factorize(10), //
1_00).sell(security, "2011-01-15", Values.Share.factorize(1), //
99_00).addTo(client);
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
assertThat(snapshot.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1000_00)));
assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 0)));
assertThat(snapshot.getValue(CategoryType.CAPITAL_GAINS), is(Money.of(CurrencyUnit.EUR, 10_00 * 9 + (99_00 - 100_00))));
assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 110_00 * 9)));
assertThat(snapshot.getAbsoluteDelta(), is(snapshot.getValue(CategoryType.FINAL_VALUE).subtract(snapshot.getValue(CategoryType.TRANSFERS)).subtract(snapshot.getValue(CategoryType.INITIAL_VALUE))));
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testCapitalGainsWithBuyDuringReportPeriod.
@Test
public void testCapitalGainsWithBuyDuringReportPeriod() {
Client client = new Client();
Security security = new Security();
security.addPrice(new SecurityPrice(LocalDate.of(2010, Month.JANUARY, 1), Values.Quote.factorize(100)));
security.addPrice(new SecurityPrice(LocalDate.of(2011, Month.JUNE, 1), Values.Quote.factorize(110)));
client.addSecurity(security);
Portfolio portfolio = new Portfolio();
portfolio.setReferenceAccount(new Account());
portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 1_00, security, Values.Share.factorize(10), PortfolioTransaction.Type.BUY, 0, 0));
portfolio.addTransaction(new PortfolioTransaction(LocalDateTime.of(2011, Month.JANUARY, 15, 0, 0), CurrencyUnit.EUR, 99_00, security, Values.Share.factorize(1), PortfolioTransaction.Type.DELIVERY_INBOUND, 0, 0));
client.addPortfolio(portfolio);
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
assertThat(snapshot.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1000_00)));
assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 0)));
assertThat(snapshot.getValue(CategoryType.CAPITAL_GAINS), is(Money.of(CurrencyUnit.EUR, 100_00 + (110_00 - 99_00))));
assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1210_00)));
assertThat(snapshot.getAbsoluteDelta(), is(snapshot.getValue(CategoryType.FINAL_VALUE).subtract(snapshot.getValue(CategoryType.TRANSFERS)).subtract(snapshot.getValue(CategoryType.INITIAL_VALUE))));
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testDepositPlusInterest.
@Test
public void testDepositPlusInterest() {
Client client = new Client();
Account account = new Account();
account.addTransaction(new AccountTransaction(LocalDateTime.of(2010, Month.JANUARY, 1, 0, 0), CurrencyUnit.EUR, 1000_00, null, AccountTransaction.Type.DEPOSIT));
account.addTransaction(new AccountTransaction(LocalDateTime.of(2011, Month.JUNE, 1, 0, 0), CurrencyUnit.EUR, 50_00, null, AccountTransaction.Type.INTEREST));
client.addAccount(account);
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new ClientPerformanceSnapshot(client, converter, startDate, endDate);
assertNotNull(snapshot);
assertNotNull(snapshot.getStartClientSnapshot());
assertEquals(startDate, snapshot.getStartClientSnapshot().getTime());
assertNotNull(snapshot.getEndClientSnapshot());
assertEquals(endDate, snapshot.getEndClientSnapshot().getTime());
List<Category> categories = snapshot.getCategories();
assertNotNull(categories);
assertThat(categories.size(), is(ClientPerformanceSnapshot.CategoryType.values().length));
assertThat(snapshot.getValue(CategoryType.INITIAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1000_00)));
assertThat(snapshot.getValue(CategoryType.EARNINGS), is(Money.of(CurrencyUnit.EUR, 50_00)));
assertThat(snapshot.getValue(CategoryType.FINAL_VALUE), is(Money.of(CurrencyUnit.EUR, 1050_00)));
assertThat(snapshot.getAbsoluteDelta(), is(snapshot.getValue(CategoryType.FINAL_VALUE).subtract(snapshot.getValue(CategoryType.TRANSFERS)).subtract(snapshot.getValue(CategoryType.INITIAL_VALUE))));
}
Aggregations