コード例 #1
0
  @Test
  public void testIndexWhenNoQuotesExist() {
    DateMidnight startDate = new DateMidnight(2012, 12, 31);
    DateMidnight endDate = new DateMidnight(2013, 3, 31);

    // create model

    Client client = new Client();

    new AccountBuilder() //
        .deposit_(startDate, 100 * Values.Amount.factor()) //
        .addTo(client);

    Security security = new Security();
    client.addSecurity(security);

    // calculate performance indices

    List<Exception> warnings = new ArrayList<Exception>();

    ReportingPeriod reportInterval =
        new ReportingPeriod.FromXtoY(startDate.toDate(), endDate.toDate());
    ClientIndex clientIndex = PerformanceIndex.forClient(client, reportInterval, warnings);
    PerformanceIndex securityIndex = PerformanceIndex.forSecurity(clientIndex, security, warnings);

    // asserts

    assertTrue(warnings.isEmpty());
    assertThat(securityIndex.getDates().length, is(1));
    assertThat(securityIndex.getDates()[0], is(clientIndex.getFirstDataPoint().get().toDate()));
  }
コード例 #2
0
  @Test
  public void testErtragsgutschriftWhenSecurityExists() throws IOException {
    Client client = new Client();
    Security security = new Security("BASF", "DE000BASF111", null, null);
    client.addSecurity(security);

    DeutscheBankPDFExctractor extractor =
        new DeutscheBankPDFExctractor(client) {
          @Override
          String strip(File file) throws IOException {
            return from("DeutscheBankErtragsgutschrift.txt");
          }
        };
    List<Exception> errors = new ArrayList<Exception>();

    List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);

    assertThat(errors, empty());
    assertThat(results.size(), is(1));
    new AssertImportActions().check(results, CurrencyUnit.EUR);

    // check transaction
    AccountTransaction transaction = (AccountTransaction) results.get(0).getSubject();
    assertThat(transaction.getType(), is(AccountTransaction.Type.DIVIDENDS));
    assertThat(transaction.getSecurity(), is(security));
  }
コード例 #3
0
 @Before
 public void setupClient() {
   client = new Client();
   account = new Account();
   client.addAccount(account);
   portfolio = new Portfolio();
   client.addPortfolio(portfolio);
   security = new Security();
   client.addSecurity(security);
 }
コード例 #4
0
ファイル: SecurityIndexTest.java プロジェクト: Voos/portfolio
  @Test
  public void testThatSecurityIndexIsCalculated() {
    DateMidnight startDate = new DateMidnight(2012, 12, 31);
    DateMidnight endDate = new DateMidnight(2013, 4, 1);
    long startPrice = 100 * Values.Amount.factor();

    // create model

    Client client = new Client();

    Account account = new Account();
    client.addAccount(account);
    addT(account, startDate.toCalendar(Locale.getDefault()), Type.DEPOSIT, startPrice);

    Security security = new Security();
    client.addSecurity(security);

    generatePrices(security, startPrice, startDate, endDate);

    // calculate performance indices

    List<Exception> warnings = new ArrayList<Exception>();

    ReportingPeriod reportInterval =
        new ReportingPeriod.FromXtoY(startDate.toDate(), endDate.toDate());
    ClientIndex clientIndex = PerformanceIndex.forClient(client, reportInterval, warnings);
    PerformanceIndex securityIndex = PerformanceIndex.forSecurity(clientIndex, security, warnings);

    // asserts

    assertTrue(warnings.isEmpty());

    Date[] dates = securityIndex.getDates();
    assertThat(dates[0], is(startDate.toDate()));
    assertThat(dates[dates.length - 1], is(endDate.toDate()));

    long lastPrice = security.getSecurityPrice(endDate.toDate()).getValue();
    double performance = (double) (lastPrice - startPrice) / (double) startPrice;

    double[] accumulated = securityIndex.getAccumulatedPercentage();
    assertThat(accumulated[0], is(0d));
    assertThat(accumulated[accumulated.length - 1], IsCloseTo.closeTo(performance, 0.000001d));
  }
コード例 #5
0
 @Override
 public Status process(Security security) {
   // might have been added via a transaction
   if (!client.getSecurities().contains(security)) client.addSecurity(security);
   return Status.OK_STATUS;
 }
コード例 #6
0
ファイル: SecurityIndexTest.java プロジェクト: Voos/portfolio
  @Test
  public void testWhenQuotesAreOnlyAvailableFromTheMiddleOfTheReportInterval() {
    DateMidnight startDate = new DateMidnight(2012, 12, 31);
    DateMidnight middleDate = new DateMidnight(2013, 2, 18);
    DateMidnight endDate = new DateMidnight(2013, 4, 1);

    // create model

    Client client = new Client();

    Account account = new Account();
    client.addAccount(account);
    addT(
        account,
        startDate.toCalendar(Locale.getDefault()),
        Type.DEPOSIT,
        100 * Values.Amount.factor());
    addT(
        account,
        startDate.plusDays(10).toCalendar(Locale.getDefault()),
        Type.INTEREST,
        10 * Values.Amount.factor());

    Security security = new Security();
    client.addSecurity(security);

    generatePrices(security, 50 * Values.Amount.factor(), middleDate, endDate);

    // calculate performance indices

    List<Exception> warnings = new ArrayList<Exception>();

    ReportingPeriod reportInterval =
        new ReportingPeriod.FromXtoY(startDate.toDate(), endDate.toDate());
    ClientIndex clientIndex = PerformanceIndex.forClient(client, reportInterval, warnings);
    PerformanceIndex securityIndex = PerformanceIndex.forSecurity(clientIndex, security, warnings);

    // asserts

    assertTrue(warnings.isEmpty());

    Date[] clientDates = clientIndex.getDates();
    Date[] securityDates = securityIndex.getDates();

    assertThat(securityDates[0], is(middleDate.toDate()));
    assertThat(securityDates[securityDates.length - 1], is(endDate.toDate()));
    assertThat(
        new DateMidnight(clientDates[clientDates.length - 1]),
        is(new DateMidnight(securityDates[securityDates.length - 1])));

    double[] clientAccumulated = clientIndex.getAccumulatedPercentage();
    double[] securityAccumulated = securityIndex.getAccumulatedPercentage();

    int index = Days.daysBetween(startDate, middleDate).getDays();
    assertThat(new DateMidnight(clientDates[index]), is(middleDate));
    assertThat(securityAccumulated[0], IsCloseTo.closeTo(clientAccumulated[index], 0.000001d));

    long middlePrice = security.getSecurityPrice(middleDate.toDate()).getValue();
    long lastPrice = security.getSecurityPrice(endDate.toDate()).getValue();

    // 10% is interest of the deposit
    double performance = (double) (lastPrice - middlePrice) / (double) middlePrice + 0.1d;
    assertThat(
        securityAccumulated[securityAccumulated.length - 1],
        IsCloseTo.closeTo(performance, 0.000001d));
  }