title: P/Y C/Y - Calculate future value (FV) from payments (PMT) with compounding period per year (C/Y)
body: <p>I am doing a TVM project and not quite understand how the compound interest translates into code. I am using BA II Plus financial calculator as a reference.</p>
  
  <p><strong>Example:</strong> Find the future value of $100 payments made at the beginning of every month for 10 years if interest is 5% compounded quarterly.</p>
  
  <p>In the financial calculator:</p>
  
  <p>N: 120 (10y x 12m)</p>
  
  <p>I/Y: 5% (annually interest rate)</p>
  
  <p>P/Y: 12 (12 times per year)</p>
  
  <p>C/Y: 4 (4 times per year)</p>
  
  <p>PV: 0</p>
  
  <p>PMT: 100</p>
  
  <p>BGN: TRUE</p>
  
  <p>FV: [CPT] [FV] => <strong>-15575.41334</strong></p>
  
  <hr>
  
  <p>Here is the future value method.</p>
  
  <pre><code>static public double fv(double r, int n, double pmt, double pv, int bgn) {
      return -(pv * Math.pow(1 + r, n) + pmt * (1 + r * bgn) * (Math.pow(1 + r, n) - 1) / r);
  }
  </code></pre>
  
  <p>Call the method using numbers from the example</p>
  
  <pre><code>//             rate     n    pmt  pv bgn
  double fv = fv(0.05/12, 120, 100, 0, 1); // -15592.928894335751 which is wrong
  </code></pre>