Interest Rate Methodology


Tinlake uses an interest rate mechanism that is typically implemented as compounding per second. The implementation can be found in github.com/centrifuge/tinlake-math.

Below we show abstract examples of how this is calculated:

interest rate per second
the number of times the interest is compounded, compounding is once per second, so "n" is seconds past since last calculation
Nominal interest rate (5% would be 0.05)
Annual Percentage Rate (APR)
constant, seconds in a year: 360024365=315360003600 cdot 24 cdot 365 = 31536000

The basic formula is:

D=PratenD = P cdot rate^{n}

Debt equals to Principal (or the previous debt amount) times rate to the power of seconds since last calculation.

Example: Interest rate compounding per second

P=100r=0.05n=360024365=31536000P = 100 ewline r = 0.05 ewline n = 3600 cdot 24 cdot 365 = 31536000 ewline

Using the formula above, the Debt DD after half a year (n=y/2=15768000)(n = mathtt{y} / 2 = 15768000) would result in D=102.5315D = 102.5315.

After one year (n=yn = mathtt{y}) the DD would be 105.1271105.1271.

Thus a 5.00% interest rate compounded every second is equivalent to an annually compounded rate of 5.127%.

The annual percentage rate Amathtt{A} could also be calculated directly from the percentage rate Rmathtt{R} (using n=y=31536000n = mathtt{y} = 31536000):

A=(1+Ry)y=1.05127mathtt{A} = (1 + rac{mathtt{R}}{mathtt{y}})^mathtt{y} = 1.05127

Rate per Second

To calculate the Debt, we initialize an interest rate in Tinlake with a variable called ratePerSecond or raterate. The ratePerSecond represents the interest accrued per second in Tinlake.

rate=1+Ryrate = 1 + rac{mathtt{R}}{mathtt{y}}

Calculate Debt

D=PratetD = P * rate^t

The debt can be calculated by multipling the principial PP with raterate to the power of nn. The variable nn represents the time passed in seconds since the loan has been borrowed.

Continuing the example from above for annual interest:

rate=1+0.0531536000=1.0000000015854900D=1001.000000001585490031536000=105.1271rate = 1 + rac{0.05}{31536000} = 1.0000000015854900 ewline D = 100 cdot 1.0000000015854900^{31536000} = 105.1271

Using an annual percentage rate (APR) in Tinlake

The Tinlake User Interface uses an annual percentage rate (APR) as input. Tinlake transforms this annually compounded rate Amathtt{A} into the equivalent rate used for compounding per seconds raterate. This is achieved by solving the equation:

A=(1+ratey)ymathtt{A} = (1 + rac{rate}{mathtt{y}})^mathtt{y}

for rr:

r=y(A1y1)r = mathtt{y} cdot (mathtt{A}^{ rac{1}{mathtt{y}}}-1)

Using the calculated rr compounding every second leads to the same amount of debt like using Amathtt{A} compounding annually over the course of a year. Thus, the calculated rate can be used to achive an interest per year (APR) behaviour with the compounding per second implementation in Tinlake.

Continuing the example from above with an 5.00% annual interest rate (APR):

Decimal Precision

We use fixed precision decimals for any monetary amounts. Interest Rates are typically of type ray with 27 digits precision and amounts are of type wad which has 18 digits precision.

This is usually explicitally mentioned in throught the codebase.