Exemplo n.º 1
0
  public void testRate() {
    double nPer, pmt, PV, fv, guess, result;
    boolean type = false;
    nPer = 12 * 30;
    pmt = -877.57;
    PV = 100000;
    fv = 0;
    guess = 0.10 / 12;
    result = Vba.rate(nPer, pmt, PV, fv, type, guess);

    // compare rate to pV calculation
    double expRate = 0.0083333;
    double expPV = Vba.pV(expRate, 12 * 30, -877.57, 0, false);
    result = Vba.rate(12 * 30, -877.57, expPV, 0, false, 0.10 / 12);
    assertTrue(Math.abs(expRate - result) < 0.0000001);

    // compare rate to fV calculation
    double expFV = Vba.fV(expRate, 12, -100, 0, false);
    result = Vba.rate(12, -100, 0, expFV, false, 0.10 / 12);
    assertTrue(Math.abs(expRate - result) < 0.0000001);
  }
Exemplo n.º 2
0
  public void testFv() {
    double f, r, y, p, x;
    int n;
    boolean t;

    r = 0;
    n = 3;
    y = 2;
    p = 7;
    t = true;
    f = Vba.fV(r, n, y, p, t);
    x = -13;
    assertEquals(x, f);

    r = 1;
    n = 10;
    y = 100;
    p = 10000;
    t = false;
    f = Vba.fV(r, n, y, p, t);
    x = -10342300;
    assertEquals(x, f);

    r = 1;
    n = 10;
    y = 100;
    p = 10000;
    t = true;
    f = Vba.fV(r, n, y, p, t);
    x = -10444600;
    assertEquals(x, f);

    r = 2;
    n = 12;
    y = 120;
    p = 12000;
    t = false;
    f = Vba.fV(r, n, y, p, t);
    x = -6409178400d;
    assertEquals(x, f);

    r = 2;
    n = 12;
    y = 120;
    p = 12000;
    t = true;
    f = Vba.fV(r, n, y, p, t);
    x = -6472951200d;
    assertEquals(x, f);

    // cross tests with pv
    r = 2.95;
    n = 13;
    y = 13000;
    p = -4406.78544294496;
    t = false;
    f = Vba.fV(r, n, y, p, t);
    x = 333891.230010986; // as returned by excel
    assertEquals(x, f, 1e-2);

    r = 2.95;
    n = 13;
    y = 13000;
    p = -17406.7852148156;
    t = true;
    f = Vba.fV(r, n, y, p, t);
    x = 333891.230102539; // as returned by excel
    assertEquals(x, f, 1e-2);
  }