Monday, May 25, 2015

Function to Calculate Compound Interest daily basis, penal interest calculation formula

ALTER FUNCTION [dbo].[GetComputedInterestOnDays](
 @Principal DECIMAL(18,2)
,@AnulaInterestRate DECIMAL(18,2)
,@DueDays DECIMAL(18,2)
)
RETURNS DECIMAL(18,2)
AS
-- Returns the stock level for the product.
BEGIN
 
    DECLARE @DaysInYear INT = 360, @InterestFriction DECIMAL(18,10)
 
   SET @Principal = ISNULL(@Principal,0.0);
   SET @AnulaInterestRate = ISNULL(@AnulaInterestRate,0.0);
   SET @InterestFriction = @AnulaInterestRate / @DaysInYear;
   SET @InterestFriction = (100+@InterestFriction)/100;
   SET @InterestFriction = POWER(@InterestFriction,@DueDays)
   RETURN   (@InterestFriction * @Principal)-@Principal;

END;

No comments: