Search This Blog

Wednesday 27 February 2019

How to make EMI Loan Amortization in SQL server


DECLARE
 @LoanAmount MONEY = '5000000.00'
,@ROI FLOAT = 11
,@Tenure NUMERIC(18,2) = 12
,@Period INT
,@Principal MONEY
,@Interest MONEY
,@EMI MONEY
,@AMT MONEY

SET @Period = 1
SET @ROI = (@ROI/100)/12

DECLARE @EMI_TABLE TABLE
(PERIOD INT,PAYDATE SMALLDATETIME,EMI MONEY,PRINCIPAL MONEY,INTEREST MONEY ,BALANCE MONEY)  

--EMI = [P x R x (1 + R)^N] / [(1 + R)^N - 1]
SELECT @EMI = ROUND((@LoanAmount * @ROI * POWER((1 + @ROI), @Tenure))  / (POWER((1 + @ROI), @Tenure) - 1),2)

WHILE @Period <= @Tenure
BEGIN
      --INTEREST = [P x R]
      SELECT @Interest = ROUND((@LoanAmount * @ROI),2)
      --PRINCIPAL = [EMI - INTEREST]
      SELECT @Principal = ROUND((@EMI - @Interest),2)
      --OUTSTANDING LOAN AMOUNT = [@LoanAmount - Principal]
      SELECT @LoanAmount = ROUND((@LoanAmount - @Principal),2)

      INSERT INTO @EMI_TABLE VALUES(@Period,DATEADD(MM,@Period,GETDATE()),@EMI,@Principal,@Interest,@LoanAmount)

      SET @Period = @Period + 1
END

SELECT * FROM @EMI_TABLE

Output





















Note:-


P - Loan Amount
R - Rate of Interest
N - Tenure/Loan Period

You will get different in paisa. Need to manage as per requirement.

3 comments:

  1. Wow awesome ...Got helped by this.

    ReplyDelete
  2. Wonderful illustrated information. I thank you about that. No doubt it will be very useful for my future projects. Would like to see some other posts on the same subject! Development Finance calculator

    ReplyDelete
  3. How to make casino games - DrMCD
    Casino Games - Play casino games for free, without cost. All games will be tested in 충주 출장샵 real time, 나주 출장샵 or 김해 출장마사지 in-game, 과천 출장샵 and no fees 안산 출장안마 are charged. This

    ReplyDelete