use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class CostCalculationTest method testFifoBuySellTransactions.
@Test
public void testFifoBuySellTransactions() {
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)).sell(security, "2010-02-01", 15 * Values.Share.factor(), //
Values.Amount.factorize(531.50)).buy(security, "2010-03-01", 52 * Values.Share.factor(), //
Values.Amount.factorize(1684.92)).buy(security, "2010-03-01", 32 * Values.Share.factor(), //
Values.Amount.factorize(959.30)).addTo(client);
CostCalculation cost = new CostCalculation();
cost.setTermCurrency(CurrencyUnit.EUR);
cost.visitAll(new TestCurrencyConverter(), portfolio.getTransactions());
// expected:
// 3149,20 - round(3149,20 * 15/109) + 1684,92 + 959,30 = 5360,04385
assertThat(cost.getFifoCost(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(5360.04))));
// expected moving average is identical because it is only one buy
// transaction
// 3149,20 * 94/109 + 1684.92 + 959.30 = 5360,04385
assertThat(cost.getMovingAverageCost(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(5360.04))));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class CostCalculationTest method testWhenSharesHeldGoToZero.
@Test
public void testWhenSharesHeldGoToZero() {
Client client = new Client();
Security security = //
new SecurityBuilder().addTo(client);
Portfolio portfolio = //
new PortfolioBuilder().buy(security, "2010-01-01", 100 * Values.Share.factor(), //
314920).sell(security, "2010-02-01", 100 * Values.Share.factor(), //
53150).buy(security, "2010-03-01", 50 * Values.Share.factor(), //
168492).sell(security, "2010-04-01", 50 * Values.Share.factor(), //
53150).addTo(client);
CostCalculation cost = new CostCalculation();
cost.setTermCurrency(CurrencyUnit.EUR);
cost.visitAll(new TestCurrencyConverter(), portfolio.getTransactions());
assertThat(cost.getFifoCost(), is(Money.of(CurrencyUnit.EUR, 0L)));
assertThat(cost.getMovingAverageCost(), is(Money.of(CurrencyUnit.EUR, 0L)));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class ClassificationTestCase method testCase12_ForexAccountOut100_AccountIn50.
@Test
public void testCase12_ForexAccountOut100_AccountIn50() {
Taxonomy case12 = client.getTaxonomies().stream().filter(t -> "case_12".equals(t.getName())).findAny().orElseThrow(IllegalArgumentException::new);
// check performance of 'subcategory'
Classification ccategory = case12.getAllClassifications().stream().filter(c -> "category".equals(c.getName())).findAny().orElseThrow(IllegalArgumentException::new);
Client categoryClient = new ClientClassificationFilter(ccategory).filter(client);
List<PortfolioTransaction> txp = categoryClient.getPortfolios().stream().flatMap(p -> p.getTransactions().stream()).collect(Collectors.toList());
assertThat(txp, hasSize(0));
List<AccountTransaction> txa = categoryClient.getAccounts().stream().filter(a -> "Account Forex".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
// check cash transfers
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.TRANSFER_OUT)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(50)))))));
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.REMOVAL)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.USD, Values.Amount.factorize(50)))))));
txa = categoryClient.getAccounts().stream().filter(a -> "Konto 3".equals(a.getName())).flatMap(a -> a.getTransactions().stream()).collect(Collectors.toList());
assertThat(txa, hasItem(allOf(//
hasProperty("dateTime", is(LocalDateTime.parse("2012-01-17T00:00"))), //
hasProperty("type", is(AccountTransaction.Type.TRANSFER_IN)), hasProperty("monetaryAmount", is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(78.19 * 0.5d)))))));
// create index
List<Exception> warnings = new ArrayList<>();
PerformanceIndex index_subcategory = PerformanceIndex.forClassification(client, converter, ccategory, interval, warnings);
assertThat(warnings.isEmpty(), is(true));
// 343.42 EUR (Konto 3 EUR)
// 423.52 USD / 1.2141 (exchange rate in TestCurrencyConverter)
assertThat(index_subcategory.getTotals()[index_subcategory.getTotals().length - 1], is(//
Values.Amount.factorize(343.42) + Values.Amount.factorize(423.52 / 1.2141)));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class ClassificationIndexTest method testThat100PercentAssignmentIsIdenticalToClientPerformance.
@Test
public void testThat100PercentAssignmentIsIdenticalToClientPerformance() {
Client client = createClient(Classification.ONE_HUNDRED_PERCENT);
Classification classification = client.getTaxonomies().get(0).getClassificationById("one");
List<Exception> warnings = new ArrayList<Exception>();
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex iClient = PerformanceIndex.forClient(client, converter, period, warnings);
PerformanceIndex iClassification = PerformanceIndex.forClassification(client, converter, classification, period, warnings);
assertThat(warnings.isEmpty(), is(true));
assertThat(iClient.getDates(), is(iClassification.getDates()));
assertThat(iClient.getAccumulatedPercentage(), is(iClassification.getAccumulatedPercentage()));
assertThat(iClient.getDeltaPercentage(), is(iClassification.getDeltaPercentage()));
assertThat(iClient.getTotals(), is(iClassification.getTotals()));
assertThat(iClient.getTransferals(), is(iClassification.getTransferals()));
}
use of name.abuchen.portfolio.TestCurrencyConverter in project portfolio by buchen.
the class ClassificationIndexTest method testThat50PercentAssignmentHasIdenticalPerformanceButOnly50PercentTotals.
@Test
public void testThat50PercentAssignmentHasIdenticalPerformanceButOnly50PercentTotals() {
Client client = createClient(Classification.ONE_HUNDRED_PERCENT / 2);
Classification classification = client.getTaxonomies().get(0).getClassificationById("one");
List<Exception> warnings = new ArrayList<Exception>();
CurrencyConverter converter = new TestCurrencyConverter();
PerformanceIndex iClient = PerformanceIndex.forClient(client, converter, period, warnings);
PerformanceIndex iClassification = PerformanceIndex.forClassification(client, converter, classification, period, warnings);
assertThat(warnings.isEmpty(), is(true));
assertThat(iClient.getDates(), is(iClassification.getDates()));
assertThat(iClient.getAccumulatedPercentage(), is(iClassification.getAccumulatedPercentage()));
assertThat(iClient.getDeltaPercentage(), is(iClassification.getDeltaPercentage()));
assertThat(half(iClient.getTotals()), is(iClassification.getTotals()));
assertThat(half(iClient.getTransferals()), is(iClassification.getTransferals()));
}
Aggregations