title: Oracle SQL - Calculating future loan
body: <p>I'm trying to work out a SQL query to calculate the <strong>Future Loan Balance</strong> based on the following formula :</p>
  
  <p><strong>FV</strong> (Future Balance) = <strong>CV</strong> (Current Balance ) - <strong>P</strong> (Fix Repayment) + <strong>I</strong>    (Interest Capitalized)</p>
  
  <p><strong>where **I</strong> =  ( <strong>CV</strong> * <strong>APR</strong> (Annual % Rate)<strong>/365 * D</strong> (Days between Period))</p>
  
  <p>Here is the sample raw data :</p>
  
  <pre><code>Account ID    Principal        P (Payment)    APR 
  123           $10,000.00      $200.00        0.2
  </code></pre>
  
  <p>Here is the sample output that  :</p>
  
  <pre><code>Term    Account ID  CV (Current Balance)    P (Payment) APR  D (Days)   I (Interest Cap)    FV (Future Balance)
  1       123         $10,000.00           $200.00      0.2  31         169.86              $9,969.86 
  2       123         $9,969.86                $200.00      0.2  30         163.89              $9,933.75 
  3       123         $9,933.75                $200.00      0.2  31         168.74              $9,902.49 
  4       123         $9,902.49                $200.00      0.2  30         162.78              $9,865.27 
  .....
  N       123         &lt;Term N-1 FV&gt;           $200.00     0.2  30         Derived Interest    Derived FV
  </code></pre>
  
  <p>The value of CV is always the FV from the previous term (and FV is calculated based on the formula)</p>
  
  <p>My  current <strong>constraint</strong> is that I <strong>do not have enough permission to create Procedures nor Functions in my SQL environment</strong></p>
  
  <p>It seems like an easy exercise on <em>Excel</em>, however I couldn't figure out how to do it in SQL without using a Procedure/Function .... </p>