# Accrued Interest Calculation

### Formulae

<details>

<summary><strong>Interest = (r * x * t) / 1yr / 10000</strong></summary>

r = APR in basis points (e.g. 5% = 500bp)

x = amount of tokens

t = time (in seconds)

1 year = 365.25 days (in seconds)

</details>

<details>

<summary>Full Accrued Interest formula</summary>

`InterestAccrued =`

`(rate.dRate * drawnBalance * timespan) / INTEREST_DENOMINATOR`

`+`

`(rate.fRate * (facilityBalance - drawnBalance) * timespan) / INTEREST_DENOMINATOR`

</details>

### Parameters

<details>

<summary>interestAccrued</summary>

Interest owed by a Borrower but not yet repaid to the Line of Credit contract

</details>

<details>

<summary>Interest denominator = 365.25 days * Base denominator</summary>

</details>

<details>

<summary>Base denominator</summary>

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)

</details>

<details>

<summary>One year</summary>

One Julian astronomical year, has 365.25 days: 1 year = 365.25 days = (365.25 days) × (24 hours/day) × (3600 seconds/hour) = 31557600 seconds

</details>

<details>

<summary>dRate</summary>

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%)

</details>

<details>

<summary>drawnBalance</summary>

The balance of funds that a Borrower has drawn down on the Line of Credit

</details>

<details>

<summary>fRate</summary>

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).

</details>

<details>

<summary>facilityBalance</summary>

The remaining balance of funds that a Borrower can still drawn down on the Line of Credit (aka headroom)

</details>

<details>

<summary>timespan= block.timestamp - rate.lastAccrued</summary>

The number of seconds for which interest will be accrued

</details>

<details>

<summary>block.timestamp</summary>

The block timestamp for the block during which interest is calculated, in seconds

</details>

### Contract workflow

Please see [here](/developer-material/v1-developer-material/functions-and-methods/interestratecredit.sol/interest-accrued-contract-flow.md) for an overview of the contract and function workflow.

The definitions below are useful for that.

<details>

<summary>Principal</summary>

The amount of a Lender's Deposit that has actually been drawn down by the Borrower (USD)

</details>

<details>

<summary>Deposit</summary>

The sum of the total liquidity provided by a Lender in a given token on a Line of Credit

</details>

<details>

<summary>id</summary>

Reference id for the Credit Position made available to a Borrower by a single Lender for a given token on a Line

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.creditcoop.xyz/developer-material/v1-developer-material/functions-and-methods/interestratecredit.sol/accrued-interest-calculation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
