Skip to content

Instantly share code, notes, and snippets.

@Azsaturndx
Created February 18, 2020 23:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Azsaturndx/1310c6635fc51905bec9f8ac8aa13d95 to your computer and use it in GitHub Desktop.
Save Azsaturndx/1310c6635fc51905bec9f8ac8aa13d95 to your computer and use it in GitHub Desktop.
EFFECT Function (Effective Annual Interest Rate) - SQL Server
/**
* Effective Annual Interest Rate
* (SQL Server)
* AzsaturnDx (2020) - No copyright at all
*
* Returns the effective annual interest rate, given the nominal annual interest rate and the number of compounding periods per year.
*
* @Rate FLOAT - Required. The nominal interest rate.
* @Periods INT - Required. The number of compounding periods per year.
* @return FLOAT Effective Annual Interest Rate.
*
* @Example
* SELECT dbo.EFFECT(0.452166555,52)
*
* More financial functions are available @: https://gist.github.com/Azsaturndx/8ce3e47e2d3210a65fc83b09ac32da5f
*/
CREATE FUNCTION EFFECT(
@Rate FLOAT
,@Periods INT
)
RETURNS FLOAT
AS
BEGIN
IF (@Rate <= 0) OR (@Periods < 1) RETURN 0
RETURN POWER( 1 + @Rate / @Periods, @Periods) - 1
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment