# Accrued Interest Calculation

Describes how accrued interest is calculated and where and when this happens

### Formulae

Interest = (r * x * t) / 1yr / 10000
r = APR in basis points (e.g. 5% = 500bp)
x = amount of tokens
t = time (in seconds)
1 year = 365.25 days (in seconds)
Full Accrued Interest formula
`InterestAccrued =`
`(rate.dRate * drawnBalance * timespan) / INTEREST_DENOMINATOR `
`+ `
`(rate.fRate * (facilityBalance - drawnBalance) * timespan) / INTEREST_DENOMINATOR`

### Parameters

interestAccrued
Interest owed by a Borrower but not yet repaid to the Line of Credit contract
Interest denominator = 365.25 days * Base denominator
Base denominator
10000 (adjustment factor since rates are expressed in basis points (bps) --> e.g. 5% rate is expressed as 500bp so we need to divide by 100 to get a % and then by another 100 to arrive at the decimal (500/100/100 = 0.05)
One year
One Julian astronomical year, has 365.25 days: 1 year = 365.25 days = (365.25 days) × (24 hours/day) × (3600 seconds/hour) = 31557600 seconds
dRate
The annual interest rate charged to a Borrower on borrowed / drawn down funds (in basis points to 4 decimals, e.g. 1000bp = 10% and 1234bp = 12.34% and 1234.56bp = 12.3456%)
drawnBalance
The balance of funds that a Borrower has drawn down on the Line of Credit
fRate
The annual interest rate charged to a Borrower on the remaining funds available, but not yet drawn down aka rate charged on the available facility headroom(in basis points to 4 decimals).
facilityBalance
The remaining balance of funds that a Borrower can still drawn down on the Line of Credit (aka headroom)
timespan= block.timestamp - rate.lastAccrued
The number of seconds for which interest will be accrued
block.timestamp
The block timestamp for the block during which interest is calculated, in seconds

### Contract workflow

Please see here for an overview of the contract and function workflow.
The definitions below are useful for that.
Principal
The amount of a Lender's Deposit that has actually been drawn down by the Borrower (USD)
Deposit
The sum of the total liquidity provided by a Lender in a given token on a Line of Credit
id
Reference id for the credit line made available to a Borrower by a single Lender for a given token on a Line