コード例 #1
0
  @Test
  public void testThatAlmostMatchingBuySellEntriesAreNotMatched() {
    portfolio.addTransaction(
        new PortfolioTransaction(
            Dates.today(),
            security, //
            PortfolioTransaction.Type.SELL,
            1,
            1,
            1));

    account.addTransaction(
        new AccountTransaction(
            Dates.today(),
            security, //
            AccountTransaction.Type.SELL,
            2));

    List<Issue> issues = new CrossEntryCheck().execute(client);
    assertThat(issues.size(), is(2));
    List<Object> objects = new ArrayList<Object>(issues);
    assertThat(objects, hasItem(instanceOf(MissingBuySellAccountIssue.class)));
    assertThat(objects, hasItem(instanceOf(MissingBuySellPortfolioIssue.class)));

    applyFixes(client, issues);
  }
コード例 #2
0
  @Test
  public void testVolatilityOfSharesHeldIsIdenticalToExcel() throws IOException {
    ReportingPeriod report =
        new ReportingPeriod.FromXtoY(Dates.date("2014-01-31"), Dates.date("2014-07-31"));
    List<Exception> warnings = new ArrayList<>();
    PerformanceIndex index = PerformanceIndex.forClient(client, report, warnings);

    assertThat(warnings, empty());
    assertThat(
        index.getVolatility().getStandardDeviation(), closeTo(0.01251323582, 0.000001)); // excel
  }
コード例 #3
0
  @Test
  public void testVolatilityIfSecurityIsSoldAndLaterBoughtDuringReportingPeriod()
      throws IOException {
    ReportingPeriod report =
        new ReportingPeriod.FromXtoY(Dates.date("2014-01-31"), Dates.date("2015-02-20"));
    List<Exception> warnings = new ArrayList<>();

    Security basf =
        client.getSecurities().stream().filter(s -> "Basf SE".equals(s.getName())).findAny().get();
    PerformanceIndex index = PerformanceIndex.forInvestment(client, basf, report, warnings);

    assertThat(warnings, empty());
    assertThat(
        index.getVolatility().getStandardDeviation(),
        closeTo(0.0134468200485513, 0.00001)); // excel
    assertThat(index.getDates()[index.getDates().length - 1], is(Dates.date("2015-02-20")));
  }
コード例 #4
0
  @Test
  public void testThatNotTheSamePortfolioIsMatched() {
    Portfolio second = new Portfolio();
    client.addPortfolio(second);

    portfolio.addTransaction(
        new PortfolioTransaction(
            Dates.today(),
            security, //
            PortfolioTransaction.Type.TRANSFER_IN,
            1,
            3,
            1));

    PortfolioTransaction umatched =
        new PortfolioTransaction(
            Dates.today(),
            security, //
            PortfolioTransaction.Type.TRANSFER_OUT,
            1,
            3,
            1);
    portfolio.addTransaction(umatched);

    second.addTransaction(
        new PortfolioTransaction(
            Dates.today(),
            security, //
            PortfolioTransaction.Type.TRANSFER_OUT,
            1,
            3,
            1));

    List<Issue> issues = new CrossEntryCheck().execute(client);

    assertThat(issues.size(), is(1));
    assertThat(issues.get(0), is(MissingPortfolioTransferIssue.class));

    assertThat(portfolio.getTransactions(), hasItem(umatched));
    assertThat(second.getTransactions().get(0).getCrossEntry(), notNullValue());
    assertThat(
        second.getTransactions().get(0).getType(), is(PortfolioTransaction.Type.TRANSFER_OUT));

    applyFixes(client, issues);
  }
コード例 #5
0
  @Test
  public void testVolatilityIfBenchmarkHasNoQuotes() throws IOException {
    ReportingPeriod report =
        new ReportingPeriod.FromXtoY(Dates.date("2014-01-31"), Dates.date("2015-01-31"));
    List<Exception> warnings = new ArrayList<>();

    PerformanceIndex index = PerformanceIndex.forClient(client, report, warnings);

    Security sap =
        client.getSecurities().stream().filter(s -> "Sap AG".equals(s.getName())).findAny().get();
    PerformanceIndex sapIndex = PerformanceIndex.forSecurity(index, sap, warnings);

    assertThat(warnings, empty());
    // quotes only until December 31st
    assertThat(sapIndex.getDates()[sapIndex.getDates().length - 1], is(Dates.date("2014-12-31")));
    assertThat(
        sapIndex.getVolatility().getStandardDeviation(),
        closeTo(0.0126152529671108, 0.00001)); // excel
  }
コード例 #6
0
  @Test
  public void testVolatilityIfSecurityIsSoldDuringReportingPeriod() throws IOException {
    ReportingPeriod report =
        new ReportingPeriod.FromXtoY(Dates.date("2014-01-31"), Dates.date("2015-01-31"));
    List<Exception> warnings = new ArrayList<>();

    Security basf =
        client.getSecurities().stream().filter(s -> "Basf SE".equals(s.getName())).findAny().get();
    PerformanceIndex index = PerformanceIndex.forInvestment(client, basf, report, warnings);

    assertThat(warnings, empty());
    assertThat(
        index.getVolatility().getStandardDeviation(), closeTo(0.01371839502, 0.00001)); // excel
    assertThat(index.getDates()[index.getDates().length - 1], is(Dates.date("2015-01-31")));

    // compare with client -> must be lower because cash has volatility of 0
    PerformanceIndex clientIndex = PerformanceIndex.forClient(client, report, warnings);
    assertThat(
        clientIndex.getVolatility().getStandardDeviation(),
        lessThan(index.getVolatility().getStandardDeviation()));
  }
コード例 #7
0
  @Test
  public void testThatCorrectBuySellEntriesAreNotReported() {
    BuySellEntry entry = new BuySellEntry(portfolio, account);
    entry.setType(PortfolioTransaction.Type.BUY);
    entry.setDate(Dates.today());
    entry.setSecurity(security);
    entry.setShares(1);
    entry.setAmount(100);
    entry.insert();

    assertThat(new CrossEntryCheck().execute(client).size(), is(0));
  }
コード例 #8
0
  @Test
  public void testThatAccountTransactionsWithoutSecurity() {
    Portfolio second = new Portfolio();
    client.addPortfolio(second);

    account.addTransaction(
        new AccountTransaction(
            Dates.today(),
            null, //
            AccountTransaction.Type.BUY,
            1));

    List<Issue> issues = new CrossEntryCheck().execute(client);

    assertThat(issues.size(), is(1));
    assertThat(issues.get(0).getAvailableFixes().get(0), is(DeleteTransactionFix.class));

    applyFixes(client, issues);

    ClientSnapshot.create(client, Dates.today());
  }
コード例 #9
0
  @Test
  public void testThatMatchingBuySellEntriesAreFixed() {
    portfolio.addTransaction(
        new PortfolioTransaction(
            Dates.today(),
            security, //
            PortfolioTransaction.Type.SELL,
            1,
            1,
            1));

    account.addTransaction(
        new AccountTransaction(
            Dates.today(),
            security, //
            AccountTransaction.Type.SELL,
            1));

    assertThat(new CrossEntryCheck().execute(client).size(), is(0));
    assertThat(portfolio.getTransactions().get(0).getCrossEntry(), notNullValue());
    assertThat(account.getTransactions().get(0).getCrossEntry(), notNullValue());
  }
コード例 #10
0
  @Test
  public void testThatNotTheSameAccountIsMatched() {
    Account second = new Account();
    client.addAccount(second);

    account.addTransaction(
        new AccountTransaction(
            Dates.today(),
            security, //
            AccountTransaction.Type.TRANSFER_IN,
            2));

    AccountTransaction umatched =
        new AccountTransaction(
            Dates.today(),
            security, //
            AccountTransaction.Type.TRANSFER_OUT,
            2);
    account.addTransaction(umatched);

    second.addTransaction(
        new AccountTransaction(
            Dates.today(),
            security, //
            AccountTransaction.Type.TRANSFER_OUT,
            2));

    List<Issue> issues = new CrossEntryCheck().execute(client);

    assertThat(issues.size(), is(1));
    assertThat(issues.get(0), is(MissingAccountTransferIssue.class));

    assertThat(account.getTransactions(), hasItem(umatched));
    assertThat(second.getTransactions().get(0).getCrossEntry(), notNullValue());
    assertThat(second.getTransactions().get(0).getType(), is(AccountTransaction.Type.TRANSFER_OUT));

    applyFixes(client, issues);
  }
コード例 #11
0
  @Test
  public void testMissingAccountTransferInIssue() {
    account.addTransaction(
        new AccountTransaction(
            Dates.today(),
            security, //
            AccountTransaction.Type.TRANSFER_OUT,
            1));

    List<Issue> issues = new CrossEntryCheck().execute(client);

    assertThat(issues.size(), is(1));
    assertThat(issues.get(0), is(MissingAccountTransferIssue.class));
    assertThat(issues.get(0).getEntity(), is((Object) account));

    applyFixes(client, issues);
  }
コード例 #12
0
  @Test
  public void testMissingBuyInAccountIssue() {
    portfolio.addTransaction(
        new PortfolioTransaction(
            Dates.today(),
            security, //
            PortfolioTransaction.Type.SELL,
            1,
            1,
            1));

    List<Issue> issues = new CrossEntryCheck().execute(client);

    assertThat(issues.size(), is(1));
    assertThat(issues.get(0), is(MissingBuySellAccountIssue.class));
    assertThat(issues.get(0).getEntity(), is((Object) portfolio));

    applyFixes(client, issues);
  }
コード例 #13
0
ファイル: ClientIndexTest.java プロジェクト: buchen/portfolio
  @Test
  public void testExcelSample() {
    Client client = createClient();

    ReportingPeriod.FromXtoY period =
        new ReportingPeriod.FromXtoY(
            LocalDate.of(2011, Month.DECEMBER, 31), //
            LocalDate.of(2012, Month.JANUARY, 8));
    CurrencyConverter converter = new TestCurrencyConverter();
    ClientIndex index =
        PerformanceIndex.forClient(client, converter, period, new ArrayList<Exception>());

    assertNotNull(index);

    assertThat(period.toInterval(), is(index.getReportInterval().toInterval()));
    assertThat(client, is(index.getClient()));

    LocalDate[] dates = index.getDates();
    assertThat(dates.length, is(Dates.daysBetween(period.getStartDate(), period.getEndDate()) + 1));

    double[] delta = index.getDeltaPercentage();
    assertThat(delta[0], is(0d));
    assertThat(delta[1], IsCloseTo.closeTo(0.023d, PRECISION));
    assertThat(delta[2], IsCloseTo.closeTo(0.0195503d, PRECISION));
    assertThat(delta[3], IsCloseTo.closeTo(-0.0220517d, PRECISION));
    assertThat(delta[4], IsCloseTo.closeTo(0.0294117647d, PRECISION));
    assertThat(delta[5], IsCloseTo.closeTo(0.0285714286d, PRECISION));
    assertThat(delta[6], IsCloseTo.closeTo(0.0185185185d, PRECISION));
    assertThat(delta[7], IsCloseTo.closeTo(-0.0545454545d, PRECISION));
    assertThat(delta[8], IsCloseTo.closeTo(-0.0865384615d, PRECISION));

    double[] accumulated = index.getAccumulatedPercentage();
    assertThat(accumulated[0], is(0d));
    assertThat(accumulated[1], IsCloseTo.closeTo(0.023d, PRECISION));
    assertThat(accumulated[2], IsCloseTo.closeTo(0.043d, PRECISION));
    assertThat(accumulated[3], IsCloseTo.closeTo(0.02d, PRECISION));
    assertThat(accumulated[4], IsCloseTo.closeTo(0.05d, PRECISION));
    assertThat(accumulated[5], IsCloseTo.closeTo(0.08d, PRECISION));
    assertThat(accumulated[6], IsCloseTo.closeTo(0.10d, PRECISION));
    assertThat(accumulated[7], IsCloseTo.closeTo(0.04d, PRECISION));
    assertThat(accumulated[8], IsCloseTo.closeTo(-0.05d, PRECISION));
  }